-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Consider interval of 2021-06-26, 2022-06-25. interval.getTotalMonths returns -1 instead of 11.
Here's my code fix it outside of datetime package.
@:access(datetime)
class IntervalFix {
public static function getTotalMonthsFix(interval:DateTimeIntervalCore) {
final begin = interval.begin;
final end = interval.end;
var months = (end.getYear() - begin.getYear()) * 12 + (end.getMonth() - begin.getMonth());
var d1 = begin.getDay();
var d2 = end.getDay();
if (d2 < d1) {
months --;
} else if (d1 == d2) {
var h1 = begin.getHour();
var h2 = end.getHour();
if (h2 < h1) {
months --;
} else if (h2 == h1) {
var m1 = begin.getMinute();
var m2 = end.getMinute();
if (m2 < m1) {
months --;
} else if (m2 == m1 && end.getSecond() < begin.getSecond()) {
months --;
}
}
}
return months;
}
}Metadata
Metadata
Assignees
Labels
No labels