mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Date: Rename and improve timestamp and day getter and setter
This commit is contained in:
parent
a31bc8b7ee
commit
6d81c03493
17
ui/date.js
17
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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user