Skip to content

Commit 2d41f24

Browse files
committed
Cleanup and formatting
1 parent 35fa801 commit 2d41f24

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

datepicker-rewrite/date.js

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77
(function( $, undefined ) {
88

9-
if (typeof($.global.culture) == "undefined") {
10-
$.global.culture = $.global.cultures["default"];
9+
if ( typeof( $.global.culture ) == "undefined" ) {
10+
$.global.culture = $.global.cultures[ "default" ];
1111
}
1212

1313
$.date = function ( datestring, formatstring ) {
@@ -21,66 +21,65 @@ $.date = function ( datestring, formatstring ) {
2121
return this;
2222
},
2323
setFormat: function( formatstring ) {
24-
if (formatstring) {
24+
if ( formatstring ) {
2525
format = formatstring;
2626
}
2727
return this;
2828
},
2929
setDay: function( day ) {
30-
date = new Date(date.getFullYear(), date.getMonth(), day);
30+
date = new Date( date.getFullYear(), date.getMonth(), day );
3131
return this;
3232
},
3333
adjust: function( period, offset ) {
3434
var day = period == "D" ? date.getDate() + offset : date.getDate(),
3535
month = period == "M" ? date.getMonth() + offset : date.getMonth(),
3636
year = period == "Y" ? date.getFullYear() + offset : date.getFullYear();
37-
date = new Date(year, month, day);
37+
date = new Date( year, month, day );
3838
return this;
3939
},
40-
daysInMonth: function(year, month){
40+
daysInMonth: function( year, month ) {
4141
year = year || date.getFullYear();
4242
month = month || date.getMonth();
43-
return 32 - new Date(year, month, 32).getDate();
43+
return 32 - new Date( year, month, 32 ).getDate();
4444
},
4545
monthname: function() {
46-
return calendar.months.names[date.getMonth()];
46+
return calendar.months.names[ date.getMonth() ];
4747
},
4848
year: function() {
4949
return date.getFullYear();
5050
},
5151
weekdays: function() {
5252
// TODO take firstDay into account
5353
var result = [];
54-
for (var dow = 0; dow < 7; dow++) {
55-
var day = (dow + calendar.firstDay) % 7;
56-
result.push({
57-
shortname: calendar.days.namesShort[day],
58-
fullname: calendar.days.names[day],
54+
for ( var dow = 0; dow < 7; dow++ ) {
55+
var day = ( dow + calendar.firstDay ) % 7;
56+
result.push( {
57+
shortname: calendar.days.namesShort[ day ],
58+
fullname: calendar.days.names[ day ],
5959
});
6060
}
6161
return result;
6262
},
6363
days: function() {
6464
var result = [],
6565
daysInMonth = this.daysInMonth(),
66-
firstDayOfMonth = new Date(this.year(), date.getMonth(), 1).getDay(),
67-
leadDays = (firstDayOfMonth - calendar.firstDay + 7) % 7,
68-
rows = Math.ceil((leadDays + daysInMonth) / 7),
69-
printDate = new Date(this.year(), date.getMonth(), 1 - leadDays),
70-
month = date.getMonth();
71-
for (var row = 0; row < rows; row++) {
72-
var week = result[result.length] = {
66+
firstDayOfMonth = new Date( this.year(), date.getMonth(), 1 ).getDay(),
67+
leadDays = ( firstDayOfMonth - calendar.firstDay + 7 ) % 7,
68+
rows = Math.ceil( ( leadDays + daysInMonth ) / 7),
69+
printDate = new Date( this.year(), date.getMonth(), 1 - leadDays );
70+
for ( var row = 0; row < rows; row++ ) {
71+
var week = result[ result.length ] = {
7372
days: []
7473
};
75-
for (var day = 0; day < 7; day++) {
76-
week.days.push({
77-
lead: printDate.getMonth() != month,
74+
for ( var day = 0; day < 7; day++ ) {
75+
week.days.push( {
76+
lead: printDate.getMonth() != date.getMonth(),
7877
date: printDate.getDate(),
79-
current: this.selected && this.selected.equal(printDate),
80-
today: today.equal(printDate)
78+
current: this.selected && this.selected.equal( printDate ),
79+
today: today.equal( printDate )
8180
});
82-
// use adjust("D", 1)?
83-
printDate.setDate(printDate.getDate() + 1);
81+
// TODO use adjust("D", 1)?
82+
printDate.setDate( printDate.getDate() + 1 );
8483
}
8584
}
8685
return result;
@@ -89,23 +88,25 @@ $.date = function ( datestring, formatstring ) {
8988
this.selected = this.clone();
9089
return this;
9190
},
91+
// TODO create new Date with year, month, day instead
9292
clone: function() {
93-
return $.date(this.format(), format);
93+
return $.date( this.format(), format );
9494
},
95-
equal: function(other) {
96-
function format(date) {
97-
return $.global.format(date, "d");
95+
// TODO compare year, month, day each for better performance
96+
equal: function( other ) {
97+
function format( date ) {
98+
return $.global.format( date, "d" );
9899
}
99-
return format(date) == format(other);
100+
return format( date ) == format( other );
100101
},
101102
date: function() {
102103
return date;
103104
},
104105
format: function( formatstring ) {
105-
return $.global.format(date, formatstring ? formatstring : format);
106+
return $.global.format( date, formatstring ? formatstring : format );
106107
},
107108
calendar: function( newcalendar ) {
108-
if (newcalendar) {
109+
if ( newcalendar ) {
109110
calendar = newcalendar;
110111
return this;
111112
}

0 commit comments

Comments
 (0)