Ox.formatDateRangeDuration: avoid infinite loop when passing a start date that cannot be parsed

This commit is contained in:
rlx 2012-06-10 10:27:06 +00:00
parent 92bfb38caf
commit 26681d7e39

View file

@ -422,13 +422,13 @@ Ox.formatDateRangeDuration <f> Formats the duration of a date range as a string
Ox.formatDateRangeDuration = function(start, end, utc) { Ox.formatDateRangeDuration = function(start, end, utc) {
end = end || Ox.formatDate(new Date(), '%Y-%m-%d'); end = end || Ox.formatDate(new Date(), '%Y-%m-%d');
var date = Ox.parseDate(start, utc), var date = Ox.parseDate(start, utc),
dates = [start, end].map(function(str) { dates = [start, end].map(function(string) {
return Ox.parseDate(str, utc); return Ox.parseDate(string, utc);
}), }),
keys = ['year', 'month', 'day', 'hour', 'minute', 'second'], keys = ['year', 'month', 'day', 'hour', 'minute', 'second'],
parts = ['FullYear', 'Month', 'Date', 'Hours', 'Minutes', 'Seconds'], parts = ['FullYear', 'Month', 'Date', 'Hours', 'Minutes', 'Seconds'],
values = []; values = [];
keys.forEach(function(key, i) { date && keys.forEach(function(key, i) {
while (true) { while (true) {
if (key == 'month') { if (key == 'month') {
// set the day to the same day in the next month, // set the day to the same day in the next month,