index.esm.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. var DateMapping = /** @class */ (function () {
  2. function DateMapping(monthsLengthFlags, gy, gm, gd) {
  3. this.hijriMonthsLengthFlags = monthsLengthFlags;
  4. this.gregorianDate = new Date(gy, gm, gd);
  5. }
  6. return DateMapping;
  7. }());
  8. var DatePart;
  9. (function (DatePart) {
  10. DatePart[DatePart["Year"] = 0] = "Year";
  11. DatePart[DatePart["DayOfYear"] = 1] = "DayOfYear";
  12. DatePart[DatePart["Month"] = 2] = "Month";
  13. DatePart[DatePart["Day"] = 3] = "Day";
  14. })(DatePart || (DatePart = {}));
  15. var DatePart$1 = DatePart;
  16. // Parts of this file are (c) 2007-2009 Steven Levithan <stevenlevithan.com>
  17. // https://github.com/felixge/node-dateformat/blob/master/lib/dateformat.js
  18. var token = /d{1,4}|M{1,4}|yy(?:yy)?|([HhmsTt])\1?|[LlSWN]|"[^"]*"|'[^']*'/g;
  19. function pad(val, locale, len) {
  20. val = String(val);
  21. len = len || 2;
  22. while (val.length < len) {
  23. val = '0' + val;
  24. }
  25. return locale.localizeNum(val);
  26. }
  27. function format(date, mask, locale, hy, hm, hd, woy, dow) {
  28. mask = String(locale.masks[mask] || mask || locale.masks.default);
  29. var _ = 'get';
  30. var d = hd;
  31. var D = date[_ + 'Day']();
  32. var m = hm;
  33. var y = hy;
  34. var H = date[_ + 'Hours']();
  35. var M = date[_ + 'Minutes']();
  36. var s = date[_ + 'Seconds']();
  37. var L = date[_ + 'Milliseconds']();
  38. var W = woy;
  39. var N = dow;
  40. var flags = {
  41. d: locale.localizeNum(d),
  42. dd: pad(d, locale),
  43. ddd: locale.dayNamesShort[D],
  44. dddd: locale.dayNames[D],
  45. M: locale.localizeNum(m),
  46. MM: pad(m, locale),
  47. MMM: locale.monthNamesShort[m - 1],
  48. MMMM: locale.monthNames[m - 1],
  49. yy: locale.localizeNum(String(y).slice(2)),
  50. yyyy: locale.localizeNum(y),
  51. h: locale.localizeNum(H % 12 || 12),
  52. hh: pad(H % 12 || 12, locale),
  53. H: locale.localizeNum(H),
  54. HH: pad(H, locale),
  55. m: locale.localizeNum(M),
  56. mm: pad(M, locale),
  57. s: locale.localizeNum(s),
  58. ss: pad(s, locale),
  59. l: pad(L, locale, 3),
  60. L: pad(Math.round(L / 10), locale),
  61. t: H < 12 ? locale.timeNames[0] : locale.timeNames[1],
  62. tt: H < 12 ? locale.timeNames[2] : locale.timeNames[3],
  63. T: H < 12 ? locale.timeNames[4] : locale.timeNames[5],
  64. TT: H < 12 ? locale.timeNames[6] : locale.timeNames[7],
  65. S: locale.localizeDayNum(d),
  66. W: locale.localizeNum(W),
  67. N: locale.localizeNum(N),
  68. };
  69. return locale.localizeCommas(mask.replace(token, function (match) { return flags[match]; }));
  70. }
  71. var symbolMap = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
  72. var dayNumMap = ['الأول', 'الثاني', 'الثالث', 'الرابع', 'الخامس', 'السادس', 'السابع', 'الثامن', 'التاسع', 'العاشر', 'الحادي عشر'];
  73. var ar = {
  74. name: 'ar',
  75. rtl: true,
  76. dayNamesShort: ['ح', 'ن', 'ث', 'ر', 'خ', 'ج', 'س'],
  77. dayNames: ['الأحد', 'الإثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'],
  78. monthNamesShort: ['محرم', 'صفر', 'ربيع ١', 'ربيع ٢', 'جمادى ١', 'جمادى ٢', 'رجب', 'شعبان', 'رمضان', 'شوال', 'ذو القعدة', 'ذو الحجة'],
  79. monthNames: ['محرم', 'صفر', 'ربيع الأول', 'ربيع الثاني', 'جمادى الأولى', 'جمادى الآخرة', 'رجب', 'شعبان', 'رمضان', 'شوال', 'ذو القعدة', 'ذو الحجة'],
  80. timeNames: ['ص', 'م', 'ص', 'م', 'ص', 'م', 'ص', 'م'],
  81. masks: {
  82. default: 'ddd dd MMM yyyy HH:mm:ss',
  83. shortDate: 'yy/M/d',
  84. mediumDate: 'd MMM, yyyy',
  85. longDate: 'd MMMM, yyyy',
  86. fullDate: 'dddd, d MMMM, yyyy',
  87. shortTime: 'h:mm TT',
  88. mediumTime: 'h:mm:ss TT',
  89. longTime: 'h:mm:ss.l TT',
  90. },
  91. localizeNum: function (num) {
  92. var s = String(num);
  93. var output = '';
  94. for (var i = 0; i < s.length; i++) {
  95. output += symbolMap[s.charAt(i)];
  96. }
  97. return output;
  98. },
  99. localizeDayNum: function (d) {
  100. var output = '';
  101. if (d === 11) {
  102. output = 'الحادي عشر';
  103. }
  104. else if (d === 20) {
  105. output = 'العشرون';
  106. }
  107. else if (d === 30) {
  108. output = 'الثلاثون';
  109. }
  110. else {
  111. output = dayNumMap[d - 1];
  112. }
  113. var section = d / 10;
  114. if (section > 1.1 && section < 2) {
  115. output = dayNumMap[(d - 1) % 10] + ' عشر';
  116. }
  117. else if (section > 2 && section < 3) {
  118. output = dayNumMap[(d - 1) % 10] + ' والعشرون';
  119. }
  120. return output + ' من';
  121. },
  122. localizeCommas: function (v) { return v.replace(/,/g, '،'); },
  123. };
  124. var en = {
  125. name: 'en',
  126. dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  127. dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  128. monthNamesShort: ['Muh', 'Ṣaf', 'Rab-I', 'Rab-II', 'Jum-I', 'Jum-II', 'Raj', 'Sha', 'Ram', 'Shw', 'Dhū-Q', 'Dhū-Ḥ'],
  129. monthNames: ['Muharram', 'Ṣafar', 'Rabīʿ al-Awwal', 'Rabīʿ ath-Thānī', 'Jumādá al-Ūlá', 'Jumādá al-Ākhirah', 'Rajab', 'Sha‘bān', 'Ramaḍān', 'Shawwāl', 'Dhū al-Qa‘dah', 'Dhū al-Ḥijjah'],
  130. timeNames: ['a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM'],
  131. masks: {
  132. default: 'ddd MMM dd yyyy HH:mm:ss',
  133. shortDate: 'M/d/yy',
  134. mediumDate: 'MMM d, yyyy',
  135. longDate: 'MMMM d, yyyy',
  136. fullDate: 'dddd, MMMM d, yyyy',
  137. shortTime: 'h:mm TT',
  138. mediumTime: 'h:mm:ss TT',
  139. longTime: 'h:mm:ss.l TT',
  140. },
  141. localizeNum: function (num) { return String(num); },
  142. // @ts-ignore
  143. localizeDayNum: function (d) { return ['th', 'st', 'nd', 'rd'][d % 10 > 3 ? 0 : (d % 100 - d % 10 !== 10) * d % 10]; },
  144. localizeCommas: function (v) { return v; },
  145. };
  146. /// Calendar support range:
  147. /// Calendar Minimum Maximum
  148. /// ========== ========== ==========
  149. /// Gregorian 1900/04/30 2077/11/16
  150. /// UmAlQura 1318/01/01 1500/12/30
  151. var UmAlQuraStatic = /** @class */ (function () {
  152. function UmAlQuraStatic() {
  153. }
  154. /**
  155. * Coverts the given Hijri date to Gregorian.
  156. * @param hy The Hijri year
  157. * @param hm The Hijri month
  158. * @param hd The Hijri day
  159. */
  160. UmAlQuraStatic.hijriToGregorian = function (hy, hm, hd) {
  161. this._checkYearRange(hy);
  162. this._checkMonthRange(hm);
  163. this._checkDayRange(hd);
  164. var nDays = hd - 1;
  165. var index = hy - this.minCalendarYear;
  166. var dt = this.hijriYearData[index].gregorianDate;
  167. var b = this.hijriYearData[index].hijriMonthsLengthFlags;
  168. for (var m = 1; m < hm; m++) {
  169. nDays = nDays + 29 + (b & 1);
  170. b >>= 1;
  171. }
  172. dt = this.addDays(dt, nDays);
  173. return {
  174. gy: dt.getFullYear(),
  175. gm: dt.getMonth(),
  176. gd: dt.getDate(),
  177. };
  178. };
  179. /**
  180. * Coverts the given Gregorian date to Hijri year, month and day.
  181. * @param date The date to be converted
  182. */
  183. UmAlQuraStatic.gregorianToHijri = function (date) {
  184. this._checkMillsRange(date.getTime());
  185. // Find the index where we should start our search by quessing the Hijri year that we will be in HijriYearInfo.
  186. // A Hijri year is 354 or 355 days. Use 355 days so that we will search from a lower index.
  187. var index = Math.trunc((date.getTime() - this.minDate.getTime()) / this.millisPerDay / 355);
  188. do {
  189. } while (date.getTime() > this.hijriYearData[++index].gregorianDate.getTime());
  190. if (date.getTime() !== this.hijriYearData[index].gregorianDate.getTime()) {
  191. index--;
  192. }
  193. var nDays = this._dayDiff(date, this.hijriYearData[index].gregorianDate);
  194. var yh1 = index + this.minCalendarYear;
  195. var mh1 = 1;
  196. var dh1 = 1;
  197. var b = this.hijriYearData[index].hijriMonthsLengthFlags;
  198. var daysPerThisMonth = 29 + (b & 1);
  199. while (nDays >= daysPerThisMonth) {
  200. nDays -= daysPerThisMonth;
  201. b >>= 1;
  202. daysPerThisMonth = 29 + (b & 1);
  203. mh1++;
  204. }
  205. dh1 += Math.trunc(nDays);
  206. return {
  207. hy: yh1,
  208. hm: mh1,
  209. hd: dh1,
  210. };
  211. };
  212. /**
  213. * Adds the specified amount of Hijri years to the given Gregorian date.
  214. * @param date The date
  215. * @param hys The Hijri years to be added
  216. */
  217. UmAlQuraStatic.addYears = function (date, hys) {
  218. return this.addMonths(date, hys * 12);
  219. };
  220. /**
  221. * Adds the specified amount of Hijri months to the given Gregorian date.
  222. * @param date The date
  223. * @param hms The Hijri months to be added
  224. */
  225. UmAlQuraStatic.addMonths = function (date, hms) {
  226. // Get the date in UmAlQura calendar.
  227. var y = this._getDatePart(date, DatePart$1.Year);
  228. var m = this._getDatePart(date, DatePart$1.Month);
  229. var d = this._getDatePart(date, DatePart$1.Day);
  230. var i = m - 1 + hms;
  231. if (i >= 0) {
  232. m = i % 12 + 1;
  233. y += Math.trunc(i / 12);
  234. }
  235. else {
  236. m = 12 + (i + 1) % 12;
  237. y += Math.trunc((i - 11) / 12);
  238. }
  239. if (d > 29) {
  240. var days = this.getDaysInMonth(y, m);
  241. if (d > days) {
  242. d = days;
  243. }
  244. }
  245. var _a = this.hijriToGregorian(y, m, d), gy = _a.gy, gm = _a.gm, gd = _a.gd;
  246. return this._setTime(new Date(gy, gm, gd), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
  247. };
  248. /**
  249. * Adds the specified amount of weeks to the given Gregorian date.
  250. * @param date The date
  251. * @param wks The weeks to be added
  252. */
  253. UmAlQuraStatic.addWeeks = function (date, wks) {
  254. return this.addDays(date, wks * 7);
  255. };
  256. /**
  257. * Adds the specified amount of days to the given Gregorian date.
  258. * @param date The date
  259. * @param days The days to be added
  260. */
  261. UmAlQuraStatic.addDays = function (date, days) {
  262. var d = new Date(date.valueOf());
  263. d.setDate(d.getDate() + days);
  264. return d;
  265. };
  266. /**
  267. * Adds the specified amount of units to the given Gregorian date.
  268. * @param date The date
  269. * @param value The amount of `unit`s to add
  270. * @param unit The unit of time
  271. */
  272. UmAlQuraStatic.addTime = function (date, value, unit) {
  273. var d = new Date(date.valueOf());
  274. switch (unit) {
  275. case 'hour':
  276. d.setHours(d.getHours() + value);
  277. break;
  278. case 'minute':
  279. d.setMinutes(d.getMinutes() + value);
  280. break;
  281. case 'second':
  282. d.setSeconds(d.getSeconds() + value);
  283. break;
  284. case 'millisecond':
  285. d.setMilliseconds(d.getMilliseconds() + value);
  286. break;
  287. default:
  288. throw new Error('Invalid value for `unit` param');
  289. }
  290. return d;
  291. };
  292. /**
  293. * Returns the Hijri day of year for the specified Gregorian date.
  294. * @param date The date
  295. */
  296. UmAlQuraStatic.getDayOfYear = function (date) {
  297. return this._getDatePart(date, DatePart$1.DayOfYear);
  298. };
  299. /**
  300. * Returns the Hijri day of month for the specified Gregorian date.
  301. * @param date The date
  302. */
  303. UmAlQuraStatic.getDayOfMonth = function (date) {
  304. return this._getDatePart(date, DatePart$1.Day);
  305. };
  306. /**
  307. * Returns the day of week for the specified Gregorian date.
  308. * @param date The date
  309. */
  310. UmAlQuraStatic.getDayOfWeek = function (date) {
  311. return date.getDay();
  312. };
  313. /**
  314. * Returns the Hijri week of year for the specified Gregorian date.
  315. * @param date The date
  316. */
  317. UmAlQuraStatic.getWeekOfYear = function (date) {
  318. var firstDayOfYear = this.startOf(date, 'year').getDay();
  319. var daysToDayOfWeek = firstDayOfYear - date.getDay();
  320. var d = this.addDays(date, daysToDayOfWeek);
  321. return Math.ceil(this.getDayOfYear(d) / 7);
  322. };
  323. /**
  324. * Returns the number of days in the specified Hijri year.
  325. * @param hy The Hijri year
  326. */
  327. UmAlQuraStatic.getDaysInYear = function (hy) {
  328. this._checkYearRange(hy);
  329. var days = 0;
  330. var b = this.hijriYearData[hy - this.minCalendarYear].hijriMonthsLengthFlags;
  331. for (var m = 1; m <= 12; m++) {
  332. days = days + 29 + (b & 1);
  333. b >>= 1;
  334. }
  335. if (days !== 354 && days !== 355) {
  336. throw new Error('Days in year assert error. This is possibly a bug.');
  337. }
  338. return days;
  339. };
  340. /**
  341. * Returns the number of days in the specified Hijri year and month.
  342. * @param hy The Hijri year
  343. * @param hm The Hijri month
  344. */
  345. UmAlQuraStatic.getDaysInMonth = function (hy, hm) {
  346. this._checkYearRange(hy);
  347. this._checkMonthRange(hm);
  348. if ((this.hijriYearData[hy - this.minCalendarYear].hijriMonthsLengthFlags & (1 << hm - 1)) === 0) {
  349. return 29;
  350. }
  351. else {
  352. return 30;
  353. }
  354. };
  355. /**
  356. * Returns the Hijri year corresponding to the given Gregorian date.
  357. * @param date The date
  358. */
  359. UmAlQuraStatic.getYear = function (date) {
  360. return this._getDatePart(date, DatePart$1.Year);
  361. };
  362. /**
  363. * Returns the Hijri month corresponding to the given Gregorian date.
  364. * @param date The date
  365. */
  366. UmAlQuraStatic.getMonth = function (date) {
  367. return this._getDatePart(date, DatePart$1.Month);
  368. };
  369. /**
  370. * Returns the Hijri month array for the given Gregorian date.
  371. * @param date The date
  372. */
  373. UmAlQuraStatic.getMonthArray = function (date) {
  374. var weeks = [];
  375. var month = this.getMonth(date);
  376. var start = this.startOf(this.startOf(date, 'month'), 'week');
  377. var end = this.endOf(this.endOf(date, 'month'), 'week');
  378. var i = 0;
  379. while (start < end) {
  380. var w = Math.floor(i / 7);
  381. var day = new Date(start.valueOf());
  382. weeks[w] = weeks[w] || [];
  383. weeks[w].push(this.getMonth(day) === month ? day : null);
  384. start.setDate(start.getDate() + 1);
  385. i++;
  386. }
  387. return weeks;
  388. };
  389. /**
  390. * Returns the Gregorian date corresponding to the Hijri date starting at the specified unit of time.
  391. * @param date: The date
  392. * @param unit: The unit of time
  393. */
  394. UmAlQuraStatic.startOf = function (date, unit) {
  395. var d = new Date(date);
  396. var _a = this.gregorianToHijri(d), hy = _a.hy, hm = _a.hm;
  397. switch (unit) {
  398. case 'year':
  399. return this.toDate(hy, 1, 1, 0, 0, 0, 0);
  400. case 'month':
  401. return this.toDate(hy, hm, 1, 0, 0, 0, 0);
  402. case 'week':
  403. var dow = this.getDayOfWeek(d);
  404. d = this.addDays(d, -dow);
  405. case 'day':
  406. d.setHours(0);
  407. case 'hour':
  408. d.setMinutes(0);
  409. case 'minute':
  410. d.setSeconds(0);
  411. case 'second':
  412. d.setMilliseconds(0);
  413. break;
  414. default:
  415. throw new Error('Invalid value for `unit` param');
  416. }
  417. return d;
  418. };
  419. /**
  420. * Returns the Gregorian date corresponding to the Hijri date ending at the specified unit of time.
  421. * @param date: The date
  422. * @param unit: The unit of time
  423. */
  424. UmAlQuraStatic.endOf = function (date, unit) {
  425. var d = new Date(date);
  426. var _a = this.gregorianToHijri(d), hy = _a.hy, hm = _a.hm;
  427. var daysInMonth;
  428. switch (unit) {
  429. case 'year':
  430. daysInMonth = this.getDaysInMonth(hy, 12);
  431. return this.toDate(hy, 12, daysInMonth, 23, 59, 59, 999);
  432. case 'month':
  433. daysInMonth = this.getDaysInMonth(hy, hm);
  434. return this.toDate(hy, hm, daysInMonth, 23, 59, 59, 999);
  435. case 'week':
  436. var dow = this.getDayOfWeek(d);
  437. d = this.addDays(d, 6 - dow);
  438. case 'day':
  439. d.setHours(23);
  440. case 'hour':
  441. d.setMinutes(59);
  442. case 'minute':
  443. d.setSeconds(59);
  444. case 'second':
  445. d.setMilliseconds(999);
  446. break;
  447. default:
  448. throw new Error('Invalid value for `unit` param');
  449. }
  450. return d;
  451. };
  452. /**
  453. * Returns whether or not the given Hijri year is a leap year.
  454. * A Hijri leap year is where the number of days in that year is 355.
  455. * @param hy The Hijri year
  456. */
  457. UmAlQuraStatic.isLeapYear = function (hy) {
  458. return this.getDaysInYear(hy) === 355;
  459. };
  460. /**
  461. * Converts the specified Hijri date time to a Gregorian Date instance.
  462. * @param hy The Hijri year
  463. * @param hm The Hijri month
  464. * @param hd The Hijri day
  465. * @param hour The Hour component
  466. * @param minute The Minute component
  467. * @param second The Second component
  468. * @param millisecond The Millisecond component
  469. */
  470. UmAlQuraStatic.toDate = function (hy, hm, hd, hour, minute, second, millisecond) {
  471. if (hour === void 0) { hour = 0; }
  472. if (minute === void 0) { minute = 0; }
  473. if (second === void 0) { second = 0; }
  474. if (millisecond === void 0) { millisecond = 0; }
  475. var daysInMonth = this.getDaysInMonth(hy, hm);
  476. if (hd < 1 || hd > daysInMonth) {
  477. throw new Error("Invalid value for day for the given year/month. Day must be between 1 and " + daysInMonth + ".");
  478. }
  479. if (hour < 0 || hour >= 24 || minute < 0 || minute >= 60 || second < 0 || second >= 60 || millisecond < 0 || millisecond >= this.millisPerSecond) {
  480. throw new Error('Invalid value for hour, minute, second or millisecond.');
  481. }
  482. var _a = this.hijriToGregorian(hy, hm, hd), gy = _a.gy, gm = _a.gm, gd = _a.gd;
  483. return this._setTime(new Date(gy, gm, gd), hour, minute, second, millisecond);
  484. };
  485. /**
  486. * Formats the specified Gregorian Date instance in Hijri date.
  487. * @param date The date
  488. * @param mask The format mask
  489. * @param locale The locale to use. If omitted, uses the globally set locale or the default locale.
  490. */
  491. UmAlQuraStatic.format = function (date, mask, locale) {
  492. var _a = this.gregorianToHijri(date), hy = _a.hy, hm = _a.hm, hd = _a.hd;
  493. return format(date, mask, locale ? this._loadLocale(locale) : this.locale, hy, hm, hd, this.getWeekOfYear(date), this.getDayOfWeek(date));
  494. };
  495. /**
  496. * Sets global locale to be used for formatting.
  497. * @param locale The locale
  498. */
  499. UmAlQuraStatic.setLocale = function (locale) {
  500. this.locale = this._loadLocale(locale);
  501. };
  502. /**
  503. * Registers the specified locale.
  504. * @param locale The locale
  505. */
  506. UmAlQuraStatic.registerLocale = function (locale) {
  507. if (!locale.name) {
  508. throw new Error("The locale's 'name' property must not be empty.");
  509. }
  510. if (this.locales[locale.name]) {
  511. throw new Error("A locale with the same name '" + locale.name + "' is already registered.");
  512. }
  513. this.locales[locale.name] = locale;
  514. };
  515. UmAlQuraStatic._loadLocale = function (locale) {
  516. if (this.locales[locale]) {
  517. return this.locales[locale];
  518. }
  519. console.warn("The requested locale '" + locale + "' could not be found. Using the default locale instead.");
  520. return en;
  521. };
  522. UmAlQuraStatic._getDatePart = function (date, part) {
  523. var _a = this.gregorianToHijri(date), hy = _a.hy, hm = _a.hm, hd = _a.hd;
  524. switch (part) {
  525. case DatePart$1.Year:
  526. return hy;
  527. case DatePart$1.Month:
  528. return hm;
  529. case DatePart$1.Day:
  530. return hd;
  531. case DatePart$1.DayOfYear:
  532. return Math.trunc(this._getAbsoluteDateUmAlQura(hy, hm, hd) - this._getAbsoluteDateUmAlQura(hy, 1, 1) + 1);
  533. }
  534. };
  535. UmAlQuraStatic._setTime = function (date, hour, minute, second, millisecond) {
  536. date.setHours(hour);
  537. date.setMinutes(minute);
  538. date.setSeconds(second);
  539. date.setMilliseconds(millisecond);
  540. return date;
  541. };
  542. UmAlQuraStatic._getAbsoluteDateUmAlQura = function (hy, hm, hd) {
  543. var _a = this.hijriToGregorian(hy, hm, hd), gy = _a.gy, gm = _a.gm, gd = _a.gd;
  544. return new Date(gy, gm, gd).getTime() / this.millisPerDay;
  545. };
  546. UmAlQuraStatic._checkYearRange = function (hy) {
  547. if (hy < this.minCalendarYear || hy > this.maxCalendarYear) {
  548. throw new Error("Invalid value for year. Must be between " + this.minCalendarYear + " and " + this.maxCalendarYear + ".");
  549. }
  550. };
  551. UmAlQuraStatic._checkMonthRange = function (hm) {
  552. if (hm < 1 || hm > 12) {
  553. throw new Error("Invalid value for month. Must be between 1 and 12.");
  554. }
  555. };
  556. UmAlQuraStatic._checkDayRange = function (day) {
  557. if (day < 1 || day > 30) {
  558. throw new Error("Invalid value for day. Must be between 1 and 30.");
  559. }
  560. };
  561. UmAlQuraStatic._checkMillsRange = function (millis) {
  562. if (millis < this.minDate.getTime() || millis > this.maxDate.getTime()) {
  563. throw new Error("Invalid value for epoch. Must be between " + this.minDate.getTime() + " and " + this.maxDate.getTime() + ".");
  564. }
  565. };
  566. UmAlQuraStatic._dayDiff = function (date, other) {
  567. return (date.getTime() - other.getTime()) / (1000 * 60 * 60 * 24);
  568. };
  569. UmAlQuraStatic._initDateMapping = function () {
  570. var rawData = [
  571. // This data is auto generated from the .net BCL which seemed the most accurate
  572. // Other source which have been found having abnormalities include:
  573. // http://www.staff.science.uu.nl/~gent0113/islam/addfiles/islamcalendar_dat.js - Has 28 days in one of the month which is impossible
  574. // http://www.ummulqura.org.sa/ - Has several inaccurate dates
  575. // Generated by /personal-proj/umalqura/data-gen
  576. /* DaysPerM GY GM GD D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12
  577. 1318*/ 0x02EA, 1900, 4, 30,
  578. 0x06E9, 1901, 4, 19,
  579. 0x0ED2, 1902, 4, 9,
  580. 0x0EA4, 1903, 3, 30,
  581. 0x0D4A, 1904, 3, 18,
  582. 0x0A96, 1905, 3, 7,
  583. 0x0536, 1906, 2, 24,
  584. 0x0AB5, 1907, 2, 13,
  585. 0x0DAA, 1908, 2, 3,
  586. 0x0BA4, 1909, 1, 23,
  587. 0x0B49, 1910, 1, 12,
  588. 0x0A93, 1911, 1, 1,
  589. 0x052B, 1911, 12, 21,
  590. 0x0A57, 1912, 12, 9,
  591. 0x04B6, 1913, 11, 29,
  592. 0x0AB5, 1914, 11, 18,
  593. 0x05AA, 1915, 11, 8,
  594. 0x0D55, 1916, 10, 27,
  595. 0x0D2A, 1917, 10, 17,
  596. 0x0A56, 1918, 10, 6,
  597. 0x04AE, 1919, 9, 25,
  598. 0x095D, 1920, 9, 13,
  599. 0x02EC, 1921, 9, 3,
  600. 0x06D5, 1922, 8, 23,
  601. 0x06AA, 1923, 8, 13,
  602. 0x0555, 1924, 8, 1,
  603. 0x04AB, 1925, 7, 21,
  604. 0x095B, 1926, 7, 10,
  605. 0x02BA, 1927, 6, 30,
  606. 0x0575, 1928, 6, 18,
  607. 0x0BB2, 1929, 6, 8,
  608. 0x0764, 1930, 5, 29,
  609. 0x0749, 1931, 5, 18,
  610. 0x0655, 1932, 5, 6,
  611. 0x02AB, 1933, 4, 25,
  612. 0x055B, 1934, 4, 14,
  613. 0x0ADA, 1935, 4, 4,
  614. 0x06D4, 1936, 3, 24,
  615. 0x0EC9, 1937, 3, 13,
  616. 0x0D92, 1938, 3, 3,
  617. 0x0D25, 1939, 2, 20,
  618. 0x0A4D, 1940, 2, 9,
  619. 0x02AD, 1941, 1, 28,
  620. 0x056D, 1942, 1, 17,
  621. 0x0B6A, 1943, 1, 7,
  622. 0x0B52, 1943, 12, 28,
  623. 0x0AA5, 1944, 12, 16,
  624. 0x0A4B, 1945, 12, 5,
  625. 0x0497, 1946, 11, 24,
  626. 0x0937, 1947, 11, 13,
  627. 0x02B6, 1948, 11, 2,
  628. 0x0575, 1949, 10, 22,
  629. 0x0D6A, 1950, 10, 12,
  630. 0x0D52, 1951, 10, 2,
  631. 0x0A96, 1952, 9, 20,
  632. 0x092D, 1953, 9, 9,
  633. 0x025D, 1954, 8, 29,
  634. 0x04DD, 1955, 8, 18,
  635. 0x0ADA, 1956, 8, 7,
  636. 0x05D4, 1957, 7, 28,
  637. 0x0DA9, 1958, 7, 17,
  638. 0x0D52, 1959, 7, 7,
  639. 0x0AAA, 1960, 6, 25,
  640. 0x04D6, 1961, 6, 14,
  641. 0x09B6, 1962, 6, 3,
  642. 0x0374, 1963, 5, 24,
  643. 0x0769, 1964, 5, 12,
  644. 0x0752, 1965, 5, 2,
  645. 0x06A5, 1966, 4, 21,
  646. 0x054B, 1967, 4, 10,
  647. 0x0AAB, 1968, 3, 29,
  648. 0x055A, 1969, 3, 19,
  649. 0x0AD5, 1970, 3, 8,
  650. 0x0DD2, 1971, 2, 26,
  651. 0x0DA4, 1972, 2, 16,
  652. 0x0D49, 1973, 2, 4,
  653. 0x0A95, 1974, 1, 24,
  654. 0x052D, 1975, 1, 13,
  655. 0x0A5D, 1976, 1, 2,
  656. 0x055A, 1976, 12, 22,
  657. 0x0AD5, 1977, 12, 11,
  658. 0x06AA, 1978, 12, 1,
  659. 0x0695, 1979, 11, 20,
  660. 0x052B, 1980, 11, 8,
  661. 0x0A57, 1981, 10, 28,
  662. 0x04AE, 1982, 10, 18,
  663. 0x0976, 1983, 10, 7,
  664. 0x056C, 1984, 9, 26,
  665. 0x0B55, 1985, 9, 15,
  666. 0x0AAA, 1986, 9, 5,
  667. 0x0A55, 1987, 8, 25,
  668. 0x04AD, 1988, 8, 13,
  669. 0x095D, 1989, 8, 2,
  670. 0x02DA, 1990, 7, 23,
  671. 0x05D9, 1991, 7, 12,
  672. 0x0DB2, 1992, 7, 1,
  673. 0x0BA4, 1993, 6, 21,
  674. 0x0B4A, 1994, 6, 10,
  675. 0x0A55, 1995, 5, 30,
  676. 0x02B5, 1996, 5, 18,
  677. 0x0575, 1997, 5, 7,
  678. 0x0B6A, 1998, 4, 27,
  679. 0x0BD2, 1999, 4, 17,
  680. 0x0BC4, 2000, 4, 6,
  681. 0x0B89, 2001, 3, 26,
  682. 0x0A95, 2002, 3, 15,
  683. 0x052D, 2003, 3, 4,
  684. 0x05AD, 2004, 2, 21,
  685. 0x0B6A, 2005, 2, 10,
  686. 0x06D4, 2006, 1, 31,
  687. 0x0DC9, 2007, 1, 20,
  688. 0x0D92, 2008, 1, 10,
  689. 0x0AA6, 2008, 12, 29,
  690. 0x0956, 2009, 12, 18,
  691. 0x02AE, 2010, 12, 7,
  692. 0x056D, 2011, 11, 26,
  693. 0x036A, 2012, 11, 15,
  694. 0x0B55, 2013, 11, 4,
  695. 0x0AAA, 2014, 10, 25,
  696. 0x094D, 2015, 10, 14,
  697. 0x049D, 2016, 10, 2,
  698. 0x095D, 2017, 9, 21,
  699. 0x02BA, 2018, 9, 11,
  700. 0x05B5, 2019, 8, 31,
  701. 0x05AA, 2020, 8, 20,
  702. 0x0D55, 2021, 8, 9,
  703. 0x0A9A, 2022, 7, 30,
  704. 0x092E, 2023, 7, 19,
  705. 0x026E, 2024, 7, 7,
  706. 0x055D, 2025, 6, 26,
  707. 0x0ADA, 2026, 6, 16,
  708. 0x06D4, 2027, 6, 6,
  709. 0x06A5, 2028, 5, 25,
  710. 0x054B, 2029, 5, 14,
  711. 0x0A97, 2030, 5, 3,
  712. 0x054E, 2031, 4, 23,
  713. 0x0AAE, 2032, 4, 11,
  714. 0x05AC, 2033, 4, 1,
  715. 0x0BA9, 2034, 3, 21,
  716. 0x0D92, 2035, 3, 11,
  717. 0x0B25, 2036, 2, 28,
  718. 0x064B, 2037, 2, 16,
  719. 0x0CAB, 2038, 2, 5,
  720. 0x055A, 2039, 1, 26,
  721. 0x0B55, 2040, 1, 15,
  722. 0x06D2, 2041, 1, 4,
  723. 0x0EA5, 2041, 12, 24,
  724. 0x0E4A, 2042, 12, 14,
  725. 0x0A95, 2043, 12, 3,
  726. 0x052D, 2044, 11, 21,
  727. 0x0AAD, 2045, 11, 10,
  728. 0x036C, 2046, 10, 31,
  729. 0x0759, 2047, 10, 20,
  730. 0x06D2, 2048, 10, 9,
  731. 0x0695, 2049, 9, 28,
  732. 0x052D, 2050, 9, 17,
  733. 0x0A5B, 2051, 9, 6,
  734. 0x04BA, 2052, 8, 26,
  735. 0x09BA, 2053, 8, 15,
  736. 0x03B4, 2054, 8, 5,
  737. 0x0B69, 2055, 7, 25,
  738. 0x0B52, 2056, 7, 14,
  739. 0x0AA6, 2057, 7, 3,
  740. 0x04B6, 2058, 6, 22,
  741. 0x096D, 2059, 6, 11,
  742. 0x02EC, 2060, 5, 31,
  743. 0x06D9, 2061, 5, 20,
  744. 0x0EB2, 2062, 5, 10,
  745. 0x0D54, 2063, 4, 30,
  746. 0x0D2A, 2064, 4, 18,
  747. 0x0A56, 2065, 4, 7,
  748. 0x04AE, 2066, 3, 27,
  749. 0x096D, 2067, 3, 16,
  750. 0x0D6A, 2068, 3, 5,
  751. 0x0B54, 2069, 2, 23,
  752. 0x0B29, 2070, 2, 12,
  753. 0x0A93, 2071, 2, 1,
  754. 0x052B, 2072, 1, 21,
  755. 0x0A57, 2073, 1, 9,
  756. 0x0536, 2073, 12, 30,
  757. 0x0AB5, 2074, 12, 19,
  758. 0x06AA, 2075, 12, 9,
  759. 0x0E93, 2076, 11, 27,
  760. 0, 2077, 11, 17 /* 0 0 0 0 0 0 0 0 0 0 0 0 2077-11-17*/
  761. ];
  762. var mapping = [];
  763. for (var i = 0; i < rawData.length / 4; i++) {
  764. mapping.push(new DateMapping(rawData[i * 4], rawData[i * 4 + 1], rawData[i * 4 + 2] - 1, rawData[i * 4 + 3]));
  765. }
  766. return mapping;
  767. };
  768. // private static readonly maxSeconds = 9223372036854775807 / 10000000;
  769. // private static readonly minSeconds = -9223372036854775807 / 10000000;
  770. UmAlQuraStatic.millisPerSecond = 1000;
  771. UmAlQuraStatic.millisPerMinute = UmAlQuraStatic.millisPerSecond * 60;
  772. UmAlQuraStatic.millisPerHour = UmAlQuraStatic.millisPerMinute * 60;
  773. UmAlQuraStatic.millisPerDay = UmAlQuraStatic.millisPerHour * 24;
  774. UmAlQuraStatic.minDate = new Date(1900, 3, 30);
  775. UmAlQuraStatic.maxDate = new Date(2077, 10, 16, 23, 59, 59, 999);
  776. UmAlQuraStatic.hijriYearData = UmAlQuraStatic._initDateMapping();
  777. // Holds globally set locale
  778. UmAlQuraStatic.locale = en;
  779. // Holds registered locales
  780. UmAlQuraStatic.locales = {};
  781. UmAlQuraStatic.minCalendarYear = 1318;
  782. UmAlQuraStatic.maxCalendarYear = 1500;
  783. return UmAlQuraStatic;
  784. }());
  785. // Register both locales so they'll be bundled in the package.
  786. // This is fine since for this library, there will probably be
  787. // only be these two locales.
  788. UmAlQuraStatic.registerLocale(ar);
  789. UmAlQuraStatic.registerLocale(en);
  790. var UmAlQura = /** @class */ (function () {
  791. function UmAlQura(dateOrHy, hm, hd, hour, minute, second, millisecond) {
  792. if (hour === void 0) { hour = 0; }
  793. if (minute === void 0) { minute = 0; }
  794. if (second === void 0) { second = 0; }
  795. if (millisecond === void 0) { millisecond = 0; }
  796. this._date = new Date(0, 0, 0);
  797. this._hy = 0;
  798. this._hm = 0;
  799. this._hd = 0;
  800. if (dateOrHy instanceof Date) {
  801. this._setDate(dateOrHy);
  802. }
  803. else if (dateOrHy !== undefined && hm !== undefined && hd !== undefined) {
  804. var _a = UmAlQuraStatic.hijriToGregorian(dateOrHy, hm, hd), gy = _a.gy, gm = _a.gm, gd = _a.gd;
  805. this._setDate(new Date(gy, gm, gd, hour, minute, second, millisecond));
  806. }
  807. else {
  808. this._setDate(new Date());
  809. }
  810. }
  811. Object.defineProperty(UmAlQura.prototype, "date", {
  812. /**
  813. * Returns the `Date` object of this instance.
  814. */
  815. get: function () { return new Date(this._date.valueOf()); },
  816. enumerable: true,
  817. configurable: true
  818. });
  819. Object.defineProperty(UmAlQura.prototype, "hy", {
  820. /**
  821. * Returns the Hijri year of this instance.
  822. */
  823. get: function () { return this._hy; },
  824. enumerable: true,
  825. configurable: true
  826. });
  827. Object.defineProperty(UmAlQura.prototype, "hm", {
  828. /**
  829. * Returns the Hijri month of this instance.
  830. */
  831. get: function () { return this._hm; },
  832. enumerable: true,
  833. configurable: true
  834. });
  835. Object.defineProperty(UmAlQura.prototype, "hd", {
  836. /**
  837. * Returns the Hijri day of month of this instance.
  838. */
  839. get: function () { return this._hd; },
  840. enumerable: true,
  841. configurable: true
  842. });
  843. Object.defineProperty(UmAlQura.prototype, "dayOfYear", {
  844. /**
  845. * Returns the Hijri day of year of this instance.
  846. */
  847. get: function () { return UmAlQuraStatic.getDayOfYear(this.date); },
  848. enumerable: true,
  849. configurable: true
  850. });
  851. Object.defineProperty(UmAlQura.prototype, "dayOfWeek", {
  852. /**
  853. * Returns the day of week of this instance.
  854. */
  855. get: function () { return UmAlQuraStatic.getDayOfWeek(this.date); },
  856. enumerable: true,
  857. configurable: true
  858. });
  859. Object.defineProperty(UmAlQura.prototype, "weekOfYear", {
  860. /**
  861. * Returns the Hijri week of year of this instance.
  862. */
  863. get: function () { return UmAlQuraStatic.getWeekOfYear(this.date); },
  864. enumerable: true,
  865. configurable: true
  866. });
  867. Object.defineProperty(UmAlQura.prototype, "daysInYear", {
  868. /**
  869. * Returns the number of days in year of this instance.
  870. */
  871. get: function () { return UmAlQuraStatic.getDaysInYear(this.hy); },
  872. enumerable: true,
  873. configurable: true
  874. });
  875. Object.defineProperty(UmAlQura.prototype, "daysInMonth", {
  876. /**
  877. * Returns the number of days in month of this instance.
  878. */
  879. get: function () { return UmAlQuraStatic.getDaysInMonth(this.hy, this.hm); },
  880. enumerable: true,
  881. configurable: true
  882. });
  883. Object.defineProperty(UmAlQura.prototype, "isLeapYear", {
  884. /**
  885. * Returns whether or not the Hijri year of this instance is a leap year.
  886. */
  887. get: function () { return UmAlQuraStatic.isLeapYear(this.hy); },
  888. enumerable: true,
  889. configurable: true
  890. });
  891. Object.defineProperty(UmAlQura.prototype, "monthArray", {
  892. /**
  893. * Returns the Hijri month array of this instance.
  894. */
  895. get: function () {
  896. return UmAlQuraStatic.getMonthArray(this.date)
  897. .map(function (w) { return w.map(function (d) { return d ? new UmAlQura(d) : null; }); });
  898. },
  899. enumerable: true,
  900. configurable: true
  901. });
  902. /**
  903. * Adds the specified amount of `unit` to the current date and returns a new instance.
  904. * @param {number} value The amount of units to be added
  905. * @param {UnitOfTimeMs} unit The unit of time
  906. */
  907. UmAlQura.prototype.add = function (value, unit) {
  908. switch (unit) {
  909. case 'year':
  910. return new UmAlQura(UmAlQuraStatic.addYears(this.date, value));
  911. case 'month':
  912. return new UmAlQura(UmAlQuraStatic.addMonths(this.date, value));
  913. case 'week':
  914. return new UmAlQura(UmAlQuraStatic.addWeeks(this.date, value));
  915. case 'day':
  916. return new UmAlQura(UmAlQuraStatic.addDays(this.date, value));
  917. case 'hour':
  918. case 'minute':
  919. case 'second':
  920. case 'millisecond':
  921. return new UmAlQura(UmAlQuraStatic.addTime(this.date, value, unit));
  922. default:
  923. throw new Error('Invalid value for `unit`');
  924. }
  925. };
  926. /**
  927. * Subtracts the specified amount of `unit` from the current date and returns a new instance.
  928. * @param {number} value The amount of units to be subtracted
  929. * @param {UnitOfTimeMs} unit The unit of time
  930. */
  931. UmAlQura.prototype.subtract = function (value, unit) {
  932. return this.add(value * -1, unit);
  933. };
  934. /**
  935. * Returns a new instance having the Hijri date of this instance starting at the specified unit of time.
  936. * @param {UnitOfTime} unit The unit of time
  937. */
  938. UmAlQura.prototype.startOf = function (unit) {
  939. return new UmAlQura(UmAlQuraStatic.startOf(this.date, unit));
  940. };
  941. /**
  942. * Returns a new instance having the Hijri date of this instance ending at the specified unit of time.
  943. * @param {UnitOfTime} unit The unit of time
  944. */
  945. UmAlQura.prototype.endOf = function (unit) {
  946. return new UmAlQura(UmAlQuraStatic.endOf(this.date, unit));
  947. };
  948. /**
  949. * Checks if current date is before the specified date. The comparison is made based on milliseconds of both
  950. * times. This can be changed by specifying a value for the `unit` parameter.
  951. * @param {(UmAlQura | Date)} other The date to compare against
  952. * @param {UnitOfTimeMs} [unit='millisecond'] The unit of time
  953. */
  954. UmAlQura.prototype.isBefore = function (other, unit) {
  955. if (unit === void 0) { unit = 'millisecond'; }
  956. var thisDate = this.date;
  957. var thatDate = other instanceof Date ? other : other.date;
  958. if (unit === 'millisecond') {
  959. return thisDate.valueOf() < thatDate.valueOf();
  960. }
  961. else {
  962. return this.endOf(unit).date.valueOf() < thatDate.valueOf();
  963. }
  964. };
  965. /**
  966. * Checks if current date is after the specified date. The comparison is made based on milliseconds,
  967. * this can be changed by specifying a value for the `unit` parameter.
  968. * @param {(UmAlQura | Date)} other The date to compare against
  969. * @param {UnitOfTimeMs} [unit='millisecond'] The unit of time
  970. */
  971. UmAlQura.prototype.isAfter = function (other, unit) {
  972. if (unit === void 0) { unit = 'millisecond'; }
  973. var thisDate = this.date;
  974. var thatDate = other instanceof Date ? other : other.date;
  975. if (unit === 'millisecond') {
  976. return thisDate.valueOf() > thatDate.valueOf();
  977. }
  978. else {
  979. return this.startOf(unit).date.valueOf() > thatDate.valueOf();
  980. }
  981. };
  982. /**
  983. * Checks if current date is same as the specified date. The comparison is made based on milliseconds,
  984. * this can be changed by specifying a value for the `unit` parameter.
  985. * @param {(UmAlQura | Date)} other The date to compare against
  986. * @param {UnitOfTimeMs} [unit='millisecond'] The unit of time
  987. */
  988. UmAlQura.prototype.isSame = function (other, unit) {
  989. if (unit === void 0) { unit = 'millisecond'; }
  990. var thisDate = this.date;
  991. var thatDate = other instanceof Date ? other : other.date;
  992. if (unit === 'millisecond') {
  993. return thisDate.valueOf() === thatDate.valueOf();
  994. }
  995. else {
  996. return this.startOf(unit).date.valueOf() === new UmAlQura(thatDate).startOf(unit).date.valueOf();
  997. }
  998. };
  999. /**
  1000. * Checks if current date is same as or before the specified date. The comparison is made based on milliseconds,
  1001. * this can be changed by specifying a value for the `unit` parameter.
  1002. * @param {(UmAlQura | Date)} other The date to compare against
  1003. * @param {UnitOfTimeMs} [unit='millisecond'] The unit of time
  1004. */
  1005. UmAlQura.prototype.isSameOrBefore = function (other, unit) {
  1006. if (unit === void 0) { unit = 'millisecond'; }
  1007. return this.isSame(other, unit) || this.isBefore(other, unit);
  1008. };
  1009. /**
  1010. * Checks if current date is same as or after the specified date. The comparison is made based on milliseconds,
  1011. * this can be changed by specifying a value for the `unit` parameter.
  1012. * @param {(UmAlQura | Date)} other The date to compare against
  1013. * @param {UnitOfTimeMs} [unit='millisecond'] The unit of time
  1014. */
  1015. UmAlQura.prototype.isSameOrAfter = function (other, unit) {
  1016. if (unit === void 0) { unit = 'millisecond'; }
  1017. return this.isSame(other, unit) || this.isAfter(other, unit);
  1018. };
  1019. /**
  1020. * Checks if current date is between the specified `from`/`to` dates. The comparison is made based on milliseconds,
  1021. * this can be changed by specifying a value for the `unit` parameter. The comparison is exclusive of both ends by default,
  1022. * this can be controller by `fromInclusive`/`toInclusive` parameters.
  1023. * @param {(UmAlQura | Date)} from The lower bound date
  1024. * @param {(UmAlQura | Date)} to The higher bound date
  1025. * @param {boolean} [fromInclusive=false] Whether lower bound is inclusive, defaults to false.
  1026. * @param {boolean} [toInclusive=false] Whether upper bound is inclusive, defaults to false.
  1027. * @param {UnitOfTimeMs} [unit='millisecond'] The unit of time
  1028. */
  1029. UmAlQura.prototype.isBetween = function (from, to, fromInclusive, toInclusive, unit) {
  1030. if (fromInclusive === void 0) { fromInclusive = false; }
  1031. if (toInclusive === void 0) { toInclusive = false; }
  1032. if (unit === void 0) { unit = 'millisecond'; }
  1033. return (fromInclusive ? this.isSameOrAfter(from, unit) : this.isAfter(from, unit)) &&
  1034. (toInclusive ? this.isSameOrBefore(to, unit) : this.isBefore(to, unit));
  1035. };
  1036. /**
  1037. * Formats this instance in Hijri date.
  1038. * @param {string} mask The mask
  1039. * @param {string} locale The locale to use. If omitted, uses the locale set via `locale` or the default locale.
  1040. */
  1041. UmAlQura.prototype.format = function (mask, locale) {
  1042. // tslint:disable-next-line:no-string-literal
  1043. return UmAlQuraStatic.format(this.date, mask, locale || UmAlQuraStatic['locale'].name);
  1044. };
  1045. /**
  1046. * Clones this instance and returns a new instance with the same values.
  1047. */
  1048. UmAlQura.prototype.clone = function () {
  1049. return new UmAlQura(this.date);
  1050. };
  1051. UmAlQura.prototype._setDate = function (date) {
  1052. var _a = UmAlQuraStatic.gregorianToHijri(date), hy = _a.hy, hm = _a.hm, hd = _a.hd;
  1053. this._date = new Date(date.valueOf());
  1054. this._hy = hy;
  1055. this._hm = hm;
  1056. this._hd = hd;
  1057. };
  1058. return UmAlQura;
  1059. }());
  1060. function umalqura(dateOrHy, hm, hd, hour, minute, second, millisecond) {
  1061. if (hour === void 0) { hour = 0; }
  1062. if (minute === void 0) { minute = 0; }
  1063. if (second === void 0) { second = 0; }
  1064. if (millisecond === void 0) { millisecond = 0; }
  1065. if (dateOrHy instanceof Date) {
  1066. return new UmAlQura(dateOrHy);
  1067. }
  1068. else if (dateOrHy !== undefined && hm !== undefined && hd !== undefined) {
  1069. return new UmAlQura(dateOrHy, hm, hd, hour, minute, second, millisecond);
  1070. }
  1071. else {
  1072. return new UmAlQura();
  1073. }
  1074. }
  1075. /**
  1076. * Returns the library version.
  1077. */
  1078. umalqura.VERSION = "0.0.7";
  1079. /**
  1080. * Returns a class which exposes static Hijri related functions.
  1081. */
  1082. umalqura.$ = UmAlQuraStatic;
  1083. /**
  1084. * Returns the minimum supported Hijri date.
  1085. */
  1086. umalqura.min = umalqura(UmAlQuraStatic['minCalendarYear'], 1, 1);
  1087. /**
  1088. * Returns the maximum supported Hijri date.
  1089. */
  1090. umalqura.max = umalqura(UmAlQuraStatic['maxCalendarYear'], 1, 1).endOf('year');
  1091. /**
  1092. * Gets or sets the global locale
  1093. * @param locale The locale to set. If omitted, returns the current locale
  1094. */
  1095. umalqura.locale = function (locale) { return locale ? UmAlQuraStatic.setLocale(locale) : UmAlQuraStatic['locale'].name; };
  1096. /**
  1097. * Returns whether the currently set locale is RTL or not.
  1098. */
  1099. umalqura.rtl = function () { return !!UmAlQuraStatic['locale'].rtl; };
  1100. /**
  1101. * Returns the times names using the currently set locale.
  1102. */
  1103. umalqura.times = function () { return UmAlQuraStatic['locale'].timeNames.slice(); };
  1104. /**
  1105. * Returns the days names using the currently set locale.
  1106. */
  1107. umalqura.days = function () { return UmAlQuraStatic['locale'].dayNames.slice(); };
  1108. /**
  1109. * Returns the days short names using the currently set locale.
  1110. */
  1111. umalqura.daysShort = function () { return UmAlQuraStatic['locale'].dayNamesShort.slice(); };
  1112. /**
  1113. * Returns the months names using the currently set locale.
  1114. */
  1115. umalqura.months = function () { return UmAlQuraStatic['locale'].monthNames.slice(); };
  1116. /**
  1117. * Returns the months short names using the currently set locale.
  1118. */
  1119. umalqura.monthsShort = function () { return UmAlQuraStatic['locale'].monthNamesShort.slice(); };
  1120. /**
  1121. * Returns the localized number for the given number using the currently set locale.
  1122. */
  1123. umalqura.localizeNum = function (num) { return UmAlQuraStatic['locale'].localizeNum(num); };
  1124. /**
  1125. * Returns the localized day number for the given day number using the currently set locale.
  1126. */
  1127. umalqura.localizeDayNum = function (d) { return UmAlQuraStatic['locale'].localizeDayNum(d); };
  1128. export default umalqura;