From 4973580b4b719602643732f494d10990be835b4f Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 16 Dec 2015 22:16:04 -0500 Subject: [PATCH] (js) Improve parsing of dates in component editor --- .../js/Scheduler/Component.service.js | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/UI/WebServerResources/js/Scheduler/Component.service.js b/UI/WebServerResources/js/Scheduler/Component.service.js index f5b29c69f..c2c5e1750 100644 --- a/UI/WebServerResources/js/Scheduler/Component.service.js +++ b/UI/WebServerResources/js/Scheduler/Component.service.js @@ -408,6 +408,27 @@ }); }; + /** + * @function $parseDate + * @desc Parse a date string with format YYYY-MM-DDTHH:MM + * @param {string} dateString - the string representing the date + * @param {object} [options] - additional options (use {no_time: true} to ignore the time) + * @returns a date object + */ + Component.$parseDate = function(dateString, options) { + var date, time; + + date = dateString.substring(0,10).split('-'); + + if (options && options.no_time) + return new Date(parseInt(date[0]), parseInt(date[1]) - 1, parseInt(date[2])); + + time = dateString.substring(11,16).split(':'); + + return new Date(parseInt(date[0]), parseInt(date[1]) - 1, parseInt(date[2]), + parseInt(time[0]), parseInt(time[1]), 0, 0); + }; + /** * @function init * @memberof Component.prototype @@ -440,7 +461,7 @@ if (this.startDate) { if (angular.isString(this.startDate)) // Ex: 2015-10-25T22:34:51+00:00 - this.start = new Date(this.startDate.substring(0,10) + ' ' + this.startDate.substring(11,16)); + this.start = Component.$parseDate(this.startDate); else // Date object this.start = this.startDate; @@ -451,7 +472,7 @@ } if (this.endDate) { - this.end = new Date(this.endDate.substring(0,10) + ' ' + this.endDate.substring(11,16)); + this.end = Component.$parseDate(this.endDate); this.delta = this.start.minutesTo(this.end); } else if (this.type == 'appointment') { @@ -459,7 +480,7 @@ } if (this.dueDate) - this.due = new Date(this.dueDate.substring(0,10) + ' ' + this.dueDate.substring(11,16)); + this.due = Component.$parseDate(this.dueDate); if (this.c_category) this.categories = _.invoke(this.c_category, 'asCSSIdentifier'); @@ -500,7 +521,7 @@ this.repeat.end = 'count'; else if (this.repeat.until) { this.repeat.end = 'until'; - this.repeat.until = this.repeat.until.substring(0,10).asDate(); + this.repeat.until = Component.$parseDate(this.repeat.until, { no_time: true }); } else this.repeat.end = 'never';