Date: Rename and improve timestamp and day getter and setter

This commit is contained in:
Felix Nagel 2017-03-31 21:31:45 +02:00
parent a31bc8b7ee
commit 6d81c03493
2 changed files with 10 additions and 14 deletions

View File

@ -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;
}

View File

@ -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;
}