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,39 +140,55 @@ 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]) {
} date.setDate(m[5]);
if (m[5]) { }
date.setDate(m[5]); if (m[7]) {
check.setDate(m[5]); date.setHours(m[7]);
} }
fixDate(date, check); if (m[8]) {
if (m[7]) { date.setMinutes(m[8]);
date.setHours(m[7]); }
} if (m[10]) {
if (m[8]) { date.setSeconds(m[10]);
date.setMinutes(m[8]); }
} if (m[12]) {
if (m[10]) { date.setMilliseconds(Number("0." + m[12]) * 1000);
date.setSeconds(m[10]); }
} } else {
if (m[12]) { date.setUTCFullYear(m[1]);
date.setMilliseconds(Number("0." + m[12]) * 1000); if (m[3]) {
} date.setUTCMonth(m[3] - 1);
fixDate(date, check); }
if (!ignoreTimezone) { 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