Skip to content

Commit 6d81c03

Browse files
committed
Date: Rename and improve timestamp and day getter and setter
1 parent a31bc8b commit 6d81c03

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

ui/date.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,13 @@ $.extend( $.ui.date.prototype, {
4848
this.firstDay = this.attributes.firstDay;
4949
},
5050

51-
// TODO: Same as the underlying Date object's terminology, but still misleading.
52-
// TODO: We can use .setTime() instead of new Date and rename to setTimestamp.
53-
setTime: function( time ) {
54-
this.dateObject = new Date( time );
51+
setTimestamp: function( time ) {
52+
this.dateObject.setTime( time );
5553
return this;
5654
},
5755

5856
setDay: function( day ) {
59-
var date = this.dateObject;
60-
61-
// FIXME: Why not to use .setDate?
62-
this.dateObject = new Date( date.getFullYear(), date.getMonth(), day, date.getHours(),
63-
date.getMinutes(), date.getSeconds() );
57+
this.dateObject.setDate( day );
6458
return this;
6559
},
6660

@@ -156,7 +150,6 @@ $.extend( $.ui.date.prototype, {
156150
this.eachDay( day );
157151
}
158152

159-
// TODO use adjust("D", 1)?
160153
printDate.setDate( printDate.getDate() + 1 );
161154
}
162155
}
@@ -190,6 +183,10 @@ $.extend( $.ui.date.prototype, {
190183
return format( this.dateObject ) === format( other );
191184
},
192185

186+
timestamp: function() {
187+
return this.dateObject.getTime();
188+
},
189+
193190
date: function() {
194191
return this.dateObject;
195192
}

ui/widgets/calendar.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ return $.widget( "ui.calendar", {
196196
( this.date.month() > this.viewDate.month() ? 1 : -1 )
197197
);
198198
} else {
199-
this.viewDate.setTime( this.date.date().getTime() );
199+
this.viewDate.setTimestamp( this.date.timestamp() );
200200
}
201201

202202
this.refresh();
@@ -582,7 +582,6 @@ return $.widget( "ui.calendar", {
582582
this.labels = this.options.labels;
583583

584584
// Determine which day grid cell to focus after refresh
585-
// TODO: Prevent disabled cells from being focused
586585
if ( this.options.numberOfMonths === 1 ) {
587586
this.element.find( ".ui-calendar-title" ).replaceWith( this._buildTitle() );
588587
this.element.find( ".ui-calendar-calendar" ).replaceWith( this._buildGrid() );
@@ -727,7 +726,7 @@ return $.widget( "ui.calendar", {
727726
this.viewDate.setAttributes( this._calendarDateOptions );
728727
}
729728
if ( create || refresh ) {
730-
this.viewDate.setTime( this.date.date().getTime() );
729+
this.viewDate.setTimestamp( this.date.timestamp() );
731730
}
732731
if ( create ) {
733732
this.element.empty();
@@ -743,7 +742,7 @@ return $.widget( "ui.calendar", {
743742
_setOption: function( key, value ) {
744743
if ( key === "value" ) {
745744
if ( this._isValid( value ) ) {
746-
this.date.setTime( value.getTime() );
745+
this.date.setTimestamp( value.getTime() );
747746
} else {
748747
value = null;
749748
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy