Allow the "ignore timezone" setting to be adjustable when parsing ISO8601 dates

This commit is contained in:
Edward Rudd 2010-09-26 20:38:41 +08:00 committed by Adam Shaw
parent dc7094ed27
commit a436ea73f0
2 changed files with 9 additions and 4 deletions

View file

@ -44,6 +44,8 @@ var defaults = {
timeFormat: { // for event elements timeFormat: { // for event elements
'': 'h(:mm)t' // default '': 'h(:mm)t' // default
}, },
// ignoreTimezone for ISO8601 dates in added Events
ignoreTimezone: true,
// locale // locale
isRTL: false, isRTL: false,
@ -894,8 +896,8 @@ function normalizeEvent(event, options) {
} }
delete event.date; delete event.date;
} }
event._start = cloneDate(event.start = parseDate(event.start)); event._start = cloneDate(event.start = parseDate(event.start, options.ignoreTimezone));
event.end = parseDate(event.end); event.end = parseDate(event.end, options.ignoreTimezone);
if (event.end && event.end <= event.start) { if (event.end && event.end <= event.start) {
event.end = null; event.end = null;
} }

View file

@ -116,7 +116,7 @@ function setYMD(date, y, m, d) {
/* Date Parsing /* Date Parsing
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
var parseDate = fc.parseDate = function(s) { var parseDate = fc.parseDate = function(s, ignoreTimezone) {
if (typeof s == 'object') { // already a Date object if (typeof s == 'object') { // already a Date object
return s; return s;
} }
@ -127,7 +127,10 @@ var parseDate = fc.parseDate = function(s) {
if (s.match(/^\d+$/)) { // a UNIX timestamp if (s.match(/^\d+$/)) { // a UNIX timestamp
return new Date(parseInt(s) * 1000); return new Date(parseInt(s) * 1000);
} }
return parseISO8601(s, true) || (s ? new Date(s) : null); if (ignoreTimezone === undefined) {
ignoreTimezone = true;
}
return parseISO8601(s, ignoreTimezone) || (s ? new Date(s) : null);
} }
// TODO: never return invalid dates (like from new Date(<string>)), return null instead // TODO: never return invalid dates (like from new Date(<string>)), return null instead
return null; return null;