1
+ /*
2
+ * jQuery Date
3
+ *
4
+ * Copyright 2010 Marc Grabanski
5
+ * Licensed under the MIT license
6
+ *
7
+ *
8
+ * Depends:
9
+ * jquery.glob.js
10
+ */
11
+ ( function ( $ , undefined ) {
12
+
13
+ if ( typeof ( $ . global . culture ) == "undefined" ) {
14
+ $ . global . culture = $ . global . cultures [ "default" ] ;
15
+ }
16
+
17
+ $ . date = function ( datestring , formatstring ) {
18
+ var calendar = $ . global . culture . calendar ,
19
+ format = formatstring ? formatstring : calendar . patterns . d ,
20
+ date = datestring ? $ . global . parseDate ( datestring , format ) : new Date ( ) ;
21
+ return {
22
+ setFormat : function ( formatstring ) {
23
+ if ( formatstring ) {
24
+ format = formatstring ;
25
+ }
26
+ return this ;
27
+ } ,
28
+ adjust : function ( period , offset ) {
29
+ var day = period == "D" ? date . getDate ( ) + offset : date . getDate ( ) ,
30
+ month = period == "M" ? date . getMonth ( ) + offset : date . getMonth ( ) ,
31
+ year = period == "Y" ? date . getFullYear ( ) + offset : date . getFullYear ( ) ;
32
+ date = new Date ( year , month , day ) ;
33
+ return this ;
34
+ } ,
35
+ daysInMonth : function ( year , month ) {
36
+ year = year || date . getFullYear ( ) ;
37
+ month = month || date . getMonth ( ) ;
38
+ return 32 - new Date ( year , month , 32 ) . getDate ( ) ;
39
+ } ,
40
+ monthname : function ( ) {
41
+ return calendar . months . names [ date . getMonth ( ) ] ;
42
+ } ,
43
+ year : function ( ) {
44
+ return date . getFullYear ( ) ;
45
+ } ,
46
+ weekdays : function ( ) {
47
+ // TODO take firstDay into account
48
+ var result = [ ] ;
49
+ for ( var dow = 0 ; dow < 7 ; dow ++ ) {
50
+ var day = ( dow + calendar . firstDay ) % 7 ;
51
+ result . push ( {
52
+ shortname : calendar . days . namesShort [ day ] ,
53
+ fullname : calendar . days . names [ day ] ,
54
+ } ) ;
55
+ }
56
+ return result ;
57
+ } ,
58
+ days : function ( ) {
59
+ var result = [ ] ,
60
+ daysInMonth = this . daysInMonth ( ) ,
61
+ firstDayOfMonth = new Date ( this . year ( ) , date . getMonth ( ) , 1 ) . getDay ( ) ,
62
+ leadDays = ( firstDayOfMonth - calendar . firstDay + 7 ) % 7
63
+ rows = Math . ceil ( ( leadDays + daysInMonth ) / 7 ) ,
64
+ printDate = new Date ( this . year ( ) , date . getMonth ( ) , 1 - leadDays ) ;
65
+ for ( var row = 0 ; row < rows ; row ++ ) {
66
+ var week = result [ result . length ] = {
67
+ days : [ ]
68
+ } ;
69
+ for ( var day = 0 ; day < 7 ; day ++ ) {
70
+ week . days . push ( printDate . getDate ( ) ) ;
71
+ // use adjust("D", 1)?
72
+ printDate . setDate ( printDate . getDate ( ) + 1 ) ;
73
+ }
74
+ }
75
+ return result ;
76
+ } ,
77
+ date : function ( ) {
78
+ return date ;
79
+ } ,
80
+ format : function ( formatstring ) {
81
+ return $ . global . format ( date , formatstring ? formatstring : format ) ;
82
+ } ,
83
+ calendar : function ( newcalendar ) {
84
+ if ( newcalendar ) {
85
+ calendar = newcalendar ;
86
+ return this ;
87
+ }
88
+ return calendar ;
89
+ }
90
+ }
91
+ }
92
+
93
+ } ( jQuery ) ) ;
0 commit comments