6
6
*/
7
7
( function ( $ , undefined ) {
8
8
9
- if ( typeof ( $ . global . culture ) == "undefined" ) {
10
- $ . global . culture = $ . global . cultures [ "default" ] ;
9
+ if ( typeof ( $ . global . culture ) == "undefined" ) {
10
+ $ . global . culture = $ . global . cultures [ "default" ] ;
11
11
}
12
12
13
13
$ . date = function ( datestring , formatstring ) {
@@ -21,66 +21,65 @@ $.date = function ( datestring, formatstring ) {
21
21
return this ;
22
22
} ,
23
23
setFormat : function ( formatstring ) {
24
- if ( formatstring ) {
24
+ if ( formatstring ) {
25
25
format = formatstring ;
26
26
}
27
27
return this ;
28
28
} ,
29
29
setDay : function ( day ) {
30
- date = new Date ( date . getFullYear ( ) , date . getMonth ( ) , day ) ;
30
+ date = new Date ( date . getFullYear ( ) , date . getMonth ( ) , day ) ;
31
31
return this ;
32
32
} ,
33
33
adjust : function ( period , offset ) {
34
34
var day = period == "D" ? date . getDate ( ) + offset : date . getDate ( ) ,
35
35
month = period == "M" ? date . getMonth ( ) + offset : date . getMonth ( ) ,
36
36
year = period == "Y" ? date . getFullYear ( ) + offset : date . getFullYear ( ) ;
37
- date = new Date ( year , month , day ) ;
37
+ date = new Date ( year , month , day ) ;
38
38
return this ;
39
39
} ,
40
- daysInMonth : function ( year , month ) {
40
+ daysInMonth : function ( year , month ) {
41
41
year = year || date . getFullYear ( ) ;
42
42
month = month || date . getMonth ( ) ;
43
- return 32 - new Date ( year , month , 32 ) . getDate ( ) ;
43
+ return 32 - new Date ( year , month , 32 ) . getDate ( ) ;
44
44
} ,
45
45
monthname : function ( ) {
46
- return calendar . months . names [ date . getMonth ( ) ] ;
46
+ return calendar . months . names [ date . getMonth ( ) ] ;
47
47
} ,
48
48
year : function ( ) {
49
49
return date . getFullYear ( ) ;
50
50
} ,
51
51
weekdays : function ( ) {
52
52
// TODO take firstDay into account
53
53
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 ] ,
59
59
} ) ;
60
60
}
61
61
return result ;
62
62
} ,
63
63
days : function ( ) {
64
64
var result = [ ] ,
65
65
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 ] = {
73
72
days : [ ]
74
73
} ;
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 ( ) ,
78
77
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 )
81
80
} ) ;
82
- // use adjust("D", 1)?
83
- printDate . setDate ( printDate . getDate ( ) + 1 ) ;
81
+ // TODO use adjust("D", 1)?
82
+ printDate . setDate ( printDate . getDate ( ) + 1 ) ;
84
83
}
85
84
}
86
85
return result ;
@@ -89,23 +88,25 @@ $.date = function ( datestring, formatstring ) {
89
88
this . selected = this . clone ( ) ;
90
89
return this ;
91
90
} ,
91
+ // TODO create new Date with year, month, day instead
92
92
clone : function ( ) {
93
- return $ . date ( this . format ( ) , format ) ;
93
+ return $ . date ( this . format ( ) , format ) ;
94
94
} ,
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" ) ;
98
99
}
99
- return format ( date ) == format ( other ) ;
100
+ return format ( date ) == format ( other ) ;
100
101
} ,
101
102
date : function ( ) {
102
103
return date ;
103
104
} ,
104
105
format : function ( formatstring ) {
105
- return $ . global . format ( date , formatstring ? formatstring : format ) ;
106
+ return $ . global . format ( date , formatstring ? formatstring : format ) ;
106
107
} ,
107
108
calendar : function ( newcalendar ) {
108
- if ( newcalendar ) {
109
+ if ( newcalendar ) {
109
110
calendar = newcalendar ;
110
111
return this ;
111
112
}
0 commit comments