I am striving to enhance the cleanliness of my method.
Based on the value of an integer number, I am generating different date formats, resulting in the following:
getRanges() {
var currentDate = new Date();
//This can definitely be simplified
const format = (format) => {
this.formatedTimeRange.start = moment(new Date(currentDate.getTime() - this.timeRange * 60000), "YYYY-MM-DDTHH:mm:ss.SSSZ").format(format);
this.formatedTimeRange.end = moment(new Date(this.linesData[0].x[this.linesData[0].x.length-1]), "YYYY-MM-DDTHH:mm:ss.SSSZ").format(format);
}
const Ranges = {
'1': format("YYYY-MM-DD HH:mm:ss"),
'5': format("YYYY-MM-DD HH:mm:ss"),
'15': format("YYYY-MM-DD HH:mm:ss"),
'60': format("YYYY-MM-DD HH:mm"),
'180': format("YYYY-MM-DD HH:mm"),
'360': format("YYYY-MM-DD HH:mm"),
'720': format("YYYY-MM-DD HH:mm"),
'1440': format("YYYY-MM-DD HH:mm"),
'2880': format("YYYY-MM-DD HH"),
'10080': format("YYYY-MM-DD HH"),
'43200': format("YYYY-MM-DD"),
}
Ranges[this.timeRange];
}
However, a warning message is triggered:
Expression statement is not assignment or call in line
Ranges[this.timeRange]
;
P.S. The code is functioning properly.