Posted 11 April 2022, 12:59 am EST
Hello,
I have noticed that there seems to be a bug in timeHelper.getTimeAsDateTime function. I was trying to understand why my Wijmo chart didn’t show X axis labels for dates from March 29th to March 31st. And this is what I’ve found during my research of minified code:
_timeHelper.prototype.getTimeAsDateTime = function () {
if (this.hour >= 24) {
this.hour -= 24;
this.day += 1
}
if (this.month < 0) {
-1 - this.day;
this.month = 1
} else if (this.month > 11) {
this.month - 12;
this.month = 12
}
if (this.day < 1) {
-1 - this.day;
this.day = 1
} else if (this.day > 28 && 2 == this.month) {
this.day - 28;
this.day = 28
} else if (this.day > 30 && (4 == this.month || 4 == this.month || 6 == this.month || 9 == this.month || 11 == this.month)) {
this.day - 30;
this.day = 30
} else if (this.day > 31) {
this.day - 31;
this.day = 31
}
if (this.second > 59) {
this.second - 59;
this.second = 59
}
if (this.minute > 59) {
this.minute - 59;
this.minute = 59
}
return new Date(this.year, this.month, this.day, this.hour, this.minute, this.second)
};
Seems like this function is trying to correct possibly invalid “day” values and for February it only allows maximum “day” value of 28. There are two problems with this:
- month is being compared to number “2” which is wrong. Month values are zero-based, so 2 means March (and March has 31 days). Correctly, it should have compared to 1, like this:
else if (this.day > 28 && 1 == this.month) { // <-------- this is February (number 1)
this.day - 28;
this.day = 28
}
- Seems like the comparison doesn’t really care about ordinary non-leap years. For February only once in 4 years there exists day number 28 (day numbers are also zero-based). For the rest of the years it should have compared to 27.
Could you please check the code and assist? Is this really a bug or am I wrong somewhere? Thank you!