@acorex/core 5.0.6 → 5.0.10

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.
@@ -168,6 +168,7 @@ class AXConfig {
168
168
  return;
169
169
  }
170
170
  if (arg1 && typeof arg1 == 'object') {
171
+ //TODO : fix override
171
172
  Object.assign(AXConfig.dataModel, arg1);
172
173
  AXConfig.dataChangeSubject.next(AXConfig.dataModel);
173
174
  return;
@@ -183,29 +184,15 @@ class AXConfig {
183
184
  AXConfig.dataModel = {};
184
185
  AXConfig.dataChangeSubject = new Subject();
185
186
 
186
- const AX_CALENDARS = [
187
- {
188
- name: 'gregorian',
189
- type: 'GeorgianCalendar'
190
- },
191
- {
192
- name: 'jalali',
193
- type: 'JalaliCalendar'
194
- }
195
- ];
196
- /**
197
- * Standard links:
198
- * {@link Foo} or {@linkplain Foo} or [[Foo]]
199
- *
200
- * Code links: (Puts Foo inside <code> tags)
201
- * {@linkcode Foo} or [[`Foo`]]
202
- */
203
187
  // @dynamic
204
188
  class AXDateTime {
205
189
  constructor(value = new Date(), calendar = AXConfig.get('dateTime.type') || 'gregorian') {
206
190
  this._calendar =
191
+ // typeof calendar == 'string'
192
+ // ? eval(`new ${AX_CALENDARS.find((c) => c.name == calendar).type}()`)
193
+ // : calendar;
207
194
  typeof calendar == 'string'
208
- ? eval(`new ${AX_CALENDARS.find((c) => c.name == calendar).type}()`)
195
+ ? AXConfig.get(`dateTime.calendars.${calendar}`)
209
196
  : calendar;
210
197
  if (value instanceof Date) {
211
198
  this._date = value;
@@ -227,9 +214,6 @@ class AXDateTime {
227
214
  }
228
215
  return date;
229
216
  }
230
- /**
231
- * This comment _supports_ [Markdown](https://marked.js.org/)
232
- */
233
217
  get date() {
234
218
  return this._date;
235
219
  }
@@ -239,14 +223,14 @@ class AXDateTime {
239
223
  clone() {
240
224
  return new AXDateTime(this.date, this.calendar.name());
241
225
  }
242
- get dayInMonth() {
243
- return this._calendar.dayInMonth(this.date);
226
+ get dayOfMonth() {
227
+ return this._calendar.dayOfMonth(this.date);
244
228
  }
245
229
  get dayOfYear() {
246
230
  return this._calendar.dayOfYear(this.date);
247
231
  }
248
- get dayInWeek() {
249
- return this._calendar.dayInWeek(this.date);
232
+ get dayOfWeek() {
233
+ return this._calendar.dayOfWeek(this.date);
250
234
  }
251
235
  get hour() {
252
236
  return this._date.getHours();
@@ -263,6 +247,9 @@ class AXDateTime {
263
247
  get monthOfYear() {
264
248
  return this._calendar.monthOfYear(this.date);
265
249
  }
250
+ get weekOfYear() {
251
+ return this._calendar.weekOfYear(this.date);
252
+ }
266
253
  get month() {
267
254
  return new AXCalendarMonth(this);
268
255
  }
@@ -286,17 +273,17 @@ class AXDateTime {
286
273
  'DDD, dd MMM yyyy') {
287
274
  format = format.replace('ss', this.pad(this.date.getSeconds(), 2));
288
275
  format = format.replace('s', this.date.getSeconds().toString());
289
- format = format.replace('dd', this.pad(this.calendar.dayInMonth(this.date), 2));
290
- format = format.replace('d', this.calendar.dayInMonth(this.date).toString());
276
+ format = format.replace('dd', this.pad(this.calendar.dayOfMonth(this.date), 2));
277
+ format = format.replace('d', this.calendar.dayOfMonth(this.date).toString());
291
278
  format = format.replace('mm', this.pad(this.date.getMinutes(), 2));
292
279
  format = format.replace('m', this.date.getMinutes().toString());
293
280
  format = format.replace('MMMM', this.calendar.monthNames[this.calendar.monthOfYear(this.date) - 1]);
294
281
  format = format.replace('MMM', this.calendar.monthShortNames[this.calendar.monthOfYear(this.date) - 1]);
295
282
  format = format.replace('MM', this.pad(this.calendar.monthOfYear(this.date), 2));
296
283
  format = format.replace(/M(?![ao])/, this.calendar.monthOfYear(this.date).toString());
297
- format = format.replace('DDDD', this.calendar.dayNames[this.calendar.dayInWeek(this.date) - 1]);
298
- format = format.replace('DDD', this.calendar.dayShortNames[this.calendar.dayInWeek(this.date) - 1]);
299
- format = format.replace(/D(?!e)/, this.calendar.dayNames[this.calendar.dayInWeek(this.date) - 1].substring(0, 3));
284
+ format = format.replace('DDDD', this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1]);
285
+ format = format.replace('DDD', this.calendar.dayShortNames[this.calendar.dayOfWeek(this.date) - 1]);
286
+ format = format.replace(/D(?!e)/, this.calendar.dayNames[this.calendar.dayOfWeek(this.date) - 1].substring(0, 3));
300
287
  format = format.replace('yyyy', this.calendar.year(this.date).toString());
301
288
  format = format.replace('YYYY', this.calendar.year(this.date).toString());
302
289
  format = format.replace('yy', this.calendar.year(this.date).toString().substring(2));
@@ -313,19 +300,45 @@ class AXDateTime {
313
300
  return this.format();
314
301
  }
315
302
  equal(value, unit = 'day') {
316
- return this.compaire(value, unit) == 0;
303
+ return this.compare(value, unit) == 0;
317
304
  }
318
- compaire(value, unit = 'day') {
319
- // TODO:
305
+ compare(value, unit = 'day') {
320
306
  const val = AXDateTime.convert(value);
321
- if (this.date == val.date) {
322
- return 0;
323
- }
324
- else if (this.date > val.date) {
325
- return 1;
326
- }
327
- else {
328
- return -1;
307
+ const func = (v1, v2) => {
308
+ if (v1 == v2) {
309
+ return 0;
310
+ }
311
+ else if (v1 > v2) {
312
+ return 1;
313
+ }
314
+ else {
315
+ return -1;
316
+ }
317
+ };
318
+ let p = 0;
319
+ switch (unit) {
320
+ case 'year':
321
+ return func(this.year, val.year);
322
+ case 'week':
323
+ p = this.compare(val, 'year');
324
+ return p == 0 ? func(this.weekOfYear, val.weekOfYear) : p;
325
+ case 'month':
326
+ p = this.compare(val, 'year');
327
+ return p == 0 ? func(this.monthOfYear, val.monthOfYear) : p;
328
+ case 'day':
329
+ p = this.compare(val, 'year');
330
+ return p == 0 ? func(this.dayOfYear, val.dayOfYear) : p;
331
+ case 'hour':
332
+ p = this.compare(val, 'day');
333
+ return p == 0 ? func(this.hour, val.hour) : p;
334
+ case 'minute':
335
+ p = this.compare(val, 'hour');
336
+ return p == 0 ? func(this.minute, val.minute) : p;
337
+ case 'second':
338
+ p = this.compare(val, 'minute');
339
+ return p == 0 ? func(this.second, val.second) : p;
340
+ default:
341
+ return func(this.date.getTime(), val.date.getTime());
329
342
  }
330
343
  }
331
344
  convert(calendar) {
@@ -347,8 +360,14 @@ class AXCalendarMonth {
347
360
  }
348
361
  class AXDateTimeRange {
349
362
  constructor(startTime, endTime) {
350
- this.startTime = startTime;
351
- this.endTime = endTime;
363
+ this._startTime = startTime;
364
+ this._endTime = endTime;
365
+ }
366
+ get startTime() {
367
+ return this._startTime;
368
+ }
369
+ get endTime() {
370
+ return this._endTime;
352
371
  }
353
372
  duration() {
354
373
  const result = {
@@ -377,8 +396,8 @@ class AXDateTimeRange {
377
396
  const one_week = one_day * 7;
378
397
  const one_year = 365.25 * one_day;
379
398
  const one_month = one_year / 12;
380
- const startTime = this.startTime.date.getTime();
381
- const endTime = this.endTime.date.getTime();
399
+ const startTime = this._startTime.date.getTime();
400
+ const endTime = this._endTime.date.getTime();
382
401
  const diff = Math.abs(endTime - startTime);
383
402
  //
384
403
  result.total.miliseconds = diff;
@@ -408,9 +427,15 @@ class AXDateTimeRange {
408
427
  result.years = Number(result.total.years.toFixed(0));
409
428
  return result;
410
429
  }
411
- enumurate(unit = 'day') {
412
- // TODO: ??
413
- return [];
430
+ enumurate(unit = 'day', amount = 1) {
431
+ // TODO: setptemper savingtime issue
432
+ const result = [];
433
+ let item = this._startTime.clone();
434
+ while (item.compare(this._endTime, unit) < 1) {
435
+ result.push(item);
436
+ item = item.add(unit, amount);
437
+ }
438
+ return result;
414
439
  }
415
440
  includes(value, unit = 'day') {
416
441
  // TODO: ??
@@ -440,21 +465,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.6", ngImpor
440
465
  args: [{ name: 'axDate' }]
441
466
  }], ctorParameters: function () { return []; } });
442
467
 
443
- class AXDateTimeModule {
444
- }
445
- AXDateTimeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXDateTimeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
446
- AXDateTimeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXDateTimeModule, declarations: [AXDateTimePipe], exports: [AXDateTimePipe] });
447
- AXDateTimeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXDateTimeModule, providers: [], imports: [[]] });
448
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXDateTimeModule, decorators: [{
449
- type: NgModule,
450
- args: [{
451
- imports: [],
452
- exports: [AXDateTimePipe],
453
- declarations: [AXDateTimePipe],
454
- providers: [],
455
- }]
456
- }] });
457
-
458
468
  class GeorgianCalendar {
459
469
  constructor() {
460
470
  this.monthNames = [
@@ -481,18 +491,28 @@ class GeorgianCalendar {
481
491
  name() {
482
492
  return 'gregorian';
483
493
  }
484
- dayInMonth(date) {
494
+ dayOfMonth(date) {
485
495
  return date.getDate();
486
496
  }
487
497
  dayOfYear(date) {
488
- const start = +new Date(date.getFullYear(), 0, 0);
489
- const diff = +date - start;
490
- const oneDay = 1000 * 60 * 60 * 24;
491
- return Math.floor(diff / oneDay);
498
+ let result = 0;
499
+ let m = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
500
+ if (this.isLeap(date)) {
501
+ m[1] = 29;
502
+ }
503
+ for (let i = 0; i < date.getMonth(); i++) {
504
+ result = result + m[i];
505
+ }
506
+ result += date.getDate();
507
+ return result;
492
508
  }
493
- dayInWeek(date) {
509
+ dayOfWeek(date) {
494
510
  return date.getDay() + 1;
495
511
  }
512
+ weekOfYear(date) {
513
+ const firstDay = new AXDateTime(date).startOf('year');
514
+ return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
515
+ }
496
516
  year(date) {
497
517
  return date.getFullYear();
498
518
  }
@@ -532,7 +552,7 @@ class GeorgianCalendar {
532
552
  case 'year':
533
553
  const yv = new Date(value);
534
554
  yv.setFullYear(yv.getFullYear() + amount);
535
- value = v.valueOf();
555
+ value = yv.valueOf();
536
556
  break;
537
557
  case 'day':
538
558
  default:
@@ -560,7 +580,10 @@ class GeorgianCalendar {
560
580
  clone.setHours(0, 0, 0, 0);
561
581
  return new AXDateTime(clone, this.name());
562
582
  case "week":
563
- const diff = clone.getDate() - clone.getDay() + (clone.getDay() === 0 ? -6 : 1);
583
+ const index = 0;
584
+ const start = index >= 0 ? index : 0;
585
+ const day = clone.getDay();
586
+ const diff = clone.getDate() - day + (start > day ? start - 7 : start);
564
587
  clone.setDate(diff);
565
588
  return new AXDateTime(clone, this.name()).startOf('day');
566
589
  case "month":
@@ -597,8 +620,363 @@ class GeorgianCalendar {
597
620
  return new AXDateTime(clone, this.name()).endOf('month');
598
621
  }
599
622
  }
623
+ isLeap(date) {
624
+ let leapYear = new Date(date.getFullYear(), 1, 29);
625
+ return leapYear.getDate() == 29;
626
+ }
627
+ }
628
+
629
+ class JalaliCalendar {
630
+ constructor() {
631
+ this.monthNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
632
+ this.monthShortNames = ("فروردین_اردیبهشت_خرداد_تیر_مرداد_شهریور_مهر_آبان_آذر_دی_بهمن_اسفند").split("_");
633
+ this.dayNames = ("شنبه_یکشنبه_دوشنبه_سه شنبه_چهارشنبه_پنج شنبه_جمعه").split("_");
634
+ this.dayShortNames = "ش_ی_د_س_چ_پ_ج".split("_");
635
+ }
636
+ name() {
637
+ return 'jalali';
638
+ }
639
+ dayOfMonth(date) {
640
+ return this.toJalali(date).day;
641
+ }
642
+ dayOfYear(date) {
643
+ const j = this.toJalali(date);
644
+ return (j.month <= 6 ? ((j.month - 1) * 31) : ((6 * 31) + (j.month - 7) * 30)) + j.day;
645
+ }
646
+ dayOfWeek(date) {
647
+ return date.getDay() == 6 ? 1 : date.getDay() + 2;
648
+ }
649
+ weekOfYear(date) {
650
+ //TODO : apply jalali
651
+ const firstDay = new AXDateTime(date).startOf('year');
652
+ return Math.ceil((((date.getTime() - firstDay.date.getTime()) / 86400000) + firstDay.date.getDay() + 1) / 7);
653
+ }
654
+ year(date) {
655
+ return this.toJalali(date).year;
656
+ }
657
+ monthOfYear(date) {
658
+ return this.toJalali(date).month;
659
+ }
660
+ add(date, unit, amount) {
661
+ let value = date.valueOf();
662
+ switch (unit) {
663
+ case 'second':
664
+ value += 1000 * amount;
665
+ break;
666
+ case 'minute':
667
+ value += 60000 * amount;
668
+ break;
669
+ case 'hour':
670
+ value += 3600000 * amount;
671
+ break;
672
+ case 'month':
673
+ {
674
+ const v = new Date(value);
675
+ let jd = this.dayOfMonth(date);
676
+ let jm = this.monthOfYear(date);
677
+ let jy = this.year(date);
678
+ jm = (jm + amount) % 12;
679
+ if (0 > jm) {
680
+ jy += (this.monthOfYear(date) + amount - jm - 12) / 12;
681
+ jm += 12;
682
+ }
683
+ else {
684
+ jy += ((this.monthOfYear(date) + amount - jm) / 12);
685
+ }
686
+ const vv = this.toGregorian(jy, jm, jd);
687
+ v.setFullYear(vv.getFullYear());
688
+ v.setMonth(vv.getMonth());
689
+ v.setDate(vv.getDate());
690
+ value = v.valueOf();
691
+ break;
692
+ }
693
+ case 'week':
694
+ value += 7 * 86400000 * amount;
695
+ break;
696
+ case 'year':
697
+ {
698
+ const v = new Date(value);
699
+ let jd = this.dayOfMonth(date);
700
+ let jm = this.monthOfYear(date);
701
+ let jy = this.year(date);
702
+ const vv = this.toGregorian(jy + amount, jm, jd);
703
+ v.setFullYear(vv.getFullYear());
704
+ v.setMonth(vv.getMonth());
705
+ v.setDate(vv.getDate());
706
+ value = v.valueOf();
707
+ }
708
+ break;
709
+ case 'day':
710
+ default:
711
+ value += 86400000 * amount;
712
+ }
713
+ return new AXDateTime(new Date(value), this.name());
714
+ }
715
+ set(date, unit, value) {
716
+ throw new Error("Method not implemented.");
717
+ }
718
+ startOf(date, unit) {
719
+ const clone = new Date(date.valueOf());
720
+ switch (unit) {
721
+ case 'second':
722
+ clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 0);
723
+ return new AXDateTime(clone, this.name());
724
+ case 'minute':
725
+ clone.setHours(clone.getHours(), clone.getMinutes(), 0, 0);
726
+ return new AXDateTime(clone, this.name());
727
+ case 'hour':
728
+ clone.setHours(clone.getHours(), 0, 0, 0);
729
+ return new AXDateTime(clone, this.name());
730
+ default:
731
+ case 'day':
732
+ clone.setHours(0, 0, 0, 0);
733
+ return new AXDateTime(clone, this.name());
734
+ case "week":
735
+ return new AXDateTime(clone, this.name()).add('day', -this.dayOfWeek(clone) + 1).startOf('day');
736
+ case "month":
737
+ {
738
+ const jy = this.year(date);
739
+ const jm = this.monthOfYear(date);
740
+ const gDate = this.toGregorian(jy, jm, 1);
741
+ return new AXDateTime(gDate, this.name()).startOf('day');
742
+ }
743
+ case "year":
744
+ {
745
+ const jy = this.year(date);
746
+ const gDate = this.toGregorian(jy, 1, 1);
747
+ return new AXDateTime(gDate, this.name()).startOf('day');
748
+ }
749
+ }
750
+ }
751
+ endOf(date, unit) {
752
+ const clone = new Date(date.valueOf());
753
+ switch (unit) {
754
+ case 'second':
755
+ clone.setHours(clone.getHours(), clone.getMinutes(), clone.getSeconds(), 999);
756
+ return new AXDateTime(clone, this.name());
757
+ case 'minute':
758
+ clone.setHours(clone.getHours(), clone.getMinutes(), 59, 999);
759
+ return new AXDateTime(clone, this.name());
760
+ case 'hour':
761
+ clone.setHours(clone.getHours(), 59, 59, 999);
762
+ return new AXDateTime(clone, this.name());
763
+ default:
764
+ case 'day':
765
+ clone.setHours(23, 59, 59, 999);
766
+ return new AXDateTime(clone, this.name());
767
+ case 'week':
768
+ {
769
+ return this.startOf(date, 'week').add('day', 6).endOf('day');
770
+ }
771
+ case 'month':
772
+ {
773
+ const jy = this.year(date);
774
+ const jm = this.monthOfYear(date);
775
+ const jd = this.monthLength(jy, jm);
776
+ const gDate = this.toGregorian(jy, jm, jd);
777
+ return new AXDateTime(gDate, this.name()).endOf('day');
778
+ }
779
+ case "year":
780
+ let jy = this.year(date);
781
+ const gDate = this.toGregorian(jy, 12, this.monthLength(jy, 12));
782
+ return new AXDateTime(gDate, this.name()).endOf('day');
783
+ }
784
+ }
785
+ toJalali(date) {
786
+ const gy = date.getFullYear();
787
+ const gm = date.getMonth() + 1;
788
+ const gd = date.getDate();
789
+ const r = this.d2j(this.g2d(gy, gm, gd));
790
+ return {
791
+ year: r.jy,
792
+ month: r.jm,
793
+ day: r.jd,
794
+ };
795
+ }
796
+ /*
797
+ Converts a Jalaali date to Gregorian.
798
+ */
799
+ toGregorian(jy, jm, jd) {
800
+ const g = this.d2g(this.j2d(jy, jm, jd));
801
+ return new Date(g.gy, g.gm - 1, g.gd);
802
+ }
803
+ /*
804
+ Checks whether a Jalaali date is valid or not.
805
+ */
806
+ isValid(jy, jm, jd) {
807
+ return jy >= -61 && jy <= 3177 &&
808
+ jm >= 1 && jm <= 12 &&
809
+ jd >= 1 && jd <= this.monthLength(jy, jm);
810
+ }
811
+ /*
812
+ Is this a leap year or not?
813
+ */
814
+ isLeapYear(jy) {
815
+ return this.jalCal(jy).leap === 0;
816
+ }
817
+ /*
818
+ Number of days in a given month in a Jalaali year.
819
+ */
820
+ monthLength(jy, jm) {
821
+ if (jm <= 6)
822
+ return 31;
823
+ if (jm <= 11)
824
+ return 30;
825
+ if (this.isLeapYear(jy))
826
+ return 30;
827
+ return 29;
828
+ }
829
+ jalCal(jy) {
830
+ // Jalaali years starting the 33-year rule.
831
+ let breaks = [-61, 9, 38, 199, 426, 686, 756, 818, 1111, 1181, 1210,
832
+ 1635, 2060, 2097, 2192, 2262, 2324, 2394, 2456, 3178
833
+ ], bl = breaks.length, gy = jy + 621, leapJ = -14, jp = breaks[0], jm, jump, leap, leapG, march, n, i;
834
+ if (jy < jp || jy >= breaks[bl - 1])
835
+ throw new Error('Invalid Jalaali year ' + jy);
836
+ // Find the limiting years for the Jalaali year jy.
837
+ for (i = 1; i < bl; i += 1) {
838
+ jm = breaks[i];
839
+ jump = jm - jp;
840
+ if (jy < jm)
841
+ break;
842
+ leapJ = leapJ + this.div(jump, 33) * 8 + this.div(this.mod(jump, 33), 4);
843
+ jp = jm;
844
+ }
845
+ n = jy - jp;
846
+ // Find the number of leap years from AD 621 to the beginning
847
+ // of the current Jalaali year in the Persian calendar.
848
+ leapJ = leapJ + this.div(n, 33) * 8 + this.div(this.mod(n, 33) + 3, 4);
849
+ if (this.mod(jump, 33) === 4 && jump - n === 4)
850
+ leapJ += 1;
851
+ // And the same in the Gregorian calendar (until the year gy).
852
+ leapG = this.div(gy, 4) - this.div((this.div(gy, 100) + 1) * 3, 4) - 150;
853
+ // Determine the Gregorian date of Farvardin the 1st.
854
+ march = 20 + leapJ - leapG;
855
+ // Find how many years have passed since the last leap year.
856
+ if (jump - n < 6)
857
+ n = n - jump + this.div(jump + 4, 33) * 33;
858
+ leap = this.mod(this.mod(n + 1, 33) - 1, 4);
859
+ if (leap === -1) {
860
+ leap = 4;
861
+ }
862
+ return {
863
+ leap: leap,
864
+ gy: gy,
865
+ march: march
866
+ };
867
+ }
868
+ /*
869
+ Converts a date of the Jalaali calendar to the Julian Day number.
870
+ @param jy Jalaali year (1 to 3100)
871
+ @param jm Jalaali month (1 to 12)
872
+ @param jd Jalaali day (1 to 29/31)
873
+ @return Julian Day number
874
+ */
875
+ j2d(jy, jm, jd) {
876
+ let r = this.jalCal(jy);
877
+ return this.g2d(r.gy, 3, r.march) + (jm - 1) * 31 - this.div(jm, 7) * (jm - 7) + jd - 1;
878
+ }
879
+ /*
880
+ Converts the Julian Day number to a date in the Jalaali calendar.
881
+ @param jdn Julian Day number
882
+ @return
883
+ jy: Jalaali year (1 to 3100)
884
+ jm: Jalaali month (1 to 12)
885
+ jd: Jalaali day (1 to 29/31)
886
+ */
887
+ d2j(jdn) {
888
+ let gy = this.d2g(jdn).gy // Calculate Gregorian year (gy).
889
+ , jy = gy - 621, r = this.jalCal(jy), jdn1f = this.g2d(gy, 3, r.march), jd, jm, k;
890
+ // Find number of days that passed since 1 Farvardin.
891
+ k = jdn - jdn1f;
892
+ if (k >= 0) {
893
+ if (k <= 185) {
894
+ // The first 6 months.
895
+ jm = 1 + this.div(k, 31);
896
+ jd = this.mod(k, 31) + 1;
897
+ return {
898
+ jy: jy,
899
+ jm: jm,
900
+ jd: jd
901
+ };
902
+ }
903
+ else {
904
+ // The remaining months.
905
+ k -= 186;
906
+ }
907
+ }
908
+ else {
909
+ // Previous Jalaali year.
910
+ jy -= 1;
911
+ k += 179;
912
+ if (r.leap === 1)
913
+ k += 1;
914
+ }
915
+ jm = 7 + this.div(k, 30);
916
+ jd = this.mod(k, 30) + 1;
917
+ return {
918
+ jy: jy,
919
+ jm: jm,
920
+ jd: jd
921
+ };
922
+ }
923
+ g2d(gy, gm, gd) {
924
+ let d = this.div((gy + this.div(gm - 8, 6) + 100100) * 1461, 4)
925
+ + this.div(153 * this.mod(gm + 9, 12) + 2, 5)
926
+ + gd - 34840408;
927
+ d = d - this.div(this.div(gy + 100100 + this.div(gm - 8, 6), 100) * 3, 4) + 752;
928
+ return d;
929
+ }
930
+ d2g(jdn) {
931
+ let j, i, gd, gm, gy;
932
+ j = 4 * jdn + 139361631;
933
+ j = j + this.div(this.div(4 * jdn + 183187720, 146097) * 3, 4) * 4 - 3908;
934
+ i = this.div(this.mod(j, 1461), 4) * 5 + 308;
935
+ gd = this.div(this.mod(i, 153), 5) + 1;
936
+ gm = this.mod(this.div(i, 153), 12) + 1;
937
+ gy = this.div(j, 1461) - 100100 + this.div(8 - gm, 6);
938
+ return {
939
+ gy: gy,
940
+ gm: gm,
941
+ gd: gd
942
+ };
943
+ }
944
+ /*
945
+ Utility helper functions.
946
+ */
947
+ div(a, b) {
948
+ return ~~(a / b);
949
+ }
950
+ mod(a, b) {
951
+ return a - ~~(a / b) * b;
952
+ }
600
953
  }
601
954
 
955
+ class AXDateTimeModule {
956
+ constructor() {
957
+ AXConfig.set({
958
+ dateTime: {
959
+ calendars: {
960
+ jalali: new JalaliCalendar(),
961
+ gregorian: new GeorgianCalendar()
962
+ }
963
+ }
964
+ });
965
+ }
966
+ }
967
+ AXDateTimeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXDateTimeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
968
+ AXDateTimeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXDateTimeModule, declarations: [AXDateTimePipe], exports: [AXDateTimePipe] });
969
+ AXDateTimeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXDateTimeModule, providers: [], imports: [[]] });
970
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXDateTimeModule, decorators: [{
971
+ type: NgModule,
972
+ args: [{
973
+ imports: [],
974
+ exports: [AXDateTimePipe],
975
+ declarations: [AXDateTimePipe],
976
+ providers: [],
977
+ }]
978
+ }], ctorParameters: function () { return []; } });
979
+
602
980
  // @dynamic
603
981
  class AXTranslator {
604
982
  static get onChange() {
@@ -755,6 +1133,19 @@ class AXPlatform {
755
1133
  is(name) {
756
1134
  return PLATFORMS_MAP[name](window) || false;
757
1135
  }
1136
+ switchDarkMode() {
1137
+ const _html = document.getElementsByTagName("html")[0];
1138
+ const _class = 'ax-dark-mode';
1139
+ const _isDark = _html.classList.contains(_class);
1140
+ if (_isDark) {
1141
+ _html.classList.remove(_class);
1142
+ localStorage.setItem("MODE", "light");
1143
+ }
1144
+ else {
1145
+ _html.classList.add(_class);
1146
+ localStorage.setItem("MODE", "dark");
1147
+ }
1148
+ }
758
1149
  }
759
1150
  AXPlatform.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXPlatform, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
760
1151
  AXPlatform.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.6", ngImport: i0, type: AXPlatform, providedIn: 'platform' });
@@ -774,5 +1165,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.6", ngImpor
774
1165
  * Generated bundle index. Do not edit.
775
1166
  */
776
1167
 
777
- export { AXCalendarMonth, AXConfig, AXCoreModule, AXDateTime, AXDateTimeModule, AXDateTimePipe, AXDateTimeRange, AXDrawingUtil, AXObjectUtil, AXPlatform, AXPlatformEvent, AXSafePipe, AXTranslationModule, AXTranslator, AXTranslatorPipe, AX_CALENDARS, GeorgianCalendar, testUserAgent };
1168
+ export { AXCalendarMonth, AXConfig, AXCoreModule, AXDateTime, AXDateTimeModule, AXDateTimePipe, AXDateTimeRange, AXDrawingUtil, AXObjectUtil, AXPlatform, AXPlatformEvent, AXSafePipe, AXTranslationModule, AXTranslator, AXTranslatorPipe, GeorgianCalendar, testUserAgent };
778
1169
  //# sourceMappingURL=acorex-core.js.map