Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / date / hebrew / Date.js

History | View | Annotate | Download (8.1 KB)

1
/*
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.hebrew.Date"]){
9
dojo._hasResource["dojox.date.hebrew.Date"]=true;
10
dojo.provide("dojox.date.hebrew.Date");
11
dojo.require("dojox.date.hebrew.numerals");
12
dojo.declare("dojox.date.hebrew.Date",null,{_MONTH_LENGTH:[[30,30,30],[29,29,30],[29,30,30],[29,29,29],[30,30,30],[30,30,30],[29,29,29],[30,30,30],[29,29,29],[30,30,30],[29,29,29],[30,30,30],[29,29,29]],_MONTH_START:[[0,0,0],[30,30,30],[59,59,60],[88,89,90],[117,118,119],[147,148,149],[147,148,149],[176,177,178],[206,207,208],[235,236,237],[265,266,267],[294,295,296],[324,325,326],[353,354,355]],_LEAP_MONTH_START:[[0,0,0],[30,30,30],[59,59,60],[88,89,90],[117,118,119],[147,148,149],[177,178,179],[206,207,208],[236,237,238],[265,266,267],[295,296,297],[324,325,326],[354,355,356],[383,384,385]],_GREGORIAN_MONTH_COUNT:[[31,31,0,0],[28,29,31,31],[31,31,59,60],[30,30,90,91],[31,31,120,121],[30,30,151,152],[31,31,181,182],[31,31,212,213],[30,30,243,244],[31,31,273,274],[30,30,304,305],[31,31,334,335]],_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>12){
43
console.warn("the month is incorrect , set 0  "+this._month+"   "+this._year);
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
this._setDay();
54
},getDate:function(){
55
return this._date;
56
},getDateLocalized:function(_3){
57
return (_3||dojo.locale).match(/^he(?:-.+)?$/)?dojox.date.hebrew.numerals.getDayHebrewLetters(this._date):this.getDate();
58
},getMonth:function(){
59
return this._month;
60
},getFullYear:function(){
61
return this._year;
62
},getHours:function(){
63
return this._hours;
64
},getMinutes:function(){
65
return this._minutes;
66
},getSeconds:function(){
67
return this._seconds;
68
},getMilliseconds:function(){
69
return this._milliseconds;
70
},setDate:function(_4){
71
_4=+_4;
72
var _5;
73
if(_4>0){
74
while(_4>(_5=this.getDaysInHebrewMonth(this._month,this._year))){
75
_4-=_5;
76
this._month++;
77
if(this._month>=13){
78
this._year++;
79
this._month-=13;
80
}
81
}
82
}else{
83
while(_4<=0){
84
_5=this.getDaysInHebrewMonth((this._month-1)>=0?(this._month-1):12,((this._month-1)>=0)?this._year:this._year-1);
85
this._month--;
86
if(this._month<0){
87
this._year--;
88
this._month+=13;
89
}
90
_4+=_5;
91
}
92
}
93
this._date=_4;
94
this._setDay();
95
return this;
96
},setFullYear:function(_6,_7,_8){
97
this._year=_6=+_6;
98
if(!this.isLeapYear(_6)&&this._month==5){
99
this._month++;
100
}
101
if(_7!==undefined){
102
this.setMonth(_7);
103
}
104
if(_8!==undefined){
105
this.setDate(_8);
106
}
107
var _9=this.getDaysInHebrewMonth(this._month,this._year);
108
if(_9<this._date){
109
this._date=_9;
110
}
111
this._setDay();
112
return this;
113
},setMonth:function(_a){
114
_a=+_a;
115
if(!this.isLeapYear(this._year)&&_a==5){
116
_a++;
117
}
118
if(_a>=0){
119
while(_a>12){
120
this._year++;
121
_a-=13;
122
if(!this.isLeapYear(this._year)&&_a>=5){
123
_a++;
124
}
125
}
126
}else{
127
while(_a<0){
128
this._year--;
129
_a+=(!this.isLeapYear(this._year)&&_a<-7)?12:13;
130
}
131
}
132
this._month=_a;
133
var _b=this.getDaysInHebrewMonth(this._month,this._year);
134
if(_b<this._date){
135
this._date=_b;
136
}
137
this._setDay();
138
return this;
139
},setHours:function(){
140
var _c=arguments.length;
141
var _d=0;
142
if(_c>=1){
143
_d+=+arguments[0];
144
}
145
if(_c>=2){
146
this._minutes+=+arguments[1];
147
}
148
if(_c>=3){
149
this._seconds+=+arguments[2];
150
}
151
if(_c==4){
152
this._milliseconds+=+arguments[3];
153
}
154
while(_d>=24){
155
this._date++;
156
var _e=this.getDaysInHebrewMonth(this._month,this._year);
157
if(this._date>_e){
158
this._month++;
159
if(!this.isLeapYear(this._year)&&this._month==5){
160
this._month++;
161
}
162
if(this._month>=13){
163
this._year++;
164
this._month-=13;
165
}
166
this._date-=_e;
167
}
168
_d-=24;
169
}
170
this._hours=_d;
171
this._setDay();
172
return this;
173
},setMinutes:function(_f){
174
_f=+_f;
175
this._minutes=_f%60;
176
this.setHours(parseInt(_f/60));
177
this._setDay();
178
return this;
179
},setSeconds:function(_10){
180
_10=+_10;
181
this._seconds=_10%60;
182
this.setMinutes(parseInt(_10/60));
183
this._setDay();
184
return this;
185
},setMilliseconds:function(_11){
186
_11=+_11;
187
this._milliseconds=_11%1000;
188
this.setSeconds(parseInt(_11/1000));
189
this._setDay();
190
return this;
191
},_setDay:function(){
192
var day=this._startOfYear(this._year);
193
if(this._month!=0){
194
day+=(this.isLeapYear(this._year)?this._LEAP_MONTH_START:this._MONTH_START)[this._month][this._yearType(this._year)];
195
}
196
day+=this._date-1;
197
this._day=(day+1)%7;
198
},toString:function(){
199
return this._date+", "+this._month+", "+this._year+"  "+this._hours+":"+this._minutes+":"+this._seconds;
200
},getDaysInHebrewMonth:function(_12,_13){
201
var _14=(_12==1||_12==2)?this._yearType(_13):0;
202
return (!this.isLeapYear(this._year)&&_12==5)?0:this._MONTH_LENGTH[_12][_14];
203
},_yearType:function(_15){
204
var _16=this._handleGetYearLength(Number(_15));
205
if(_16>380){
206
_16-=30;
207
}
208
var _17=_16-353;
209
if(_17<0||_17>2){
210
throw new Error("Illegal year length "+_16+" in year "+_15);
211
}
212
return _17;
213
},_handleGetYearLength:function(_18){
214
return this._startOfYear(_18+1)-this._startOfYear(_18);
215
},_startOfYear:function(_19){
216
var _1a=Math.floor((235*_19-234)/19),_1b=_1a*(12*1080+793)+11*1080+204,day=_1a*29+Math.floor(_1b/(24*1080));
217
_1b%=24*1080;
218
var wd=day%7;
219
if(wd==2||wd==4||wd==6){
220
day+=1;
221
wd=day%7;
222
}
223
if(wd==1&&_1b>15*1080+204&&!this.isLeapYear(_19)){
224
day+=2;
225
}else{
226
if(wd==0&&_1b>21*1080+589&&this.isLeapYear(_19-1)){
227
day+=1;
228
}
229
}
230
return day;
231
},isLeapYear:function(_1c){
232
var x=(_1c*12+17)%19;
233
return x>=((x<0)?-7:12);
234
},fromGregorian:function(_1d){
235
var _1e=this._computeHebrewFields(_1d);
236
this._year=_1e[0];
237
this._month=_1e[1];
238
this._date=_1e[2];
239
this._hours=_1d.getHours();
240
this._milliseconds=_1d.getMilliseconds();
241
this._minutes=_1d.getMinutes();
242
this._seconds=_1d.getSeconds();
243
this._setDay();
244
return this;
245
},_computeHebrewFields:function(_1f){
246
var _20=this._getJulianDayFromGregorianDate(_1f),d=_20-347997,m=Math.floor((d*24*1080)/(29*24*1080+12*1080+793)),_21=Math.floor((19*m+234)/235)+1,ys=this._startOfYear(_21),_22=(d-ys);
247
while(_22<1){
248
_21--;
249
ys=this._startOfYear(_21);
250
_22=d-ys;
251
}
252
var _23=this._yearType(_21),_24=this.isLeapYear(_21)?this._LEAP_MONTH_START:this._MONTH_START,_25=0;
253
while(_22>_24[_25][_23]){
254
_25++;
255
}
256
_25--;
257
var _26=_22-_24[_25][_23];
258
return [_21,_25,_26];
259
},toGregorian:function(){
260
var _27=this._year,_28=this._month,_29=this._date,day=this._startOfYear(_27);
261
if(_28!=0){
262
day+=(this.isLeapYear(_27)?this._LEAP_MONTH_START:this._MONTH_START)[_28][this._yearType(_27)];
263
}
264
var _2a=(_29+day+347997),_2b=_2a-1721426;
265
var rem=[];
266
var _2c=this._floorDivide(_2b,146097,rem),_2d=this._floorDivide(rem[0],36524,rem),n4=this._floorDivide(rem[0],1461,rem),n1=this._floorDivide(rem[0],365,rem),_2e=400*_2c+100*_2d+4*n4+n1,_2f=rem[0];
267
if(_2d==4||n1==4){
268
_2f=365;
269
}else{
270
++_2e;
271
}
272
var _30=!(_2e%4)&&(_2e%100||!(_2e%400)),_31=0,_32=_30?60:59;
273
if(_2f>=_32){
274
_31=_30?1:2;
275
}
276
var _33=Math.floor((12*(_2f+_31)+6)/367);
277
var _34=_2f-this._GREGORIAN_MONTH_COUNT[_33][_30?3:2]+1;
278
return new Date(_2e,_33,_34,this._hours,this._minutes,this._seconds,this._milliseconds);
279
},_floorDivide:function(_35,_36,_37){
280
if(_35>=0){
281
_37[0]=(_35%_36);
282
return Math.floor(_35/_36);
283
}
284
var _38=Math.floor(_35/_36);
285
_37[0]=_35-(_38*_36);
286
return _38;
287
},getDay:function(){
288
var _39=this._year,_3a=this._month,_3b=this._date,day=this._startOfYear(_39);
289
if(_3a!=0){
290
day+=(this.isLeapYear(_39)?this._LEAP_MONTH_START:this._MONTH_START)[_3a][this._yearType(_39)];
291
}
292
day+=_3b-1;
293
return (day+1)%7;
294
},_getJulianDayFromGregorianDate:function(_3c){
295
var _3d=_3c.getFullYear(),_3e=_3c.getMonth(),d=_3c.getDate(),_3f=!(_3d%4)&&(_3d%100||!(_3d%400)),y=_3d-1;
296
var _40=365*y+Math.floor(y/4)-Math.floor(y/100)+Math.floor(y/400)+1721426-1;
297
if(_3e!=0){
298
_40+=this._GREGORIAN_MONTH_COUNT[_3e][_3f?3:2];
299
}
300
_40+=d;
301
return _40;
302
}});
303
dojox.date.hebrew.Date.prototype.valueOf=function(){
304
return this.toGregorian().valueOf();
305
};
306
}