umalquraCalendar.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. define(["../impl/Record", "../impl/calendarFunctions", "./gregorianCalendar", "./islamicCalendar"],
  2. function (Record, calendarFunctions, gregorian, islamicCalendar) {
  3. return {
  4. MONTH_LENGTH:
  5. //1300-1304
  6. ["101010101010", "110101010100", "111011001001", "011011010100", "011011101010",
  7. //1305-1309
  8. "001101101100", "101010101101", "010101010101", "011010101001", "011110010010",
  9. //1310-1314
  10. "101110101001", "010111010100", "101011011010", "010101011100", "110100101101",
  11. //1315-1319
  12. "011010010101", "011101001010", "101101010100", "101101101010", "010110101101",
  13. //1320-1324
  14. "010010101110", "101001001111", "010100010111", "011010001011", "011010100101",
  15. //1325-1329
  16. "101011010101", "001011010110", "100101011011", "010010011101", "101001001101",
  17. //1330-1334
  18. "110100100110", "110110010101", "010110101100", "100110110110", "001010111010",
  19. //1335-1339
  20. "101001011011", "010100101011", "101010010101", "011011001010", "101011101001",
  21. //1340-1344
  22. "001011110100", "100101110110", "001010110110", "100101010110", "101011001010",
  23. //1345-1349
  24. "101110100100", "101111010010", "010111011001", "001011011100", "100101101101",
  25. //1350-1354
  26. "010101001101", "101010100101", "101101010010", "101110100101", "010110110100",
  27. //1355-1359
  28. "100110110110", "010101010111", "001010010111", "010101001011", "011010100011",
  29. //1360-1364
  30. "011101010010", "101101100101", "010101101010", "101010101011", "010100101011",
  31. //1365-1369
  32. "110010010101", "110101001010", "110110100101", "010111001010", "101011010110",
  33. //1370-1374
  34. "100101010111", "010010101011", "100101001011", "101010100101", "101101010010",
  35. //1375-1379
  36. "101101101010", "010101110101", "001001110110", "100010110111", "010001011011",
  37. //1380-1384
  38. "010101010101", "010110101001", "010110110100", "100111011010", "010011011101",
  39. //1385-1389
  40. "001001101110", "100100110110", "101010101010", "110101010100", "110110110010",
  41. //1390-1394
  42. "010111010101", "001011011010", "100101011011", "010010101011", "101001010101",
  43. //1395-1399
  44. "101101001001", "101101100100", "101101110001", "010110110100", "101010110101",
  45. //1400-1404
  46. "101001010101", "110100100101", "111010010010", "111011001001", "011011010100",
  47. //1405-1409
  48. "101011101001", "100101101011", "010010101011", "101010010011", "110101001001",
  49. //1410-1414
  50. "110110100100", "110110110010", "101010111001", "010010111010", "101001011011",
  51. //1415-1419
  52. "010100101011", "101010010101", "101100101010", "101101010101", "010101011100",
  53. //1420-1424
  54. "010010111101", "001000111101", "100100011101", "101010010101", "101101001010",
  55. //1425-1429
  56. "101101011010", "010101101101", "001010110110", "100100111011", "010010011011",
  57. //1430-1434
  58. "011001010101", "011010101001", "011101010100", "101101101010", "010101101100",
  59. //1435-1439
  60. "101010101101", "010101010101", "101100101001", "101110010010", "101110101001",
  61. //1440-1444
  62. "010111010100", "101011011010", "010101011010", "101010101011", "010110010101",
  63. //1445-1449
  64. "011101001001", "011101100100", "101110101010", "010110110101", "001010110110",
  65. //1450-1454
  66. "101001010110", "111001001101", "101100100101", "101101010010", "101101101010",
  67. //1455-1459
  68. "010110101101", "001010101110", "100100101111", "010010010111", "011001001011",
  69. //1460-1464
  70. "011010100101", "011010101100", "101011010110", "010101011101", "010010011101",
  71. //1465-1469
  72. "101001001101", "110100010110", "110110010101", "010110101010", "010110110101",
  73. //1470-1474
  74. "001011011010", "100101011011", "010010101101", "010110010101", "011011001010",
  75. //1475-1479
  76. "011011100100", "101011101010", "010011110101", "001010110110", "100101010110",
  77. //1480-1484
  78. "101010101010", "101101010100", "101111010010", "010111011001", "001011101010",
  79. //1485-1489
  80. "100101101101", "010010101101", "101010010101", "101101001010", "101110100101",
  81. //1490-1494
  82. "010110110010", "100110110101", "010011010110", "101010010111", "010101000111",
  83. //1495-1499
  84. "011010010011", "011101001001", "101101010101", "010101101010", "101001101011",
  85. //1500-1504
  86. "010100101011", "101010001011", "110101000110", "110110100011", "010111001010",
  87. //1505-1509
  88. "101011010110", "010011011011", "001001101011", "100101001011", "101010100101",
  89. //1510-1514
  90. "101101010010", "101101101001", "010101110101", "000101110110", "100010110111",
  91. //1515-1519
  92. "001001011011", "010100101011", "010101100101", "010110110100", "100111011010",
  93. //1520-1524
  94. "010011101101", "000101101101", "100010110110", "101010100110", "110101010010",
  95. //1525-1529
  96. "110110101001", "010111010100", "101011011010", "100101011011", "010010101011",
  97. //1530-1534
  98. "011001010011", "011100101001", "011101100010", "101110101001", "010110110010",
  99. //1535-1539
  100. "101010110101", "010101010101", "101100100101", "110110010010", "111011001001",
  101. //1540-1544
  102. "011011010010", "101011101001", "010101101011", "010010101011", "101001010101",
  103. //1545-1549
  104. "110100101001", "110101010100", "110110101010", "100110110101", "010010111010",
  105. //1550-1554
  106. "101000111011", "010010011011", "101001001101", "101010101010", "101011010101",
  107. //1555-1559
  108. "001011011010", "100101011101", "010001011110", "101000101110", "110010011010",
  109. //1560-1564
  110. "110101010101", "011010110010", "011010111001", "010010111010", "101001011101",
  111. //1565-1569
  112. "010100101101", "101010010101", "101101010010", "101110101000", "101110110100",
  113. //1570-1574
  114. "010110111001", "001011011010", "100101011010", "101101001010", "110110100100",
  115. //1575-1579
  116. "111011010001", "011011101000", "101101101010", "010101101101", "010100110101",
  117. //1580-1584
  118. "011010010101", "110101001010", "110110101000", "110111010100", "011011011010",
  119. //1585-1589
  120. "010101011011", "001010011101", "011000101011", "101100010101", "101101001010",
  121. //1590-1594
  122. "101110010101", "010110101010", "101010101110", "100100101110", "110010001111",
  123. //1595-1599
  124. "010100100111", "011010010101", "011010101010", "101011010110", "010101011101",
  125. //1600
  126. "001010011101"
  127. ],
  128. getDaysDiff: function (date1, date2) {
  129. // summary:
  130. // This function returns the number of days between two different dates.
  131. var ONE_DAY = 1000 * 60 * 60 * 24;
  132. var diff = Math.abs(date1.getTime() - date2.getTime());
  133. return Math.round(diff / ONE_DAY);
  134. },
  135. fromGregorian: function ( /* Date */ gdate) {
  136. // summary:
  137. // This function returns the equivalent islamic(umalqura) date value for a give input gregorian date.
  138. // gdate: Date
  139. // Gregorian date which will be converted to islamic date
  140. // returns:
  141. // Islamic(umalqura) date.
  142. var date = new Date(gdate);
  143. var gregorianFirstRef = new Date(1882, 10, 12, 0, 0, 0, 0);
  144. var gregorianLastRef = new Date(2174, 10, 25, 23, 59, 59, 999);
  145. var daysDiff = this.getDaysDiff(date, gregorianFirstRef);
  146. if (date - gregorianFirstRef >= 0 && date - gregorianLastRef <= 0) {
  147. var year = 1300;
  148. for (var i = 0; i < this.MONTH_LENGTH.length; i++, year++) {
  149. for (var j = 0; j < 12; j++) {
  150. var numOfDays = parseInt(this.MONTH_LENGTH[i][j], 10) + 29;
  151. if (daysDiff <= numOfDays) {
  152. this.date = daysDiff + 1;
  153. if (this.date > numOfDays) {
  154. this.date = 1;
  155. j++;
  156. }
  157. if (j > 11) {
  158. j = 0;
  159. year++;
  160. }
  161. this.month = j;
  162. this.year = year;
  163. this.hours = date.getHours();
  164. this.minutes = date.getMinutes();
  165. this.seconds = date.getSeconds();
  166. this.milliseconds = date.getMilliseconds();
  167. this.day = date.getDay();
  168. return this;
  169. }
  170. daysDiff = parseInt(daysDiff, 10) - numOfDays;
  171. }
  172. }
  173. } else {
  174. var islamicDate = islamicCalendar.fromGregorian(date);
  175. this.date = islamicDate.date;
  176. this.month = islamicDate.month;
  177. this.year = islamicDate.year;
  178. this.hours = islamicDate.hours;
  179. this.minutes = islamicDate.minutes;
  180. this.seconds = islamicDate.seconds;
  181. this.milliseconds = islamicDate.milliseconds;
  182. this.day = islamicDate.day;
  183. }
  184. return this;
  185. },
  186. toLocalTime: function (date, timeZone) {
  187. var islamicDate = this.fromGregorian(date);
  188. var dt = new Date(date);
  189. var result = new Record();
  190. result.set("weekday", timeZone === "UTC" ? dt.getUTCDay() : dt.getDay());
  191. result.set("era", 0);
  192. result.set("year", islamicDate.year);
  193. result.set("month", islamicDate.month);
  194. result.set("day", islamicDate.date);
  195. calendarFunctions.setTimeFields(dt, timeZone, result);
  196. return result;
  197. }
  198. };
  199. });