From: Jan Schneider Date: Mon, 16 Feb 2009 14:12:48 +0000 (+0100) Subject: Extend Date prototype. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=98d1e68da174fb298ab4713baaf6e0a24fef9634;p=horde.git Extend Date prototype. --- diff --git a/kronolith/js/src/kronolith.js b/kronolith/js/src/kronolith.js index 6d01f350e..7c0a3d527 100644 --- a/kronolith/js/src/kronolith.js +++ b/kronolith/js/src/kronolith.js @@ -386,10 +386,10 @@ KronolithCore = { // Calculate first and last days being displayed. day.setDate(1); firstDay = day.clone() - this.moveToBeginOfWeek(day); + day.moveToBeginOfWeek(); monthEnd.moveToLastDayOfMonth(); lastDay = monthEnd.clone(); - this.moveToBeginOfWeek(monthEnd); + monthEnd.moveToBeginOfWeek(); // Remove old rows. Maybe we should only rebuild the calendars if // necessary. @@ -460,9 +460,9 @@ KronolithCore = { weekStart, weekEnd, weekEndDay, td, tr; day.setDate(1); - this.moveToBeginOfWeek(day); + day.moveToBeginOfWeek(); monthEnd.moveToLastDayOfMonth(); - this.moveToEndOfWeek(monthEnd); + monthEnd.moveToEndOfWeek(); // Update header. $('kronolithMinicalDate').setText(date.toString('MMMM yyyy')).setAttribute('date', date.toString('yyyyMMdd')); @@ -534,41 +534,6 @@ KronolithCore = { return new Date(date.substr(0, 4), date.substr(4, 2) - 1, date.substr(6, 2)); }, - /** - * Moves a date to the end of the corresponding week. - * - * @param Date date A Date object. Passed by reference! - * - * @return Date The same Date object, now pointing to the end of the week. - */ - moveToEndOfWeek: function(date) - { - var weekEndDay = Kronolith.conf.week_start + 6; - if (weekEndDay > 6) { - weekEndDay -= 7; - } - if (date.getDay() != weekEndDay) { - date.moveToDayOfWeek(weekEndDay, 1); - } - return date; - }, - - /** - * Moves a date to the begin of the corresponding week. - * - * @param Date date A Date object. Passed by reference! - * - * @return Date The same Date object, now pointing to the begin of the - * week. - */ - moveToBeginOfWeek: function(date) - { - if (date.getDay() != Kronolith.conf.week_start) { - date.moveToDayOfWeek(Kronolith.conf.week_start, -1); - } - return date; - }, - _addHistory: function(loc, data) { if (Horde.dhtmlHistory.getCurrentLocation() != loc) { @@ -1072,3 +1037,36 @@ Object.extend(String.prototype, { }); } }); + +Object.extend(Date.prototype, { + /** + * Moves a date to the end of the corresponding week. + * + * @return Date The same Date object, now pointing to the end of the week. + */ + moveToEndOfWeek: function() + { + var weekEndDay = Kronolith.conf.week_start + 6; + if (weekEndDay > 6) { + weekEndDay -= 7; + } + if (this.getDay() != weekEndDay) { + this.moveToDayOfWeek(weekEndDay, 1); + } + return this; + }, + + /** + * Moves a date to the begin of the corresponding week. + * + * @return Date The same Date object, now pointing to the begin of the + * week. + */ + moveToBeginOfWeek: function() + { + if (this.getDay() != Kronolith.conf.week_start) { + this.moveToDayOfWeek(Kronolith.conf.week_start, -1); + } + return this; + }, +});