Project

General

Profile

Statistics
| Revision:

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

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