@acorex/core 5.0.6 → 5.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -211,6 +211,7 @@
211
211
  return;
212
212
  }
213
213
  if (arg1 && typeof arg1 == 'object') {
214
+ //TODO : fix override
214
215
  Object.assign(AXConfig.dataModel, arg1);
215
216
  AXConfig.dataChangeSubject.next(AXConfig.dataModel);
216
217
  return;
@@ -227,31 +228,17 @@
227
228
  AXConfig.dataModel = {};
228
229
  AXConfig.dataChangeSubject = new rxjs.Subject();
229
230
 
230
- var AX_CALENDARS = [
231
- {
232
- name: 'gregorian',
233
- type: 'GeorgianCalendar'
234
- },
235
- {
236
- name: 'jalali',
237
- type: 'JalaliCalendar'
238
- }
239
- ];
240
- /**
241
- * Standard links:
242
- * {@link Foo} or {@linkplain Foo} or [[Foo]]
243
- *
244
- * Code links: (Puts Foo inside <code> tags)
245
- * {@linkcode Foo} or [[`Foo`]]
246
- */
247
231
  // @dynamic
248
232
  var AXDateTime = /** @class */ (function () {
249
233
  function AXDateTime(value, calendar) {
250
234
  if (value === void 0) { value = new Date(); }
251
235
  if (calendar === void 0) { calendar = AXConfig.get('dateTime.type') || 'gregorian'; }
252
236
  this._calendar =
237
+ // typeof calendar == 'string'
238
+ // ? eval(`new ${AX_CALENDARS.find((c) => c.name == calendar).type}()`)
239
+ // : calendar;
253
240
  typeof calendar == 'string'
254
- ? eval("new " + AX_CALENDARS.find(function (c) { return c.name == calendar; }).type + "()")
241
+ ? AXConfig.get("dateTime.calendars." + calendar)
255
242
  : calendar;
256
243
  if (value instanceof Date) {
257
244
  this._date = value;
@@ -275,9 +262,6 @@
275
262
  return date;
276
263
  };
277
264
  Object.defineProperty(AXDateTime.prototype, "date", {
278
- /**
279
- * This comment _supports_ [Markdown](https://marked.js.org/)
280
- */
281
265
  get: function () {
282
266
  return this._date;
283
267
  },
@@ -294,9 +278,9 @@
294
278
  AXDateTime.prototype.clone = function () {
295
279
  return new AXDateTime(this.date, this.calendar.name());
296
280
  };
297
- Object.defineProperty(AXDateTime.prototype, "dayInMonth", {
281
+ Object.defineProperty(AXDateTime.prototype, "dayOfMonth", {
298
282
  get: function () {
299
- return this._calendar.dayInMonth(this.date);
283
+ return this._calendar.dayOfMonth(this.date);
300
284
  },
301
285
  enumerable: false,
302
286
  configurable: true
@@ -308,9 +292,9 @@
308
292
  enumerable: false,
309
293
  configurable: true
310
294
  });
311
- Object.defineProperty(AXDateTime.prototype, "dayInWeek", {
295
+ Object.defineProperty(AXDateTime.prototype, "dayOfWeek", {
312
296
  get: function () {
313
- return this._calendar.dayInWeek(this.date);
297
+ return this._calendar.dayOfWeek(this.date);
314
298
  },
315
299
  enumerable: false,
316
300
  configurable: true
@@ -350,6 +334,13 @@
350
334
  enumerable: false,
351
335
  configurable: true
352
336
  });
337
+ Object.defineProperty(AXDateTime.prototype, "weekOfYear", {
338
+ get: function () {
339
+ return this._calendar.weekOfYear(this.date);
340
+ },
341
+ enumerable: false,
342
+ configurable: true
343
+ });
353
344
  Object.defineProperty(AXDateTime.prototype, "month", {
354
345
  get: function () {
355
346
  return new AXCalendarMonth(this);
@@ -382,17 +373,17 @@
382
373
  'DDD, dd MMM yyyy'; }
383
374
  format = format.replace('ss', this.pad(this.date.getSeconds(), 2));
384
375
  format = format.replace('s', this.date.getSeconds().toString());
385
- format = format.replace('dd', this.pad(this.calendar.dayInMonth(this.date), 2));
386
- format = format.replace('d', this.calendar.dayInMonth(this.date).toString());
376
+ format = format.replace('dd', this.pad(this.calendar.dayOfMonth(this.date), 2));
377
+ format = format.replace('d', this.calendar.dayOfMonth(this.date).toString());
387
378
  format = format.replace('mm', this.pad(this.date.getMinutes(), 2));
388
379
  format = format.replace('m', this.date.getMinutes().toString());
389
380
  format = format.replace('MMMM', this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1]);
390
381
  format = format.replace('MMM', this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1]);
391
382
  format = format.replace('MM', this.pad(this.calendar.monthOfYear(this.date), 2));
392
383
  format = format.replace(/M(?![ao])/, this.calendar.monthOfYear(this.date).toString());
393
- format = format.replace('DDDD', this.calendar.dayNames[this.calendar.dayInWeek(this.date) - 1]);
394
- format = format.replace('DDD', this.calendar.dayShortNames[this.calendar.dayInWeek(this.date) - 1]);
395
- format = format.replace(/D(?!e)/, this.calendar.dayNames[this.calendar.dayInWeek(this.date) - 1].substring(0, 3));
384
+ format = format.replace('DDDD', this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1]);
385
+ format = format.replace('DDD', this.calendar.dayShortNames[this.calendar.dayOfWeek(this.date) - 1]);
386
+ format = format.replace(/D(?!e)/, this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1].substring(0, 3));
396
387
  format = format.replace('yyyy', this.calendar.year(this.date).toString());
397
388
  format = format.replace('YYYY', this.calendar.year(this.date).toString());
398
389
  format = format.replace('yy', this.calendar.year(this.date).toString().substring(2));
@@ -411,20 +402,46 @@
411
402
  };
412
403
  AXDateTime.prototype.equal = function (value, unit) {
413
404
  if (unit === void 0) { unit = 'day'; }
414
- return this.compaire(value, unit) == 0;
405
+ return this.compare(value, unit) == 0;
415
406
  };
416
- AXDateTime.prototype.compaire = function (value, unit) {
407
+ AXDateTime.prototype.compare = function (value, unit) {
417
408
  if (unit === void 0) { unit = 'day'; }
418
- // TODO:
419
409
  var val = AXDateTime.convert(value);
420
- if (this.date == val.date) {
421
- return 0;
422
- }
423
- else if (this.date > val.date) {
424
- return 1;
425
- }
426
- else {
427
- return -1;
410
+ var func = function (v1, v2) {
411
+ if (v1 == v2) {
412
+ return 0;
413
+ }
414
+ else if (v1 > v2) {
415
+ return 1;
416
+ }
417
+ else {
418
+ return -1;
419
+ }
420
+ };
421
+ var p = 0;
422
+ switch (unit) {
423
+ case 'year':
424
+ return func(this.year, val.year);
425
+ case 'week':
426
+ p = this.compare(val, 'year');
427
+ return p == 0 ? func(this.weekOfYear, val.weekOfYear) : p;
428
+ case 'month':
429
+ p = this.compare(val, 'year');
430
+ return p == 0 ? func(this.monthOfYear, val.monthOfYear) : p;
431
+ case 'day':
432
+ p = this.compare(val, 'year');
433
+ return p == 0 ? func(this.dayOfYear, val.dayOfYear) : p;
434
+ case 'hour':
435
+ p = this.compare(val, 'day');
436
+ return p == 0 ? func(this.hour, val.hour) : p;
437
+ case 'minute':
438
+ p = this.compare(val, 'hour');
439
+ return p == 0 ? func(this.minute, val.minute) : p;
440
+ case 'second':
441
+ p = this.compare(val, 'minute');
442
+ return p == 0 ? func(this.second, val.second) : p;
443
+ default:
444
+ return func(this.date.getTime(), val.date.getTime());
428
445
  }
429
446
  };
430
447
  AXDateTime.prototype.convert = function (calendar) {
@@ -452,9 +469,23 @@
452
469
  }());
453
470
  var AXDateTimeRange = /** @class */ (function () {
454
471
  function AXDateTimeRange(startTime, endTime) {
455
- this.startTime = startTime;
456
- this.endTime = endTime;
472
+ this._startTime = startTime;
473
+ this._endTime = endTime;
457
474
  }
475
+ Object.defineProperty(AXDateTimeRange.prototype, "startTime", {
476
+ get: function () {
477
+ return this._startTime;
478
+ },
479
+ enumerable: false,
480
+ configurable: true
481
+ });
482
+ Object.defineProperty(AXDateTimeRange.prototype, "endTime", {
483
+ get: function () {
484
+ return this._endTime;
485
+ },
486
+ enumerable: false,
487
+ configurable: true
488
+ });
458
489
  AXDateTimeRange.prototype.duration = function () {
459
490
  var result = {
460
491
  miliseconds: 0,
@@ -482,8 +513,8 @@
482
513
  var one_week = one_day * 7;
483
514
  var one_year = 365.25 * one_day;
484
515
  var one_month = one_year / 12;
485
- var startTime = this.startTime.date.getTime();
486
- var endTime = this.endTime.date.getTime();
516
+ var startTime = this._startTime.date.getTime();
517
+ var endTime = this._endTime.date.getTime();
487
518
  var diff = Math.abs(endTime - startTime);
488
519
  //
489
520
  result.total.miliseconds = diff;
@@ -513,10 +544,17 @@
513
544
  result.years = Number(result.total.years.toFixed(0));
514
545
  return result;
515
546
  };
516
- AXDateTimeRange.prototype.enumurate = function (unit) {
547
+ AXDateTimeRange.prototype.enumurate = function (unit, amount) {
517
548
  if (unit === void 0) { unit = 'day'; }
518
- // TODO: ??
519
- return [];
549
+ if (amount === void 0) { amount = 1; }
550
+ // TODO: setptemper savingtime issue
551
+ var result = [];
552
+ var item = this._startTime.clone();
553
+ while (item.compare(this._endTime, unit) < 1) {
554
+ result.push(item);
555
+ item = item.add(unit, amount);
556
+ }
557
+ return result;
520
558
  };
521
559
  AXDateTimeRange.prototype.includes = function (value, unit) {
522
560
  if (unit === void 0) { unit = 'day'; }
@@ -550,24 +588,6 @@
550
588
  args: [{ name: 'axDate' }]
551
589
  }], ctorParameters: function () { return []; } });
552
590
 
553
- var AXDateTimeModule = /** @class */ (function () {
554
- function AXDateTimeModule() {
555
- }
556
- return AXDateTimeModule;
557
- }());
558
- AXDateTimeModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0__namespace, type: AXDateTimeModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
559
- AXDateTimeModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0__namespace, type: AXDateTimeModule, declarations: [AXDateTimePipe], exports: [AXDateTimePipe] });
560
- AXDateTimeModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0__namespace, type: AXDateTimeModule, providers: [], imports: [[]] });
561
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0__namespace, type: AXDateTimeModule, decorators: [{
562
- type: i0.NgModule,
563
- args: [{
564
- imports: [],
565
- exports: [AXDateTimePipe],
566
- declarations: [AXDateTimePipe],
567
- providers: [],
568
- }]
569
- }] });
570
-
571
591
  var GeorgianCalendar = /** @class */ (function () {
572
592
  function GeorgianCalendar() {
573
593
  this.monthNames = [
@@ -594,18 +614,28 @@
594
614
  GeorgianCalendar.prototype.name = function () {
595
615
  return 'gregorian';
596
616
  };
597
- GeorgianCalendar.prototype.dayInMonth = function (date) {
617
+ GeorgianCalendar.prototype.dayOfMonth = function (date) {
598
618
  return date.getDate();
599
619
  };
600
620
  GeorgianCalendar.prototype.dayOfYear = function (date) {
601
- var start = +new Date(date.getFullYear(), 0, 0);
602
- var diff = +date - start;
603
- var oneDay = 1000 * 60 * 60 * 24;
604
- return Math.floor(diff / oneDay);
621
+ var result = 0;
622
+ var m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
623
+ if (this.isLeap(date)) {
624
+ m[1] = 29;
625
+ }
626
+ for (var i = 0; i < date.getMonth(); i++) {
627
+ result = result + m[i];
628
+ }
629
+ result += date.getDate();
630
+ return result;
605
631
  };
606
- GeorgianCalendar.prototype.dayInWeek = function (date) {
632
+ GeorgianCalendar.prototype.dayOfWeek = function (date) {
607
633
  return date.getDay() + 1;
608
634
  };
635
+ GeorgianCalendar.prototype.weekOfYear = function (date) {
636
+ var firstDay = new AXDateTime(date).startOf('year');
637
+ return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
638
+ };
609
639
  GeorgianCalendar.prototype.year = function (date) {
610
640
  return date.getFullYear();
611
641
  };
@@ -645,7 +675,7 @@
645
675
  case 'year':
646
676
  var yv = new Date(value);
647
677
  yv.setFullYear(yv.getFullYear() + amount);
648
- value = v.valueOf();
678
+ value = yv.valueOf();
649
679
  break;
650
680
  case 'day':
651
681
  default:
@@ -673,7 +703,10 @@
673
703
  clone.setHours(0, 0, 0, 0);
674
704
  return new AXDateTime(clone, this.name());
675
705
  case "week":
676
- var diff = clone.getDate() - clone.getDay() + (clone.getDay() === 0 ? -6 : 1);
706
+ var index = 0;
707
+ var start = index >= 0 ? index : 0;
708
+ var day = clone.getDay();
709
+ var diff = clone.getDate() - day + (start > day ? start - 7 : start);
677
710
  clone.setDate(diff);
678
711
  return new AXDateTime(clone, this.name()).startOf('day');
679
712
  case "month":
@@ -710,9 +743,366 @@
710
743
  return new AXDateTime(clone, this.name()).endOf('month');
711
744
  }
712
745
  };
746
+ GeorgianCalendar.prototype.isLeap = function (date) {
747
+ var leapYear = new Date(date.getFullYear(), 1, 29);
748
+ return leapYear.getDate() == 29;
749
+ };
713
750
  return GeorgianCalendar;
714
751
  }());
715
752
 
753
+ var JalaliCalendar = /** @class */ (function () {
754
+ function JalaliCalendar() {
755
+ this.monthNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
756
+ this.monthShortNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
757
+ this.dayNames = ("شنبه_یکشنبه_دوشنبه_سه شنبه_چهارشنبه_پنج شنبه_جمعه").split("_");
758
+ this.dayShortNames = "ش_ی_د_س_چ_پ_ج".split("_");
759
+ }
760
+ JalaliCalendar.prototype.name = function () {
761
+ return 'jalali';
762
+ };
763
+ JalaliCalendar.prototype.dayOfMonth = function (date) {
764
+ return this.toJalali(date).day;
765
+ };
766
+ JalaliCalendar.prototype.dayOfYear = function (date) {
767
+ var j = this.toJalali(date);
768
+ return (j.month <= 6 ? ((j.month - 1) * 31) : ((6 * 31) + (j.month - 7) * 30)) + j.day;
769
+ };
770
+ JalaliCalendar.prototype.dayOfWeek = function (date) {
771
+ return date.getDay() == 6 ? 1 : date.getDay() + 2;
772
+ };
773
+ JalaliCalendar.prototype.weekOfYear = function (date) {
774
+ //TODO : apply jalali
775
+ var firstDay = new AXDateTime(date).startOf('year');
776
+ return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
777
+ };
778
+ JalaliCalendar.prototype.year = function (date) {
779
+ return this.toJalali(date).year;
780
+ };
781
+ JalaliCalendar.prototype.monthOfYear = function (date) {
782
+ return this.toJalali(date).month;
783
+ };
784
+ JalaliCalendar.prototype.add = function (date, unit, amount) {
785
+ var value = date.valueOf();
786
+ switch (unit) {
787
+ case 'second':
788
+ value += 1000 * amount;
789
+ break;
790
+ case 'minute':
791
+ value += 60000 * amount;
792
+ break;
793
+ case 'hour':
794
+ value += 3600000 * amount;
795
+ break;
796
+ case 'month':
797
+ {
798
+ var v = new Date(value);
799
+ var jd = this.dayOfMonth(date);
800
+ var jm = this.monthOfYear(date);
801
+ var jy = this.year(date);
802
+ jm = (jm + amount) % 12;
803
+ if (0 > jm) {
804
+ jy += (this.monthOfYear(date) + amount - jm - 12) / 12;
805
+ jm += 12;
806
+ }
807
+ else {
808
+ jy += ((this.monthOfYear(date) + amount - jm) / 12);
809
+ }
810
+ var vv = this.toGregorian(jy, jm, jd);
811
+ v.setFullYear(vv.getFullYear());
812
+ v.setMonth(vv.getMonth());
813
+ v.setDate(vv.getDate());
814
+ value = v.valueOf();
815
+ break;
816
+ }
817
+ case 'week':
818
+ value += 7 * 86400000 * amount;
819
+ break;
820
+ case 'year':
821
+ {
822
+ var v = new Date(value);
823
+ var jd = this.dayOfMonth(date);
824
+ var jm = this.monthOfYear(date);
825
+ var jy = this.year(date);
826
+ var vv = this.toGregorian(jy + amount, jm, jd);
827
+ v.setFullYear(vv.getFullYear());
828
+ v.setMonth(vv.getMonth());
829
+ v.setDate(vv.getDate());
830
+ value = v.valueOf();
831
+ }
832
+ break;
833
+ case 'day':
834
+ default:
835
+ value += 86400000 * amount;
836
+ }
837
+ return new AXDateTime(new Date(value), this.name());
838
+ };
839
+ JalaliCalendar.prototype.set = function (date, unit, value) {
840
+ throw new Error("Method not implemented.");
841
+ };
842
+ JalaliCalendar.prototype.startOf = function (date, unit) {
843
+ var clone = new Date(date.valueOf());
844
+ switch (unit) {
845
+ case 'second':
846
+ clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
847
+ return new AXDateTime(clone, this.name());
848
+ case 'minute':
849
+ clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
850
+ return new AXDateTime(clone, this.name());
851
+ case 'hour':
852
+ clone.setHours(clone.getHours(), 0, 0, 0);
853
+ return new AXDateTime(clone, this.name());
854
+ default:
855
+ case 'day':
856
+ clone.setHours(0, 0, 0, 0);
857
+ return new AXDateTime(clone, this.name());
858
+ case "week":
859
+ return new AXDateTime(clone, this.name()).add('day', -this.dayOfWeek(clone) + 1).startOf('day');
860
+ case "month":
861
+ {
862
+ var jy = this.year(date);
863
+ var jm = this.monthOfYear(date);
864
+ var gDate = this.toGregorian(jy, jm, 1);
865
+ return new AXDateTime(gDate, this.name()).startOf('day');
866
+ }
867
+ case "year":
868
+ {
869
+ var jy = this.year(date);
870
+ var gDate = this.toGregorian(jy, 1, 1);
871
+ return new AXDateTime(gDate, this.name()).startOf('day');
872
+ }
873
+ }
874
+ };
875
+ JalaliCalendar.prototype.endOf = function (date, unit) {
876
+ var clone = new Date(date.valueOf());
877
+ switch (unit) {
878
+ case 'second':
879
+ clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
880
+ return new AXDateTime(clone, this.name());
881
+ case 'minute':
882
+ clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
883
+ return new AXDateTime(clone, this.name());
884
+ case 'hour':
885
+ clone.setHours(clone.getHours(), 59, 59, 999);
886
+ return new AXDateTime(clone, this.name());
887
+ default:
888
+ case 'day':
889
+ clone.setHours(23, 59, 59, 999);
890
+ return new AXDateTime(clone, this.name());
891
+ case 'week':
892
+ {
893
+ return this.startOf(date, 'week').add('day', 6).endOf('day');
894
+ }
895
+ case 'month':
896
+ {
897
+ var jy_1 = this.year(date);
898
+ var jm = this.monthOfYear(date);
899
+ var jd = this.monthLength(jy_1, jm);
900
+ var gDate_1 = this.toGregorian(jy_1, jm, jd);
901
+ return new AXDateTime(gDate_1, this.name()).endOf('day');
902
+ }
903
+ case "year":
904
+ var jy = this.year(date);
905
+ var gDate = this.toGregorian(jy, 12, this.monthLength(jy, 12));
906
+ return new AXDateTime(gDate, this.name()).endOf('day');
907
+ }
908
+ };
909
+ JalaliCalendar.prototype.toJalali = function (date) {
910
+ var gy = date.getFullYear();
911
+ var gm = date.getMonth() + 1;
912
+ var gd = date.getDate();
913
+ var r = this.d2j(this.g2d(gy, gm, gd));
914
+ return {
915
+ year: r.jy,
916
+ month: r.jm,
917
+ day: r.jd,
918
+ };
919
+ };
920
+ /*
921
+ Converts a Jalaali date to Gregorian.
922
+ */
923
+ JalaliCalendar.prototype.toGregorian = function (jy, jm, jd) {
924
+ var g = this.d2g(this.j2d(jy, jm, jd));
925
+ return new Date(g.gy, g.gm - 1, g.gd);
926
+ };
927
+ /*
928
+ Checks whether a Jalaali date is valid or not.
929
+ */
930
+ JalaliCalendar.prototype.isValid = function (jy, jm, jd) {
931
+ return jy >= -61 && jy <= 3177 &&
932
+ jm >= 1 && jm <= 12 &&
933
+ jd >= 1 && jd <= this.monthLength(jy, jm);
934
+ };
935
+ /*
936
+ Is this a leap year or not?
937
+ */
938
+ JalaliCalendar.prototype.isLeapYear = function (jy) {
939
+ return this.jalCal(jy).leap === 0;
940
+ };
941
+ /*
942
+ Number of days in a given month in a Jalaali year.
943
+ */
944
+ JalaliCalendar.prototype.monthLength = function (jy, jm) {
945
+ if (jm <= 6)
946
+ return 31;
947
+ if (jm <= 11)
948
+ return 30;
949
+ if (this.isLeapYear(jy))
950
+ return 30;
951
+ return 29;
952
+ };
953
+ JalaliCalendar.prototype.jalCal = function (jy) {
954
+ // Jalaali years starting the 33-year rule.
955
+ var breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210,
956
+ 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178
957
+ ], bl = breaks.length, gy = jy + 621, leapJ = -14, jp = breaks[0], jm, jump, leap, leapG, march, n, i;
958
+ if (jy < jp || jy >= breaks[bl - 1])
959
+ throw new Error('Invalid Jalaali year ' + jy);
960
+ // Find the limiting years for the Jalaali year jy.
961
+ for (i = 1; i < bl; i += 1) {
962
+ jm = breaks[i];
963
+ jump = jm - jp;
964
+ if (jy < jm)
965
+ break;
966
+ leapJ = leapJ + this.div(jump, 33) * 8 + this.div(this.mod(jump, 33), 4);
967
+ jp = jm;
968
+ }
969
+ n = jy - jp;
970
+ // Find the number of leap years from AD 621 to the beginning
971
+ // of the current Jalaali year in the Persian calendar.
972
+ leapJ = leapJ + this.div(n, 33) * 8 + this.div(this.mod(n, 33) + 3, 4);
973
+ if (this.mod(jump, 33) === 4 && jump - n === 4)
974
+ leapJ += 1;
975
+ // And the same in the Gregorian calendar (until the year gy).
976
+ leapG = this.div(gy, 4) - this.div((this.div(gy, 100) + 1) * 3, 4) - 150;
977
+ // Determine the Gregorian date of Farvardin the 1st.
978
+ march = 20 + leapJ - leapG;
979
+ // Find how many years have passed since the last leap year.
980
+ if (jump - n < 6)
981
+ n = n - jump + this.div(jump + 4, 33) * 33;
982
+ leap = this.mod(this.mod(n + 1, 33) - 1, 4);
983
+ if (leap === -1) {
984
+ leap = 4;
985
+ }
986
+ return {
987
+ leap: leap,
988
+ gy: gy,
989
+ march: march
990
+ };
991
+ };
992
+ /*
993
+ Converts a date of the Jalaali calendar to the Julian Day number.
994
+ @param jy Jalaali year (1 to 3100)
995
+ @param jm Jalaali month (1 to 12)
996
+ @param jd Jalaali day (1 to 29/31)
997
+ @return Julian Day number
998
+ */
999
+ JalaliCalendar.prototype.j2d = function (jy, jm, jd) {
1000
+ var r = this.jalCal(jy);
1001
+ return this.g2d(r.gy, 3, r.march) + (jm - 1) * 31 - this.div(jm, 7) * (jm - 7) + jd - 1;
1002
+ };
1003
+ /*
1004
+ Converts the Julian Day number to a date in the Jalaali calendar.
1005
+ @param jdn Julian Day number
1006
+ @return
1007
+ jy: Jalaali year (1 to 3100)
1008
+ jm: Jalaali month (1 to 12)
1009
+ jd: Jalaali day (1 to 29/31)
1010
+ */
1011
+ JalaliCalendar.prototype.d2j = function (jdn) {
1012
+ var gy = this.d2g(jdn).gy // Calculate Gregorian year (gy).
1013
+ , jy = gy - 621, r = this.jalCal(jy), jdn1f = this.g2d(gy, 3, r.march), jd, jm, k;
1014
+ // Find number of days that passed since 1 Farvardin.
1015
+ k = jdn - jdn1f;
1016
+ if (k >= 0) {
1017
+ if (k <= 185) {
1018
+ // The first 6 months.
1019
+ jm = 1 + this.div(k, 31);
1020
+ jd = this.mod(k, 31) + 1;
1021
+ return {
1022
+ jy: jy,
1023
+ jm: jm,
1024
+ jd: jd
1025
+ };
1026
+ }
1027
+ else {
1028
+ // The remaining months.
1029
+ k -= 186;
1030
+ }
1031
+ }
1032
+ else {
1033
+ // Previous Jalaali year.
1034
+ jy -= 1;
1035
+ k += 179;
1036
+ if (r.leap === 1)
1037
+ k += 1;
1038
+ }
1039
+ jm = 7 + this.div(k, 30);
1040
+ jd = this.mod(k, 30) + 1;
1041
+ return {
1042
+ jy: jy,
1043
+ jm: jm,
1044
+ jd: jd
1045
+ };
1046
+ };
1047
+ JalaliCalendar.prototype.g2d = function (gy, gm, gd) {
1048
+ var d = this.div((gy + this.div(gm - 8, 6) + 100100) * 1461, 4)
1049
+ + this.div(153 * this.mod(gm + 9, 12) + 2, 5)
1050
+ + gd - 34840408;
1051
+ d = d - this.div(this.div(gy + 100100 + this.div(gm - 8, 6), 100) * 3, 4) + 752;
1052
+ return d;
1053
+ };
1054
+ JalaliCalendar.prototype.d2g = function (jdn) {
1055
+ var j, i, gd, gm, gy;
1056
+ j = 4 * jdn + 139361631;
1057
+ j = j + this.div(this.div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908;
1058
+ i = this.div(this.mod(j, 1461), 4) * 5 + 308;
1059
+ gd = this.div(this.mod(i, 153), 5) + 1;
1060
+ gm = this.mod(this.div(i, 153), 12) + 1;
1061
+ gy = this.div(j, 1461) - 100100 + this.div(8 - gm, 6);
1062
+ return {
1063
+ gy: gy,
1064
+ gm: gm,
1065
+ gd: gd
1066
+ };
1067
+ };
1068
+ /*
1069
+ Utility helper functions.
1070
+ */
1071
+ JalaliCalendar.prototype.div = function (a, b) {
1072
+ return ~~(a / b);
1073
+ };
1074
+ JalaliCalendar.prototype.mod = function (a, b) {
1075
+ return a - ~~(a / b) * b;
1076
+ };
1077
+ return JalaliCalendar;
1078
+ }());
1079
+
1080
+ var AXDateTimeModule = /** @class */ (function () {
1081
+ function AXDateTimeModule() {
1082
+ AXConfig.set({
1083
+ dateTime: {
1084
+ calendars: {
1085
+ jalali: new JalaliCalendar(),
1086
+ gregorian: new GeorgianCalendar()
1087
+ }
1088
+ }
1089
+ });
1090
+ }
1091
+ return AXDateTimeModule;
1092
+ }());
1093
+ AXDateTimeModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0__namespace, type: AXDateTimeModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1094
+ AXDateTimeModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0__namespace, type: AXDateTimeModule, declarations: [AXDateTimePipe], exports: [AXDateTimePipe] });
1095
+ AXDateTimeModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0__namespace, type: AXDateTimeModule, providers: [], imports: [[]] });
1096
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0__namespace, type: AXDateTimeModule, decorators: [{
1097
+ type: i0.NgModule,
1098
+ args: [{
1099
+ imports: [],
1100
+ exports: [AXDateTimePipe],
1101
+ declarations: [AXDateTimePipe],
1102
+ providers: [],
1103
+ }]
1104
+ }], ctorParameters: function () { return []; } });
1105
+
716
1106
  // @dynamic
717
1107
  var AXTranslator = /** @class */ (function () {
718
1108
  function AXTranslator() {
@@ -921,7 +1311,6 @@
921
1311
  exports.AXTranslationModule = AXTranslationModule;
922
1312
  exports.AXTranslator = AXTranslator;
923
1313
  exports.AXTranslatorPipe = AXTranslatorPipe;
924
- exports.AX_CALENDARS = AX_CALENDARS;
925
1314
  exports.GeorgianCalendar = GeorgianCalendar;
926
1315
  exports.testUserAgent = testUserAgent;
927
1316