Debian Codegraph @

dojox/date/hebrew/Date.js

raw symbols SCIP
1 define([
2 "dojo/_base/lang",
3 "dojo/_base/declare",
4 "./numerals"
5 ], function(lang, declare, numerals){
6
7 var HDate = declare("dojox.date.hebrew.Date", null, {
8 // summary:
9 // A Date-like object which implements the Hebrew calendar
10 // description:
11 // A Date-like object which implements the Hebrew Calendar. Because this object
12 // implements many of the same methods as the native JavaScript Date object, which
13 // implements the Gregorian calendar, it can often be used its place. Note that
14 // this object does not extend Date or use its prototype.
15 // example:
16 // | dojo.require("dojox.date.hebrew.Date");
17 // |
18 // | var date = new dojox.date.hebrew.Date();
19 // | console.log(date.getFullYear()+'\'+date.getMonth()+'\'+date.getDate());
20
21 // Hebrew date calculations are performed in terms of days, hours, and
22 // "parts" (or halakim), which are 1/1080 of an hour, or 3 1/3 seconds.
23 //_HOUR_PARTS: 1080,
24 //_DAY_PARTS: 24*1080,
25
26 // An approximate value for the length of a lunar month.
27 // It is used to calculate the approximate year and month of a given
28 // absolute date.
29 //_MONTH_FRACT: 12*1080 + 793,
30 //_MONTH_PARTS: 29*24*1080 + 12*1080 + 793,
31
32 // The time of the new moon (in parts) on 1 Tishri, year 1 (the epoch)
33 // counting from noon on the day before. BAHARAD is an abbreviation of
34 // Bet (Monday), Hey (5 hours from sunset), Resh-Daled (204).
35 //_BAHARAD: 11*1080 + 204,
36
37 // The Julian day of the Gregorian epoch, that is, January 1, 1 on the
38 // Gregorian calendar.
39 //_JAN_1_1_JULIAN_DAY: 1721426,
40
41 /**
42 * The lengths of the Hebrew months. This is complicated, because there
43 * are three different types of years, or six if you count leap years.
44 * Due to the rules for postponing the start of the year to avoid having
45 * certain holidays fall on the sabbath, the year can end up being three
46 * different lengths, called "deficient", "normal", and "complete".
47 */
48
49 //"Absolute" indexes of months: Tishri - 0, Heshvan - 1, Kislev - 2, Tevet - 3, Shevat - 4, Adar I (leap years only) - 5, Adar - 6, Nisan - 7, Iyar - 8, Sivan - 9, Tammuz-10, Av - 11, Elul - 12.
50
51 _MONTH_LENGTH: [
52 // Deficient Normal Complete
53 [ 30, 30, 30 ], //Tishri 0
54 [ 29, 29, 30 ], //Heshvan 1
55 [ 29, 30, 30 ], //Kislev 2
56 [ 29, 29, 29 ], //Tevet 3
57 [ 30, 30, 30 ], //Shevat 4
58 [ 30, 30, 30 ], //Adar I (leap years only) 5
59 [ 29, 29, 29 ], //Adar 6
60 [ 30, 30, 30 ], //Nisan 7
61 [ 29, 29, 29 ], //Iyar 8
62 [ 30, 30, 30 ], //Sivan 9
63 [ 29, 29, 29 ], //Tammuz 10
64 [ 30, 30, 30 ], //Av 11
65 [ 29, 29, 29 ] //Elul 12
66 ],
67
68 /**
69 * The cumulative # of days to the end of each month in a non-leap year
70 * Although this can be calculated from the MONTH_LENGTH table,
71 * keeping it around separately makes some calculations a lot faster
72 */
73 _MONTH_START: [
74 // Deficient Normal Complete
75 [ 0, 0, 0 ], // (placeholder)
76 [ 30, 30, 30 ], // Tishri
77 [ 59, 59, 60 ], // Heshvan
78 [ 88, 89, 90 ], // Kislev
79 [ 117, 118, 119 ], // Tevet
80 [ 147, 148, 149 ], // Shevat
81 [ 147, 148, 149 ], // (Adar I placeholder)
82 [ 176, 177, 178 ], // Adar
83 [ 206, 207, 208 ], // Nisan
84 [ 235, 236, 237 ], // Iyar
85 [ 265, 266, 267 ], // Sivan
86 [ 294, 295, 296 ], // Tammuz
87 [ 324, 325, 326 ], // Av
88 [ 353, 354, 355 ] // Elul
89 ],
90
91 /**
92 * The cumulative # of days to the end of each month in a leap year
93 */
94 _LEAP_MONTH_START: [
95 // Deficient Normal Complete
96 [ 0, 0, 0 ], // (placeholder)
97 [ 30, 30, 30 ], // Tishri
98 [ 59, 59, 60 ], // Heshvan
99 [ 88, 89, 90 ], // Kislev
100 [ 117, 118, 119 ], // Tevet
101 [ 147, 148, 149 ], // Shevat
102 [ 177, 178, 179 ], // Adar I
103 [ 206, 207, 208 ], // Adar II
104 [ 236, 237, 238 ], // Nisan
105 [ 265, 266, 267 ], // Iyar
106 [ 295, 296, 297 ], // Sivan
107 [ 324, 325, 326 ], // Tammuz
108 [ 354, 355, 356 ], // Av
109 [ 383, 384, 385 ] // Elul
110 ],
111
112 _GREGORIAN_MONTH_COUNT: [
113 //len len2 st st2
114 [ 31, 31, 0, 0 ], // Jan
115 [ 28, 29, 31, 31 ], // Feb
116 [ 31, 31, 59, 60 ], // Mar
117 [ 30, 30, 90, 91 ], // Apr
118 [ 31, 31, 120, 121 ], // May
119 [ 30, 30, 151, 152 ], // Jun
120 [ 31, 31, 181, 182 ], // Jul
121 [ 31, 31, 212, 213 ], // Aug
122 [ 30, 30, 243, 244 ], // Sep
123 [ 31, 31, 273, 274 ], // Oct
124 [ 30, 30, 304, 305 ], // Nov
125 [ 31, 31, 334, 335 ] // Dec
126 // len length of month
127 // len2 length of month in a leap year
128 // st days in year before start of month
129 // st2 days in year before month in leap year
130 ],
131
132 _date: 0,
133 _month: 0,
134 _year: 0,
135 _hours: 0,
136 _minutes: 0,
137 _seconds: 0,
138 _milliseconds: 0,
139 _day: 0,
140
141 constructor: function(){
142 // summary:
143 // initialize the date object value
144 // example:
145 // | var date1 = new dojox.date.hebrew.Date();
146 // | var date2 = new dojox.date.hebrew.Date(date1);
147 // | var date3 = new dojox.date.hebrew.Date(5768,2,12);
148
149 var len = arguments.length;
150 if(!len){// use the current date value, added "" to the similarity to date
151 this.fromGregorian(new Date());
152 }else if(len == 1){
153 var arg0 = arguments[0];
154 if(typeof arg0 == "number"){ // this is time "valueof"
155 arg0 = new Date(arg0);
156 }
157
158 if(arg0 instanceof Date){
159 this.fromGregorian(arg0);
160 }else if(arg0 == ""){
161 // date should be invalid. Dijit relies on this behavior.
162 this._year = this._month = this._date = this._hours = this._minutes = this._seconds = this._milliseconds = NaN;
163 }else{ // this is hebrew.Date object
164 this._year = arg0._year;
165 this._month = arg0._month;
166 this._date = arg0._date;
167 this._hours = arg0._hours;
168 this._minutes = arg0._minutes;
169 this._seconds = arg0._seconds;
170 this._milliseconds = arg0._milliseconds;
171 }
172 }else if(len >= 3){
173 // YYYY, MM, DD arguments passed, month is from 0-12, "absolute" index of month
174 this._year += arguments[0];
175 this._month += arguments[1];
176 this._date += arguments[2];
177
178 if(this._month > 12){
179 console.warn("the month is incorrect , set 0 " + this._month + " " + this._year );
180 this._month = 0;
181 }
182 this._hours += arguments[3] || 0;
183 this._minutes += arguments[4] || 0;
184 this._seconds += arguments[5] || 0;
185 this._milliseconds += arguments[6] || 0;
186 }
187
188 this._setDay();
189 },
190
191 getDate: function(){
192 // summary:
193 // returns the date value (1 - 30)
194 // example:
195 // | var date1 = new dojox.date.hebrew.Date();
196 // | console.log(date1.getDate());
197
198 return this._date; // int
199 },
200
201 getDateLocalized: function(/*String?*/locale){
202 // summary:
203 // returns the date value as hebrew numerals for the Hebrew locale,
204 // a number for all others.
205 // example:
206 // | var date1 = new dojox.date.hebrew.Date();
207 // | console.log(date1.getDate());
208
209 return (locale || dojo.locale).match(/^he(?:-.+)?$/) ?
210 numerals.getDayHebrewLetters(this._date) : this.getDate();
211 },
212
213 getMonth: function(){
214 // summary:
215 // returns the month value (0 - 12)
216 // description:
217 // the result is the index in the month array:
218 //
219 // 0. Tishri
220 // 1. Heshvan
221 // 2. Kislev
222 // 3. Tevet
223 // 4. Shevat
224 // 5. Adar I (leap years only)
225 // 6. Adar
226 // 7. Nisan
227 // 8. Iyar
228 // 9. Sivan
229 // 10. Tammuz
230 // 11. Av
231 // 12. Elul - 12
232 //
233 // For non leap years, for months after Shevat, the actual position of
234 // the month in the year (used for short format) is less than
235 // the "absolute" index by 1.
236 // example:
237 // | var date1 = new dojox.date.hebrew.Date(5769, 6, 1);
238 // | console.log(date1.getMonth()+1);
239 // | >> 7
240
241 return this._month;
242 },
243
244 getFullYear: function(){
245 // summary:
246 // returns the Year value
247 // example:
248 // | var date1 = new dojox.date.hebrew.Date(5769, 6, 1);
249 // | console.log(date1.getFullYear());
250 // | >> 5769
251 return this._year;
252 },
253
254 getHours: function(){
255 // summary:
256 // returns the hour value
257 return this._hours;
258 },
259
260 getMinutes: function(){
261 // summary:
262 // returns the minutes value
263
264 return this._minutes;
265 },
266
267 getSeconds: function(){
268 // summary:
269 // returns the seconds value
270 return this._seconds;
271 },
272
273 getMilliseconds: function(){
274 // summary:
275 // returns the milliseconds value
276
277 return this._milliseconds;
278 },
279
280 setDate: function(/*number*/date){
281 // summary:
282 // sets the date number for a given month
283 // example:
284 // | var date1 = new dojox.date.hebrew.Date(5769, 6, 1);
285 // | date1.setDate(2);
286
287 date = +date;
288 var mdays;
289 if(date>0){
290 while (date > (mdays = this.getDaysInHebrewMonth(this._month, this._year))){
291 date -= mdays;
292 this._month++;
293 if(this._month >= 13){this._year++; this._month -= 13;}
294 }
295 }else{
296 while(date<=0){
297 mdays = this.getDaysInHebrewMonth((this._month-1)>=0 ? (this._month-1) : 12, ((this._month-1)>=0)? this._year : this._year-1);
298 this._month--;
299 if(this._month < 0){this._year--; this._month += 13;}
300 date += mdays;
301 }
302 }
303 this._date = date;
304 this._setDay();
305 return this;
306 },
307
308
309 setFullYear: function(/*number*/year, /*number?*/month, /*number?*/ date){
310 // summary:
311 // set the year
312 // example:
313 // | var date1 = new dojox.date.hebrew.Date();
314 // | date1.setFullYear(5768);
315 // | date1.setFullYear(5768, 1, 1);
316
317 this._year = year = +year;
318 if(!this.isLeapYear(year) && this._month==5){ //incorrect month number for non leap year
319 this._month++;
320 }
321
322 if(month !== undefined){this.setMonth(month);}
323 if(date !== undefined){this.setDate(date);}
324
325 var dnum = this.getDaysInHebrewMonth(this._month, this._year);
326 if(dnum < this._date){
327 this._date = dnum;
328 } // if the date in this month more than number of the days in this month
329
330 this._setDay();
331 return this;
332 },
333
334 setMonth: function(/*number*/month){
335 // summary:
336 // sets the month. You should use "absolute" index in the month array:
337 //
338 // 0. Tishri
339 // 1. Heshvan
340 // 2. Kislev
341 // 3. Tevet
342 // 4. Shevat
343 // 5. Adar I (leap years only)
344 // 6. Adar
345 // 7. Nisan
346 // 8. Iyar
347 // 9. Sivan
348 // 10. Tammuz
349 // 11. Av
350 // 12. Elul - 12
351 //
352 // For non leap years, for months after Shevat, the actual position of
353 // the month in the year (used for short format) is less than
354 // the "absolute" index by 1.
355 // example:
356 // | var date1 = new dojox.date.hebrew.Date();
357 // | date1.setMonth(0); //first month
358
359 month = +month; // coerce to a Number
360 if(!this.isLeapYear(this._year) && month == 5){month++;}
361
362 if(month>=0){
363 while(month >12){
364 this._year++;
365 month -= 13;
366 if (!this.isLeapYear(this._year) && month >= 5){month++;}
367 }
368 }else{
369 while(month<0){
370 this._year--;
371 month += (!this.isLeapYear(this._year) && month < -7) ? 12 : 13;
372 }
373 }
374
375 this._month = month;
376
377 var dnum = this.getDaysInHebrewMonth(this._month, this._year);
378 if(dnum < this._date){
379 this._date = dnum;
380 } // if the date in this month more than number of the days in this month
381
382 this._setDay();
383 return this;
384 },
385
386 setHours: function(){
387 // summary:
388 // sets the hour
389 // description:
390 // Sets the hour and optionally minutes, seconds, milliseconds also.
391 // example:
392 // | var date1 = new dojox.date.hebrew.Date();
393 // | date1.setHours(12, 30, 0, 0);
394
395 var hours_arg_no = arguments.length;
396 var hours = 0;
397 if(hours_arg_no >= 1){
398 hours = +arguments[0];
399 }
400
401 if(hours_arg_no >= 2){
402 this._minutes = +arguments[1];
403 }
404
405 if(hours_arg_no >= 3){
406 this._seconds = +arguments[2];
407 }
408
409 if(hours_arg_no == 4){
410 this._milliseconds = +arguments[3];
411 }
412
413 while(hours >= 24){
414 this._date++;
415 var mdays = this.getDaysInHebrewMonth(this._month, this._year);
416 if(this._date > mdays)
417 {
418 this._month++;
419 if(!this.isLeapYear(this._year) && this._month==5){ this._month++; }
420 if(this._month >= 13){this._year++; this._month -= 13;}
421 this._date -= mdays;
422 }
423 hours -= 24;
424 }
425 this._hours = hours;
426 this._setDay();
427 return this;
428 },
429
430 _addMinutes: function(/*Number*/minutes){
431 minutes += this._minutes;
432 this.setMinutes(minutes);
433 this.setHours(this._hours + parseInt(minutes / 60));
434 return this;
435 },
436
437 _addSeconds: function(/*Number*/seconds){
438 seconds += this._seconds;
439 this.setSeconds(seconds);
440 this._addMinutes(parseInt(seconds / 60));
441 return this;
442 },
443
444 _addMilliseconds: function(/*Number*/milliseconds){
445 milliseconds += this._milliseconds;
446 this.setMilliseconds(milliseconds);
447 this._addSeconds(parseInt(milliseconds / 1000));
448 return this;
449 },
450
451 setMinutes: function(/*Number*/minutes){
452 // summary:
453 // sets the minutes (0-59) only.
454 this._minutes = minutes % 60;
455 return this;
456 },
457
458 setSeconds: function(/*Number*/seconds){
459 // summary:
460 // sets the seconds (0-59) only.
461 this._seconds = seconds % 60;
462 return this;
463 },
464
465 setMilliseconds: function(/*Number*/milliseconds){
466 this._milliseconds = milliseconds % 1000;
467 return this;
468 },
469
470 _setDay: function(){
471 var day = this._startOfYear(this._year);
472 if(this._month != 0){
473 day += (this.isLeapYear(this._year) ? this._LEAP_MONTH_START : this._MONTH_START)[this._month || 0][this._yearType(this._year)];
474 }
475 day += this._date - 1;
476 this._day = (day+1) % 7;
477 },
478
479 toString: function(){
480 // summary:
481 // returns a string representation of the date in "dd, MM, yyyy HH:mm:ss" format
482 // description:
483 // returns a string representation of the date in "dd, MM, yyyy HH:mm:ss" format (all numeric)
484 // For user presentation, use dojox.date.hebrew.locale.format which will present in the appropriate language
485 // and format. toString() language- and culturally-specific conventions to keep this module free of
486 // dependencies on dojox.date.locale and dojo.cldr.
487 // example:
488 // | var date1 = new dojox.date.hebrew.Date(5769, 6, 1);
489 // | console.log(date1.toString());
490 // | >>> "1, 6, 5769 0:0:0"
491 return isNaN(this._date)?"Invalid Date":
492 this._date + ", " + this._month + ", " + this._year + " " + this._hours + ":" + this._minutes + ":" + this._seconds; // String
493 },
494
495 // ported from the Java class com.ibm.icu.util.HebrewCalendar from ICU4J v3.6.1 at http://www.icu-project.org/
496 getDaysInHebrewMonth: function(/*Number*/month, /*Number*/ year){
497 // summary:
498 // returns the number of days in the given month and year
499
500 // Aside from the leap month, these two months can vary: 1=HESHVAN, 2=KISLEV
501 // The rest are a fixed length
502 var yearType = (month == 1 || month == 2) ? this._yearType(year) : 0;
503 return (!this.isLeapYear(this._year) && month == 5) ? 0 : this._MONTH_LENGTH[month][yearType];
504 },
505
506 // ported from the Java class com.ibm.icu.util.HebrewCalendar from ICU4J v3.6.1 at http://www.icu-project.org/
507 _yearType: function(/*Number*/year){
508 var yearLength = this._handleGetYearLength(Number(year));
509 if(yearLength > 380){
510 yearLength -= 30; // Subtract length of leap month.
511 }
512
513 var yearType = yearLength - 353;
514 if (yearType < 0 || yearType > 2){
515 throw new Error("Illegal year length " + yearLength + " in year " + year);
516 }
517 return yearType;
518 },
519
520 // ported from the Java class com.ibm.icu.util.HebrewCalendar from ICU4J v3.6.1 at http://www.icu-project.org/
521 _handleGetYearLength: function(/*number*/eyear){
522 return this._startOfYear(eyear+1) - this._startOfYear(eyear);
523 },
524
525 // ported from the Java class com.ibm.icu.util.HebrewCalendar from ICU4J v3.6.1 at http://www.icu-project.org/
526 _startOfYear: function(/*number*/year){
527 var months = Math.floor((235 * year - 234) / 19), // # of months before year
528 frac = months * (12*1080 + 793) + 11*1080 + 204/*BAHARAD*/, // Fractional part of day #
529 day = months * 29 + Math.floor(frac / (24*1080)); // Whole # part of calculation
530 frac %= 24*1080; // Time of day
531
532 var wd = day % 7; // Day of week (0 == Monday)
533
534 if(wd == 2 || wd == 4 || wd == 6){
535 // If the 1st is on Sun, Wed, or Fri, postpone to the next day
536 day += 1;
537 wd = day % 7;
538 }
539 if(wd == 1 && frac > 15 * 1080 + 204 && !this.isLeapYear(year)){
540 // If the new moon falls after 3:11:20am (15h204p from the previous noon)
541 // on a Tuesday and it is not a leap year, postpone by 2 days.
542 // This prevents 356-day years.
543 day += 2;
544 }else if(wd == 0 && frac > 21 * 1080 + 589 && this.isLeapYear(year-1)){
545 // If the new moon falls after 9:32:43 1/3am (21h589p from yesterday noon)
546 // on a Monday and *last* year was a leap year, postpone by 1 day.
547 // Prevents 382-day years.
548 day += 1;
549 }
550
551 return day;
552 },
553
554 // ported from the Java class com.ibm.icu.util.HebrewCalendar from ICU4J v3.6.1 at http://www.icu-project.org/
555 isLeapYear: function(/*Number*/year){
556 // summary:
557 // Determines if the year (argument) is a leap year
558 // description:
559 // The Leap year contains additional month adar sheni
560
561 //return (year * 12 + 17) % 19 >= 12;
562 var x = (year*12 + 17) % 19;
563 return x >= ((x < 0) ? -7 : 12);
564 },
565
566
567 fromGregorian: function(/*Date*/gdate){
568 // summary:
569 // This function sets this Date to the Hebrew Date corresponding to the Gregorian Date
570 // example:
571 // | var dateHebrew = new dojox.date.hebrew.Date();
572 // | var dateGregorian = new Date(2008,10,12);
573 // | dateHebrew.fromGregorian(dateGregorian);
574
575 var result = (!isNaN(gdate)) ? this._computeHebrewFields(gdate) : NaN;
576 this._year = (!isNaN(gdate)) ? result[0] : NaN;
577 this._month = (!isNaN(gdate))? result[1] : NaN;
578 this._date = (!isNaN(gdate)) ? result[2] : NaN;
579 this._hours = gdate.getHours();
580 this._milliseconds = gdate.getMilliseconds();
581 this._minutes = gdate.getMinutes();
582 this._seconds = gdate.getSeconds();
583 if (!isNaN(gdate)) this._setDay();
584 return this;
585 },
586
587 // ported from the Java class com.ibm.icu.util.HebrewCalendar.handleComputeFields from ICU4J v3.6.1 at http://www.icu-project.org/
588 _computeHebrewFields: function(/*Date*/gdate){
589 var julianDay = this._getJulianDayFromGregorianDate(gdate),
590 d = julianDay - 347997,
591 m = Math.floor((d * 24*1080) / (29*24*1080 + 12*1080 + 793)), // Months (approx)
592 year = Math.floor((19 * m + 234) / 235) + 1, // Years (approx)
593 ys = this._startOfYear(year), // 1st day of year
594 dayOfYear = (d - ys);
595 // Because of the postponement rules, it's possible to guess wrong. Fix it.
596 while(dayOfYear < 1){
597 year--;
598 ys = this._startOfYear(year);
599 dayOfYear = d - ys;
600 }
601
602 // Now figure out which month we're in, and the date within that month
603
604 var typeofYear = this._yearType(year),
605 monthStart = this.isLeapYear(year) ? this._LEAP_MONTH_START : this._MONTH_START,
606 month = 0;
607
608 while(dayOfYear > monthStart[month][typeofYear]){
609 month++;
610 }
611 month--;
612 var dayOfMonth = dayOfYear - monthStart[month][typeofYear];
613 return [year, month, dayOfMonth];
614 },
615
616 // ported from the Java class com.ibm.icu.util.Calendar.computeGregorianFields from ICU4J v3.6.1 at http://www.icu-project.org/
617 toGregorian: function(){
618 // summary:
619 // returns the equivalent Gregorian date value as a native Date object
620 // example:
621 // | var dateHebrew = new dojox.date.hebrew.Date(5768,11,20);
622 // | var dateGregorian = dateHebrew.toGregorian();
623
624 var hYear = this._year || 0,
625 hMonth = this._month || 0,
626 hDate = this._date || 0,
627 day = this._startOfYear(hYear);
628
629 if(hMonth != 0){
630 day += (this.isLeapYear(hYear) ? this._LEAP_MONTH_START : this._MONTH_START)[hMonth][this._yearType(hYear)];
631 }
632
633 var julianDay = (hDate + day + 347997),
634 // The Gregorian epoch day is zero for Monday January 1, year 1.
635 gregorianEpochDay = julianDay - 1721426;
636
637 // Here we convert from the day number to the multiple radix
638 // representation. We use 400-year, 100-year, and 4-year cycles.
639 // For example, the 4-year cycle has 4 years + 1 leap day; giving
640 // 1461 == 365*4 + 1 days.
641 var rem = [];
642 var n400 = this._floorDivide(gregorianEpochDay , 146097, rem), // 400-year cycle length
643 n100 = this._floorDivide(rem[0] , 36524, rem), // 100-year cycle length
644 n4 = this._floorDivide(rem[0] , 1461, rem), // 4-year cycle length
645 n1 = this._floorDivide(rem[0] , 365, rem),
646 year = 400*n400 + 100*n100 + 4*n4 + n1,
647 dayOfYear = rem[0]; // zero-based day of year
648
649 if(n100 == 4 || n1 == 4){
650 dayOfYear = 365; // Dec 31 at end of 4- or 400-yr cycle
651 }else{
652 ++year;
653 }
654
655 var isLeap = !(year%4) && // equiv. to (year%4 == 0)
656 (year%100 || !(year%400)),
657 correction = 0,
658 march1 = isLeap ? 60 : 59; // zero-based DOY for March 1
659 if(dayOfYear >= march1){ correction = isLeap ? 1 : 2; }
660 var month = Math.floor((12 * (dayOfYear + correction) + 6) / 367); // zero-based month
661 var dayOfMonth = dayOfYear -
662 this._GREGORIAN_MONTH_COUNT[month][isLeap ? 3 : 2] + 1; // one-based DOM
663
664 return new Date(year, month, dayOfMonth, this._hours, this._minutes, this._seconds, this._milliseconds); // Date
665 },
666 _floorDivide: function(numerator, denominator, remainder){
667 if(numerator >= 0){
668 remainder[0] = (numerator % denominator);
669 return Math.floor(numerator / denominator);
670 }
671 var quotient = Math.floor(numerator / denominator);
672 remainder[0] = numerator - (quotient * denominator);
673 return quotient;
674 },
675
676 getDay: function(){
677 // summary:
678 // returns weekday value (0 - 6)
679 // example:
680 // | var date1 = new dojox.date.hebrew.Date();
681 // | console.log(date1.getDay());
682
683 var hYear = this._year,
684 hMonth = this._month,
685 hDate = this._date,
686 day = this._startOfYear(hYear);
687
688 if(hMonth != 0){
689 day += (this.isLeapYear(hYear) ? this._LEAP_MONTH_START : this._MONTH_START)[hMonth][this._yearType(hYear)];
690 }
691
692 day += hDate - 1;
693 return (day+1) % 7;
694 },
695
696 // ported from the Java class com.ibm.icu.util.Calendar.computeGregorianMonthStart from ICU4J v3.6.1 at http://www.icu-project.org/
697 _getJulianDayFromGregorianDate: function(gdate){
698 // summary:
699 // returns the Julian day of a Gregorian date
700
701 var year = gdate.getFullYear(),
702 month = gdate.getMonth(),
703 d = gdate.getDate(),
704 isLeap = !(year%4) && (year%100 || !(year%400)), //TODO: dup
705 y = year - 1;
706 // This computation is actually ... + (_JAN_1_1_JULIAN_DAY - 3) + 2.
707 // Add 2 because Gregorian calendar starts 2 days after Julian
708 // calendar.
709 var julianDay = 365*y + Math.floor(y/4) - Math.floor(y/100) +
710 Math.floor(y/400) + 1721426 - 1;
711 // At this point julianDay indicates the day BEFORE the first day
712 // of January 1, <eyear> of the Gregorian calendar.
713 if(month > 0) {
714 julianDay += this._GREGORIAN_MONTH_COUNT[month][isLeap ? 3 : 2];
715 }
716
717 julianDay += d;
718 return julianDay;
719 }
720 });
721
722 HDate.prototype.valueOf = function(){
723 return this.toGregorian().valueOf();
724 };
725 return HDate;
726 });