Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / date / islamic.js @ 12

History | View | Annotate | Download (3.22 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"]){
9
dojo._hasResource["dojox.date.islamic"]=true;
10
dojo.provide("dojox.date.islamic");
11
dojo.require("dojox.date.islamic.Date");
12
dojo.require("dojo.date");
13
dojox.date.islamic.getDaysInMonth=function(_1){
14
return _1.getDaysInIslamicMonth(_1.getMonth(),_1.getFullYear());
15
};
16
dojox.date.islamic.compare=function(_2,_3,_4){
17
if(_2 instanceof dojox.date.islamic.Date){
18
_2=_2.toGregorian();
19
}
20
if(_3 instanceof dojox.date.islamic.Date){
21
_3=_3.toGregorian();
22
}
23
return dojo.date.compare.apply(null,arguments);
24
};
25
dojox.date.islamic.add=function(_5,_6,_7){
26
var _8=new dojox.date.islamic.Date(_5);
27
switch(_6){
28
case "day":
29
_8.setDate(_5.getDate()+_7);
30
break;
31
case "weekday":
32
var _9=_5.getDay();
33
if(((_9+_7)<5)&&((_9+_7)>0)){
34
_8.setDate(_5.getDate()+_7);
35
}else{
36
var _a=0,_b=0;
37
if(_9==5){
38
_9=4;
39
_b=(_7>0)?-1:1;
40
}else{
41
if(_9==6){
42
_9=4;
43
_b=(_7>0)?-2:2;
44
}
45
}
46
var _c=(_7>0)?(5-_9-1):-_9;
47
var _d=_7-_c;
48
var _e=parseInt(_d/5);
49
if(_d%5!=0){
50
_a=(_7>0)?2:-2;
51
}
52
_a=_a+_e*7+_d%5+_c;
53
_8.setDate(_5.getDate()+_a+_b);
54
}
55
break;
56
case "year":
57
_8.setFullYear(_5.getFullYear()+_7);
58
break;
59
case "week":
60
_7*=7;
61
_8.setDate(_5.getDate()+_7);
62
break;
63
case "month":
64
var _f=_5.getMonth();
65
_8.setMonth(_f+_7);
66
break;
67
case "hour":
68
_8.setHours(_5.getHours()+_7);
69
break;
70
case "minute":
71
_8.setMinutes(_5.getMinutes()+_7);
72
break;
73
case "second":
74
_8.setSeconds(_5.getSeconds()+_7);
75
break;
76
case "millisecond":
77
_8.setMilliseconds(_5.getMilliseconds()+_7);
78
break;
79
}
80
return _8;
81
};
82
dojox.date.islamic.difference=function(_10,_11,_12){
83
_11=_11||new dojox.date.islamic.Date();
84
_12=_12||"day";
85
var _13=_10.getFullYear()-_11.getFullYear();
86
var _14=1;
87
switch(_12){
88
case "weekday":
89
var _15=Math.round(dojox.date.islamic.difference(_10,_11,"day"));
90
var _16=parseInt(dojox.date.islamic.difference(_10,_11,"week"));
91
var mod=_15%7;
92
if(mod==0){
93
_15=_16*5;
94
}else{
95
var adj=0;
96
var _17=_11.getDay();
97
var _18=_10.getDay();
98
_16=parseInt(_15/7);
99
mod=_15%7;
100
var _19=new dojox.date.islamic.Date(_11);
101
_19.setDate(_19.getDate()+(_16*7));
102
var _1a=_19.getDay();
103
if(_15>0){
104
switch(true){
105
case _17==5:
106
adj=-1;
107
break;
108
case _17==6:
109
adj=0;
110
break;
111
case _18==5:
112
adj=-1;
113
break;
114
case _18==6:
115
adj=-2;
116
break;
117
case (_1a+mod)>5:
118
adj=-2;
119
}
120
}else{
121
if(_15<0){
122
switch(true){
123
case _17==5:
124
adj=0;
125
break;
126
case _17==6:
127
adj=1;
128
break;
129
case _18==5:
130
adj=2;
131
break;
132
case _18==6:
133
adj=1;
134
break;
135
case (_1a+mod)<0:
136
adj=2;
137
}
138
}
139
}
140
_15+=adj;
141
_15-=(_16*2);
142
}
143
_14=_15;
144
break;
145
case "year":
146
_14=_13;
147
break;
148
case "month":
149
var _1b=(_10.toGregorian()>_11.toGregorian())?_10:_11;
150
var _1c=(_10.toGregorian()>_11.toGregorian())?_11:_10;
151
var _1d=_1b.getMonth();
152
var _1e=_1c.getMonth();
153
if(_13==0){
154
_14=_1b.getMonth()-_1c.getMonth();
155
}else{
156
_14=12-_1e;
157
_14+=_1d;
158
var i=_1c.getFullYear()+1;
159
var e=_1b.getFullYear();
160
for(i;i<e;i++){
161
_14+=12;
162
}
163
}
164
if(_10.toGregorian()<_11.toGregorian()){
165
_14=-_14;
166
}
167
break;
168
case "week":
169
_14=parseInt(dojox.date.islamic.difference(_10,_11,"day")/7);
170
break;
171
case "day":
172
_14/=24;
173
case "hour":
174
_14/=60;
175
case "minute":
176
_14/=60;
177
case "second":
178
_14/=1000;
179
case "millisecond":
180
_14*=_10.toGregorian().getTime()-_11.toGregorian().getTime();
181
}
182
return Math.round(_14);
183
};
184
}