diff --git a/ChangeLog b/ChangeLog index fe05d2acc..ee7f06b3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-05-17 Wolfgang Sourdeau + + * UI/WebServerResources/JavascriptAPIExtensions.js + (Date.prototype.clone): new method for copying the Date object + into another instance. + (Date.prototype.deltaDays): new method that returns the number of + days separating the current date with another one passed as + parameter. + (Date.prototype.beginOfDay): new method that returns a new date + instance corresponding to time 00:00 of the current instance. + 2010-05-06 Wolfgang Sourdeau * Tests/Integration/test-caldav-scheduling.py diff --git a/UI/WebServerResources/JavascriptAPIExtensions.js b/UI/WebServerResources/JavascriptAPIExtensions.js index 55eef3c36..55fd871d8 100644 --- a/UI/WebServerResources/JavascriptAPIExtensions.js +++ b/UI/WebServerResources/JavascriptAPIExtensions.js @@ -72,6 +72,14 @@ String.prototype.asCSSIdentifier = function() { return newString; }; +Date.prototype.clone = function() { + var newDate = new Date(); + + newDate.setTime(this.getTime()); + + return newDate; +} + Date.prototype.sogoDayName = function() { var dayName = ""; @@ -95,6 +103,18 @@ Date.prototype.sogoDayName = function() { return dayName; }; +Date.prototype.deltaDays = function(otherDate) { + var day1 = this.getTime(); + var day2 = otherDate.getTime(); + if (day1 > day2) { + var tmp = day2; + day2 = day1; + day1 = tmp; + } + + return Math.floor((day2 - day1) / 86400000); +} + Date.prototype.daysUpTo = function(otherDate) { var days = new Array(); @@ -206,18 +226,25 @@ Date.prototype.laterDate = function(otherDate) { return ((this.getTime() < workDate.getTime()) ? otherDate : this); }; + +Date.prototype.beginOfDay = function() { + var beginOfDay = new Date(this.getTime()); + beginOfDay.setHours(0); + beginOfDay.setMinutes(0); + beginOfDay.setSeconds(0); + beginOfDay.setMilliseconds(0); + + return beginOfDay; +} Date.prototype.beginOfWeek = function() { var offset = firstDayOfWeek - this.getDay(); if (offset > 0) offset -= 7; - var beginOfWeek = new Date(this.getTime()); + var beginOfWeek = this.beginOfDay(); beginOfWeek.setHours(12); beginOfWeek.addDays(offset); - beginOfWeek.setMinutes(0); - beginOfWeek.setSeconds(0); - beginOfWeek.setMilliseconds(0); return beginOfWeek; };