Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / date / islamic / Date.js @ 13

History | View | Annotate | Download (7.02 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.islamic.Date"]){
9
dojo._hasResource["dojox.date.islamic.Date"]=true;
10
dojo.provide("dojox.date.islamic.Date");
11
dojo.require("dojo.date");
12
dojo.requireLocalization("dojo.cldr","islamic",null,"ROOT,ar,he");
13
dojo.declare("dojox.date.islamic.Date",null,{_date:0,_month:0,_year:0,_hours:0,_minutes:0,_seconds:0,_milliseconds:0,_day:0,_GREGORIAN_EPOCH:1721425.5,_ISLAMIC_EPOCH:1948439.5,constructor:function(){
14
var _1=arguments.length;
15
if(!_1){
16
this.fromGregorian(new Date());
17
}else{
18
if(_1==1){
19
var _2=arguments[0];
20
if(typeof _2=="number"){
21
_2=new Date(_2);
22
}
23
if(_2 instanceof Date){
24
this.fromGregorian(_2);
25
}else{
26
if(_2==""){
27
this._date=new Date("");
28
}else{
29
this._year=_2._year;
30
this._month=_2._month;
31
this._date=_2._date;
32
this._hours=_2._hours;
33
this._minutes=_2._minutes;
34
this._seconds=_2._seconds;
35
this._milliseconds=_2._milliseconds;
36
}
37
}
38
}else{
39
if(_1>=3){
40
this._year+=arguments[0];
41
this._month+=arguments[1];
42
this._date+=arguments[2];
43
this._hours+=arguments[3]||0;
44
this._minutes+=arguments[4]||0;
45
this._seconds+=arguments[5]||0;
46
this._milliseconds+=arguments[6]||0;
47
}
48
}
49
}
50
},getDate:function(){
51
return this._date;
52
},getMonth:function(){
53
return this._month;
54
},getFullYear:function(){
55
return this._year;
56
},getDay:function(){
57
return this.toGregorian().getDay();
58
},getHours:function(){
59
return this._hours;
60
},getMinutes:function(){
61
return this._minutes;
62
},getSeconds:function(){
63
return this._seconds;
64
},getMilliseconds:function(){
65
return this._milliseconds;
66
},setDate:function(_3){
67
_3=parseInt(_3);
68
if(_3>0&&_3<=this.getDaysInIslamicMonth(this._month,this._year)){
69
this._date=_3;
70
}else{
71
var _4;
72
if(_3>0){
73
for(_4=this.getDaysInIslamicMonth(this._month,this._year);_3>_4;_3-=_4,_4=this.getDaysInIslamicMonth(this._month,this._year)){
74
this._month++;
75
if(this._month>=12){
76
this._year++;
77
this._month-=12;
78
}
79
}
80
this._date=_3;
81
}else{
82
for(_4=this.getDaysInIslamicMonth((this._month-1)>=0?(this._month-1):11,((this._month-1)>=0)?this._year:this._year-1);_3<=0;_4=this.getDaysInIslamicMonth((this._month-1)>=0?(this._month-1):11,((this._month-1)>=0)?this._year:this._year-1)){
83
this._month--;
84
if(this._month<0){
85
this._year--;
86
this._month+=12;
87
}
88
_3+=_4;
89
}
90
this._date=_3;
91
}
92
}
93
return this;
94
},setFullYear:function(_5){
95
this._year=+_5;
96
},setMonth:function(_6){
97
this._year+=Math.floor(_6/12);
98
if(_6>0){
99
this._month=Math.floor(_6%12);
100
}else{
101
this._month=Math.floor(((_6%12)+12)%12);
102
}
103
},setHours:function(){
104
var _7=arguments.length;
105
var _8=0;
106
if(_7>=1){
107
_8=parseInt(arguments[0]);
108
}
109
if(_7>=2){
110
this._minutes=parseInt(arguments[1]);
111
}
112
if(_7>=3){
113
this._seconds=parseInt(arguments[2]);
114
}
115
if(_7==4){
116
this._milliseconds=parseInt(arguments[3]);
117
}
118
while(_8>=24){
119
this._date++;
120
var _9=this.getDaysInIslamicMonth(this._month,this._year);
121
if(this._date>_9){
122
this._month++;
123
if(this._month>=12){
124
this._year++;
125
this._month-=12;
126
}
127
this._date-=_9;
128
}
129
_8-=24;
130
}
131
this._hours=_8;
132
},setMinutes:function(_a){
133
while(_a>=60){
134
this._hours++;
135
if(this._hours>=24){
136
this._date++;
137
this._hours-=24;
138
var _b=this.getDaysInIslamicMonth(this._month,this._year);
139
if(this._date>_b){
140
this._month++;
141
if(this._month>=12){
142
this._year++;
143
this._month-=12;
144
}
145
this._date-=_b;
146
}
147
}
148
_a-=60;
149
}
150
this._minutes=_a;
151
},setSeconds:function(_c){
152
while(_c>=60){
153
this._minutes++;
154
if(this._minutes>=60){
155
this._hours++;
156
this._minutes-=60;
157
if(this._hours>=24){
158
this._date++;
159
this._hours-=24;
160
var _d=this.getDaysInIslamicMonth(this._month,this._year);
161
if(this._date>_d){
162
this._month++;
163
if(this._month>=12){
164
this._year++;
165
this._month-=12;
166
}
167
this._date-=_d;
168
}
169
}
170
}
171
_c-=60;
172
}
173
this._seconds=_c;
174
},setMilliseconds:function(_e){
175
while(_e>=1000){
176
this.setSeconds++;
177
if(this.setSeconds>=60){
178
this._minutes++;
179
this.setSeconds-=60;
180
if(this._minutes>=60){
181
this._hours++;
182
this._minutes-=60;
183
if(this._hours>=24){
184
this._date++;
185
this._hours-=24;
186
var _f=this.getDaysInIslamicMonth(this._month,this._year);
187
if(this._date>_f){
188
this._month++;
189
if(this._month>=12){
190
this._year++;
191
this._month-=12;
192
}
193
this._date-=_f;
194
}
195
}
196
}
197
}
198
_e-=1000;
199
}
200
this._milliseconds=_e;
201
},toString:function(){
202
var x=new Date();
203
x.setHours(this._hours);
204
x.setMinutes(this._minutes);
205
x.setSeconds(this._seconds);
206
x.setMilliseconds(this._milliseconds);
207
return this._month+" "+this._date+" "+this._year+" "+x.toTimeString();
208
},toGregorian:function(){
209
var _10=this._year;
210
var _11=this._month;
211
var _12=this._date;
212
var _13=_12+Math.ceil(29.5*_11)+(_10-1)*354+Math.floor((3+(11*_10))/30)+this._ISLAMIC_EPOCH-1;
213
var wjd=Math.floor(_13-0.5)+0.5,_14=wjd-this._GREGORIAN_EPOCH,_15=Math.floor(_14/146097),dqc=this._mod(_14,146097),_16=Math.floor(dqc/36524),_17=this._mod(dqc,36524),_18=Math.floor(_17/1461),_19=this._mod(_17,1461),_1a=Math.floor(_19/365),_1b=(_15*400)+(_16*100)+(_18*4)+_1a;
214
if(!(_16==4||_1a==4)){
215
_1b++;
216
}
217
var _1c=this._GREGORIAN_EPOCH+(365*(_1b-1))+Math.floor((_1b-1)/4)-(Math.floor((_1b-1)/100))+Math.floor((_1b-1)/400);
218
var _1d=wjd-_1c;
219
var tjd=(this._GREGORIAN_EPOCH-1)+(365*(_1b-1))+Math.floor((_1b-1)/4)-(Math.floor((_1b-1)/100))+Math.floor((_1b-1)/400)+Math.floor((739/12)+((dojo.date.isLeapYear(new Date(_1b,3,1))?-1:-2))+1);
220
var _1e=((wjd<tjd)?0:(dojo.date.isLeapYear(new Date(_1b,3,1))?1:2));
221
var _1f=Math.floor((((_1d+_1e)*12)+373)/367);
222
var _20=(this._GREGORIAN_EPOCH-1)+(365*(_1b-1))+Math.floor((_1b-1)/4)-(Math.floor((_1b-1)/100))+Math.floor((_1b-1)/400)+Math.floor((((367*_1f)-362)/12)+((_1f<=2)?0:(dojo.date.isLeapYear(new Date(_1b,_1f,1))?-1:-2))+1);
223
var day=(wjd-_20)+1;
224
var _21=new Date(_1b,(_1f-1),day,this._hours,this._minutes,this._seconds,this._milliseconds);
225
return _21;
226
},fromGregorian:function(_22){
227
var _23=new Date(_22);
228
var _24=_23.getFullYear(),_25=_23.getMonth(),_26=_23.getDate();
229
var _27=(this._GREGORIAN_EPOCH-1)+(365*(_24-1))+Math.floor((_24-1)/4)+(-Math.floor((_24-1)/100))+Math.floor((_24-1)/400)+Math.floor((((367*(_25+1))-362)/12)+(((_25+1)<=2)?0:(dojo.date.isLeapYear(_23)?-1:-2))+_26)+(Math.floor(_23.getSeconds()+60*(_23.getMinutes()+60*_23.getHours())+0.5)/86400);
230
_27=Math.floor(_27)+0.5;
231
var _28=_27-this._ISLAMIC_EPOCH;
232
var _29=Math.floor((30*_28+10646)/10631);
233
var _2a=Math.ceil((_28-29-this._yearStart(_29))/29.5);
234
_2a=Math.min(_2a,11);
235
var _2b=Math.ceil(_28-this._monthStart(_29,_2a))+1;
236
this._date=_2b;
237
this._month=_2a;
238
this._year=_29;
239
this._hours=_23.getHours();
240
this._minutes=_23.getMinutes();
241
this._seconds=_23.getSeconds();
242
this._milliseconds=_23.getMilliseconds();
243
this._day=_23.getDay();
244
return this;
245
},valueOf:function(){
246
return this.toGregorian().valueOf();
247
},_yearStart:function(_2c){
248
return (_2c-1)*354+Math.floor((3+11*_2c)/30);
249
},_monthStart:function(_2d,_2e){
250
return Math.ceil(29.5*_2e)+(_2d-1)*354+Math.floor((3+11*_2d)/30);
251
},_civilLeapYear:function(_2f){
252
return (14+11*_2f)%30<11;
253
},getDaysInIslamicMonth:function(_30,_31){
254
var _32=0;
255
_32=29+((_30+1)%2);
256
if(_30==11&&this._civilLeapYear(_31)){
257
_32++;
258
}
259
return _32;
260
},_mod:function(a,b){
261
return a-(b*Math.floor(a/b));
262
}});
263
dojox.date.islamic.Date.getDaysInIslamicMonth=function(_33){
264
return new dojox.date.islamic.Date().getDaysInIslamicMonth(_33.getMonth(),_33.getFullYear());
265
};
266
}