From 6d81c03493c2135faf61ddb2ab69faaed9c019af Mon Sep 17 00:00:00 2001 From: Felix Nagel Date: Fri, 31 Mar 2017 21:31:45 +0200 Subject: [PATCH] Date: Rename and improve timestamp and day getter and setter --- ui/date.js | 17 +++++++---------- ui/widgets/calendar.js | 7 +++---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/ui/date.js b/ui/date.js index aea91c413..d1a2153c8 100644 --- a/ui/date.js +++ b/ui/date.js @@ -48,19 +48,13 @@ $.extend( $.ui.date.prototype, { this.firstDay = this.attributes.firstDay; }, - // TODO: Same as the underlying Date object's terminology, but still misleading. - // TODO: We can use .setTime() instead of new Date and rename to setTimestamp. - setTime: function( time ) { - this.dateObject = new Date( time ); + setTimestamp: function( time ) { + this.dateObject.setTime( time ); return this; }, setDay: function( day ) { - var date = this.dateObject; - - // FIXME: Why not to use .setDate? - this.dateObject = new Date( date.getFullYear(), date.getMonth(), day, date.getHours(), - date.getMinutes(), date.getSeconds() ); + this.dateObject.setDate( day ); return this; }, @@ -156,7 +150,6 @@ $.extend( $.ui.date.prototype, { this.eachDay( day ); } - // TODO use adjust("D", 1)? printDate.setDate( printDate.getDate() + 1 ); } } @@ -190,6 +183,10 @@ $.extend( $.ui.date.prototype, { return format( this.dateObject ) === format( other ); }, + timestamp: function() { + return this.dateObject.getTime(); + }, + date: function() { return this.dateObject; } diff --git a/ui/widgets/calendar.js b/ui/widgets/calendar.js index 4bac6c326..df919cb99 100644 --- a/ui/widgets/calendar.js +++ b/ui/widgets/calendar.js @@ -196,7 +196,7 @@ return $.widget( "ui.calendar", { ( this.date.month() > this.viewDate.month() ? 1 : -1 ) ); } else { - this.viewDate.setTime( this.date.date().getTime() ); + this.viewDate.setTimestamp( this.date.timestamp() ); } this.refresh(); @@ -582,7 +582,6 @@ return $.widget( "ui.calendar", { this.labels = this.options.labels; // Determine which day grid cell to focus after refresh - // TODO: Prevent disabled cells from being focused if ( this.options.numberOfMonths === 1 ) { this.element.find( ".ui-calendar-title" ).replaceWith( this._buildTitle() ); this.element.find( ".ui-calendar-calendar" ).replaceWith( this._buildGrid() ); @@ -727,7 +726,7 @@ return $.widget( "ui.calendar", { this.viewDate.setAttributes( this._calendarDateOptions ); } if ( create || refresh ) { - this.viewDate.setTime( this.date.date().getTime() ); + this.viewDate.setTimestamp( this.date.timestamp() ); } if ( create ) { this.element.empty(); @@ -743,7 +742,7 @@ return $.widget( "ui.calendar", { _setOption: function( key, value ) { if ( key === "value" ) { if ( this._isValid( value ) ) { - this.date.setTime( value.getTime() ); + this.date.setTimestamp( value.getTime() ); } else { value = null; } -- 2.39.5