1
0
Fork 0
forked from 0x2620/oxjs

fix a corner case in Ox.formatDateRangeDuration()

This commit is contained in:
rlx 2011-10-10 17:00:01 +00:00
commit ccece375c0
4 changed files with 28 additions and 12 deletions

View file

@ -382,19 +382,31 @@ Ox.formatDateRangeDuration = function(start, end, utc) {
Ox.forEach(keys, function(key, i) {
while (true) {
if (key == 'month') {
// set the day to the same day in the next month,
// or to its last day if the next month is shorter
var day = Ox.getDate(date, utc);
Ox.setDate(date, Math.min(
Ox.getDate(date, utc),
day,
Ox.getDaysInMonth(
Ox.getFullYear(date, utc),
Ox.getMonth(date, utc) + 2
Ox.getMonth(date, utc) + 2,
utc
)
), utc);
}
// advance the date by one unit
Ox['set' + parts[i]](date, Ox['get' + parts[i]](date, utc) + 1, utc);
Ox.print(key, '.....', date)
if (date <= dates[1]) {
// still within the range, add one unit
values[i] = (values[i] || 0) + 1;
} else {
// outside the range, rewind the date by one unit
Ox['set' + parts[i]](date, Ox['get' + parts[i]](date, utc) - 1, utc);
if (key == 'month') {
// and revert to original day
Ox.setDate(date, day, utc);
}
break;
}
}