root / trunk / web / dojo / dojox / date / buddhist / Date.js @ 11
History | View | Annotate | Download (4.82 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.date.buddhist.Date"]){ |
||
9 | dojo._hasResource["dojox.date.buddhist.Date"]=true; |
||
10 | dojo.provide("dojox.date.buddhist.Date");
|
||
11 | dojo.experimental("dojox.date.buddhist.Date");
|
||
12 | dojo.declare("dojox.date.buddhist.Date",null,{_date:0,_month:0,_year:0,_hours:0,_minutes:0,_seconds:0,_milliseconds:0,_day:0,constructor:function(){ |
||
13 | var _1=arguments.length; |
||
14 | if(!_1){
|
||
15 | this.fromGregorian(new Date()); |
||
16 | }else{
|
||
17 | if(_1==1){ |
||
18 | var _2=arguments[0]; |
||
19 | if(typeof _2=="number"){ |
||
20 | _2=new Date(_2);
|
||
21 | } |
||
22 | if(_2 instanceof Date){ |
||
23 | this.fromGregorian(_2);
|
||
24 | }else{
|
||
25 | if(_2==""){ |
||
26 | this._date=new Date(""); |
||
27 | }else{
|
||
28 | this._year=_2._year;
|
||
29 | this._month=_2._month;
|
||
30 | this._date=_2._date;
|
||
31 | this._hours=_2._hours;
|
||
32 | this._minutes=_2._minutes;
|
||
33 | this._seconds=_2._seconds;
|
||
34 | this._milliseconds=_2._milliseconds;
|
||
35 | } |
||
36 | } |
||
37 | }else{
|
||
38 | if(_1>=3){ |
||
39 | this._year+=arguments[0]; |
||
40 | this._month+=arguments[1]; |
||
41 | this._date+=arguments[2]; |
||
42 | if(this._month>11){ |
||
43 | console.warn("the month is incorrect , set 0");
|
||
44 | this._month=0; |
||
45 | } |
||
46 | this._hours+=arguments[3]||0; |
||
47 | this._minutes+=arguments[4]||0; |
||
48 | this._seconds+=arguments[5]||0; |
||
49 | this._milliseconds+=arguments[6]||0; |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | },getDate:function(_3){ |
||
54 | return parseInt(this._date); |
||
55 | },getMonth:function(){ |
||
56 | return parseInt(this._month); |
||
57 | },getFullYear:function(){ |
||
58 | return parseInt(this._year); |
||
59 | },getHours:function(){ |
||
60 | return this._hours; |
||
61 | },getMinutes:function(){ |
||
62 | return this._minutes; |
||
63 | },getSeconds:function(){ |
||
64 | return this._seconds; |
||
65 | },getMilliseconds:function(){ |
||
66 | return this._milliseconds; |
||
67 | },setDate:function(_4){ |
||
68 | _4=parseInt(_4); |
||
69 | if(_4>0&&_4<=this._getDaysInMonth(this._month,this._year)){ |
||
70 | this._date=_4;
|
||
71 | }else{
|
||
72 | var _5;
|
||
73 | if(_4>0){ |
||
74 | for(_5=this._getDaysInMonth(this._month,this._year);_4>_5;_4-=_5,_5=this._getDaysInMonth(this._month,this._year)){ |
||
75 | this._month++;
|
||
76 | if(this._month>=12){ |
||
77 | this._year++;
|
||
78 | this._month-=12; |
||
79 | } |
||
80 | } |
||
81 | this._date=_4;
|
||
82 | }else{
|
||
83 | for(_5=this._getDaysInMonth((this._month-1)>=0?(this._month-1):11,((this._month-1)>=0)?this._year:this._year-1);_4<=0;_5=this._getDaysInMonth((this._month-1)>=0?(this._month-1):11,((this._month-1)>=0)?this._year:this._year-1)){ |
||
84 | this._month--;
|
||
85 | if(this._month<0){ |
||
86 | this._year--;
|
||
87 | this._month+=12; |
||
88 | } |
||
89 | _4+=_5; |
||
90 | } |
||
91 | this._date=_4;
|
||
92 | } |
||
93 | } |
||
94 | return this; |
||
95 | },setFullYear:function(_6,_7,_8){ |
||
96 | this._year=parseInt(_6);
|
||
97 | },setMonth:function(_9){ |
||
98 | this._year+=Math.floor(_9/12); |
||
99 | this._month=Math.floor(_9%12); |
||
100 | for(;this._month<0;this._month=this._month+12){ |
||
101 | } |
||
102 | },setHours:function(){ |
||
103 | var _a=arguments.length; |
||
104 | var _b=0; |
||
105 | if(_a>=1){ |
||
106 | _b=parseInt(arguments[0]); |
||
107 | } |
||
108 | if(_a>=2){ |
||
109 | this._minutes=parseInt(arguments[1]); |
||
110 | } |
||
111 | if(_a>=3){ |
||
112 | this._seconds=parseInt(arguments[2]); |
||
113 | } |
||
114 | if(_a==4){ |
||
115 | this._milliseconds=parseInt(arguments[3]); |
||
116 | } |
||
117 | while(_b>=24){ |
||
118 | this._date++;
|
||
119 | var _c=this._getDaysInMonth(this._month,this._year); |
||
120 | if(this._date>_c){ |
||
121 | this._month++;
|
||
122 | if(this._month>=12){ |
||
123 | this._year++;
|
||
124 | this._month-=12; |
||
125 | } |
||
126 | this._date-=_c;
|
||
127 | } |
||
128 | _b-=24;
|
||
129 | } |
||
130 | this._hours=_b;
|
||
131 | },setMinutes:function(_d){ |
||
132 | while(_d>=60){ |
||
133 | this._hours++;
|
||
134 | if(this._hours>=24){ |
||
135 | this._date++;
|
||
136 | this._hours-=24; |
||
137 | var _e=this._getDaysInMonth(this._month,this._year); |
||
138 | if(this._date>_e){ |
||
139 | this._month++;
|
||
140 | if(this._month>=12){ |
||
141 | this._year++;
|
||
142 | this._month-=12; |
||
143 | } |
||
144 | this._date-=_e;
|
||
145 | } |
||
146 | } |
||
147 | _d-=60;
|
||
148 | } |
||
149 | this._minutes=_d;
|
||
150 | },setSeconds:function(_f){ |
||
151 | while(_f>=60){ |
||
152 | this._minutes++;
|
||
153 | if(this._minutes>=60){ |
||
154 | this._hours++;
|
||
155 | this._minutes-=60; |
||
156 | if(this._hours>=24){ |
||
157 | this._date++;
|
||
158 | this._hours-=24; |
||
159 | var _10=this._getDaysInMonth(this._month,this._year); |
||
160 | if(this._date>_10){ |
||
161 | this._month++;
|
||
162 | if(this._month>=12){ |
||
163 | this._year++;
|
||
164 | this._month-=12; |
||
165 | } |
||
166 | this._date-=_10;
|
||
167 | } |
||
168 | } |
||
169 | } |
||
170 | _f-=60;
|
||
171 | } |
||
172 | this._seconds=_f;
|
||
173 | },setMilliseconds:function(_11){ |
||
174 | while(_11>=1000){ |
||
175 | this.setSeconds++;
|
||
176 | if(this.setSeconds>=60){ |
||
177 | this._minutes++;
|
||
178 | this.setSeconds-=60; |
||
179 | if(this._minutes>=60){ |
||
180 | this._hours++;
|
||
181 | this._minutes-=60; |
||
182 | if(this._hours>=24){ |
||
183 | this._date++;
|
||
184 | this._hours-=24; |
||
185 | var _12=this._getDaysInMonth(this._month,this._year); |
||
186 | if(this._date>_12){ |
||
187 | this._month++;
|
||
188 | if(this._month>=12){ |
||
189 | this._year++;
|
||
190 | this._month-=12; |
||
191 | } |
||
192 | this._date-=_12;
|
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | _11-=1000;
|
||
198 | } |
||
199 | this._milliseconds=_11;
|
||
200 | },toString:function(){ |
||
201 | return this._date+", "+this._month+", "+this._year+" "+this._hours+":"+this._minutes+":"+this._seconds; |
||
202 | },_getDaysInMonth:function(_13,_14){ |
||
203 | return dojo.date.getDaysInMonth(new Date(_14-543,_13)); |
||
204 | },fromGregorian:function(_15){ |
||
205 | var _16=new Date(_15); |
||
206 | this._date=_16.getDate();
|
||
207 | this._month=_16.getMonth();
|
||
208 | this._year=_16.getFullYear()+543; |
||
209 | this._hours=_16.getHours();
|
||
210 | this._minutes=_16.getMinutes();
|
||
211 | this._seconds=_16.getSeconds();
|
||
212 | this._milliseconds=_16.getMilliseconds();
|
||
213 | this._day=_16.getDay();
|
||
214 | return this; |
||
215 | },toGregorian:function(){ |
||
216 | return new Date(this._year-543,this._month,this._date,this._hours,this._minutes,this._seconds,this._milliseconds); |
||
217 | },getDay:function(){ |
||
218 | return this.toGregorian().getDay(); |
||
219 | }}); |
||
220 | dojox.date.buddhist.Date.prototype.valueOf=function(){ |
||
221 | return this.toGregorian().valueOf(); |
||
222 | }; |
||
223 | } |