fixed parseISO8601 handling of DST boundaries, it should now be able to handle any dates

This commit is contained in:
Calvin Cheung 2010-04-10 06:09:55 +08:00 committed by Adam Shaw
parent 86cc3bdbda
commit dc7094ed27

View file

@ -140,18 +140,14 @@ var parseISO8601 = fc.parseISO8601 = function(s, ignoreTimezone) {
if (!m) { if (!m) {
return null; return null;
} }
var date = new Date(m[1], 0, 1), var date = new Date(m[1], 0, 1), offset = 0;
check = new Date(m[1], 0, 1, 9, 0), if (ignoreTimezone) {
offset = 0;
if (m[3]) { if (m[3]) {
date.setMonth(m[3] - 1); date.setMonth(m[3] - 1);
check.setMonth(m[3] - 1);
} }
if (m[5]) { if (m[5]) {
date.setDate(m[5]); date.setDate(m[5]);
check.setDate(m[5]);
} }
fixDate(date, check);
if (m[7]) { if (m[7]) {
date.setHours(m[7]); date.setHours(m[7]);
} }
@ -164,15 +160,35 @@ var parseISO8601 = fc.parseISO8601 = function(s, ignoreTimezone) {
if (m[12]) { if (m[12]) {
date.setMilliseconds(Number("0." + m[12]) * 1000); date.setMilliseconds(Number("0." + m[12]) * 1000);
} }
fixDate(date, check); } else {
if (!ignoreTimezone) { date.setUTCFullYear(m[1]);
if (m[3]) {
date.setUTCMonth(m[3] - 1);
}
if (m[5]) {
date.setUTCDate(m[5]);
}
if (m[7]) {
date.setUTCHours(m[7]);
}
if (m[8]) {
date.setUTCMinutes(m[8]);
}
if (m[10]) {
date.setUTCSeconds(m[10]);
}
if (m[12]) {
date.setUTCMilliseconds(Number("0." + m[12]) * 1000);
}
if (m[14]) { if (m[14]) {
offset = Number(m[16]) * 60 + Number(m[17]); offset = Number(m[16]) * 60 + Number(m[17]);
offset *= m[15] == '-' ? 1 : -1; offset *= m[15] == '-' ? 1 : -1;
} }
offset -= date.getTimezoneOffset(); date = new Date(+date + (offset * 60 * 1000));
} }
return new Date(+date + (offset * 60 * 1000));
return date;
}; };
var parseTime = fc.parseTime = function(s) { // returns minutes since start of day var parseTime = fc.parseTime = function(s) { // returns minutes since start of day