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;
|
this.firstDay = this.attributes.firstDay;
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: Same as the underlying Date object's terminology, but still misleading.
|
setTimestamp: function( time ) {
|
||||||
// TODO: We can use .setTime() instead of new Date and rename to setTimestamp.
|
this.dateObject.setTime( time );
|
||||||
setTime: function( time ) {
|
|
||||||
this.dateObject = new Date( time );
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
setDay: function( day ) {
|
setDay: function( day ) {
|
||||||
var date = this.dateObject;
|
this.dateObject.setDate( day );
|
||||||
|
|
||||||
// FIXME: Why not to use .setDate?
|
|
||||||
this.dateObject = new Date( date.getFullYear(), date.getMonth(), day, date.getHours(),
|
|
||||||
date.getMinutes(), date.getSeconds() );
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -156,7 +150,6 @@ $.extend( $.ui.date.prototype, {
|
|||||||
this.eachDay( day );
|
this.eachDay( day );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use adjust("D", 1)?
|
|
||||||
printDate.setDate( printDate.getDate() + 1 );
|
printDate.setDate( printDate.getDate() + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,6 +183,10 @@ $.extend( $.ui.date.prototype, {
|
|||||||
return format( this.dateObject ) === format( other );
|
return format( this.dateObject ) === format( other );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
timestamp: function() {
|
||||||
|
return this.dateObject.getTime();
|
||||||
|
},
|
||||||
|
|
||||||
date: function() {
|
date: function() {
|
||||||
return this.dateObject;
|
return this.dateObject;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ return $.widget( "ui.calendar", {
|
|||||||
( this.date.month() > this.viewDate.month() ? 1 : -1 )
|
( this.date.month() > this.viewDate.month() ? 1 : -1 )
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.viewDate.setTime( this.date.date().getTime() );
|
this.viewDate.setTimestamp( this.date.timestamp() );
|
||||||
}
|
}
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
@ -582,7 +582,6 @@ return $.widget( "ui.calendar", {
|
|||||||
this.labels = this.options.labels;
|
this.labels = this.options.labels;
|
||||||
|
|
||||||
// Determine which day grid cell to focus after refresh
|
// Determine which day grid cell to focus after refresh
|
||||||
// TODO: Prevent disabled cells from being focused
|
|
||||||
if ( this.options.numberOfMonths === 1 ) {
|
if ( this.options.numberOfMonths === 1 ) {
|
||||||
this.element.find( ".ui-calendar-title" ).replaceWith( this._buildTitle() );
|
this.element.find( ".ui-calendar-title" ).replaceWith( this._buildTitle() );
|
||||||
this.element.find( ".ui-calendar-calendar" ).replaceWith( this._buildGrid() );
|
this.element.find( ".ui-calendar-calendar" ).replaceWith( this._buildGrid() );
|
||||||
@ -727,7 +726,7 @@ return $.widget( "ui.calendar", {
|
|||||||
this.viewDate.setAttributes( this._calendarDateOptions );
|
this.viewDate.setAttributes( this._calendarDateOptions );
|
||||||
}
|
}
|
||||||
if ( create || refresh ) {
|
if ( create || refresh ) {
|
||||||
this.viewDate.setTime( this.date.date().getTime() );
|
this.viewDate.setTimestamp( this.date.timestamp() );
|
||||||
}
|
}
|
||||||
if ( create ) {
|
if ( create ) {
|
||||||
this.element.empty();
|
this.element.empty();
|
||||||
@ -743,7 +742,7 @@ return $.widget( "ui.calendar", {
|
|||||||
_setOption: function( key, value ) {
|
_setOption: function( key, value ) {
|
||||||
if ( key === "value" ) {
|
if ( key === "value" ) {
|
||||||
if ( this._isValid( value ) ) {
|
if ( this._isValid( value ) ) {
|
||||||
this.date.setTime( value.getTime() );
|
this.date.setTimestamp( value.getTime() );
|
||||||
} else {
|
} else {
|
||||||
value = null;
|
value = null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user