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