Quellcode durchsuchen

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

Edward Rudd vor 15 Jahren
Ursprung
Commit
a436ea73f0
2 geänderte Dateien mit 9 neuen und 4 gelöschten Zeilen
  1. 4 2
      src/main.js
  2. 5 2
      src/util.js

+ 4 - 2
src/main.js

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

+ 5 - 2
src/util.js

@@ -116,7 +116,7 @@ function setYMD(date, y, m, d) {
 /* Date Parsing
 -----------------------------------------------------------------------------*/
 
-var parseDate = fc.parseDate = function(s) {
+var parseDate = fc.parseDate = function(s, ignoreTimezone) {
 	if (typeof s == 'object') { // already a Date object
 		return s;
 	}
@@ -127,7 +127,10 @@ var parseDate = fc.parseDate = function(s) {
 		if (s.match(/^\d+$/)) { // a UNIX timestamp
 			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
 	return null;