@taiga-ui/cdk 2.26.0 → 2.29.0

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.
Files changed (140) hide show
  1. package/README.md +4 -5
  2. package/abstract/control.d.ts +1 -1
  3. package/abstract/interactive.d.ts +4 -4
  4. package/abstract/taiga-ui-cdk-abstract.metadata.json +1 -1
  5. package/bundles/taiga-ui-cdk-abstract.umd.js +3 -3
  6. package/bundles/taiga-ui-cdk-abstract.umd.js.map +1 -1
  7. package/bundles/taiga-ui-cdk-abstract.umd.min.js +1 -1
  8. package/bundles/taiga-ui-cdk-abstract.umd.min.js.map +1 -1
  9. package/bundles/taiga-ui-cdk-date-time.umd.js +366 -287
  10. package/bundles/taiga-ui-cdk-date-time.umd.js.map +1 -1
  11. package/bundles/taiga-ui-cdk-date-time.umd.min.js +1 -1
  12. package/bundles/taiga-ui-cdk-date-time.umd.min.js.map +1 -1
  13. package/bundles/taiga-ui-cdk-directives-copy-processor.umd.js +276 -0
  14. package/bundles/taiga-ui-cdk-directives-copy-processor.umd.js.map +1 -0
  15. package/bundles/taiga-ui-cdk-directives-copy-processor.umd.min.js +16 -0
  16. package/bundles/taiga-ui-cdk-directives-copy-processor.umd.min.js.map +1 -0
  17. package/bundles/taiga-ui-cdk-directives-for.umd.js.map +1 -1
  18. package/bundles/taiga-ui-cdk-directives-for.umd.min.js.map +1 -1
  19. package/bundles/taiga-ui-cdk-directives-media.umd.js +1 -1
  20. package/bundles/taiga-ui-cdk-directives-media.umd.js.map +1 -1
  21. package/bundles/taiga-ui-cdk-directives-media.umd.min.js +1 -1
  22. package/bundles/taiga-ui-cdk-directives-media.umd.min.js.map +1 -1
  23. package/bundles/taiga-ui-cdk-services.umd.js +4 -4
  24. package/bundles/taiga-ui-cdk-services.umd.js.map +1 -1
  25. package/bundles/taiga-ui-cdk-services.umd.min.js +1 -1
  26. package/bundles/taiga-ui-cdk-services.umd.min.js.map +1 -1
  27. package/bundles/taiga-ui-cdk-tokens.umd.js +5 -0
  28. package/bundles/taiga-ui-cdk-tokens.umd.js.map +1 -1
  29. package/bundles/taiga-ui-cdk-tokens.umd.min.js +1 -1
  30. package/bundles/taiga-ui-cdk-tokens.umd.min.js.map +1 -1
  31. package/bundles/taiga-ui-cdk-utils-miscellaneous.umd.js +4 -1
  32. package/bundles/taiga-ui-cdk-utils-miscellaneous.umd.js.map +1 -1
  33. package/bundles/taiga-ui-cdk-utils-miscellaneous.umd.min.js +1 -1
  34. package/bundles/taiga-ui-cdk-utils-miscellaneous.umd.min.js.map +1 -1
  35. package/date-time/date-separator.d.ts +2 -0
  36. package/date-time/day-range.d.ts +24 -12
  37. package/date-time/day.d.ts +71 -58
  38. package/date-time/index.d.ts +1 -0
  39. package/date-time/month-range.d.ts +1 -1
  40. package/date-time/month.d.ts +26 -26
  41. package/date-time/taiga-ui-cdk-date-time.metadata.json +1 -1
  42. package/date-time/time.d.ts +12 -12
  43. package/date-time/year.d.ts +27 -27
  44. package/directives/copy-processor/copy-processor.directive.d.ts +7 -0
  45. package/directives/copy-processor/copy-processor.module.d.ts +2 -0
  46. package/directives/copy-processor/index.d.ts +2 -0
  47. package/directives/copy-processor/package.json +13 -0
  48. package/directives/copy-processor/taiga-ui-cdk-directives-copy-processor.d.ts +4 -0
  49. package/directives/copy-processor/taiga-ui-cdk-directives-copy-processor.metadata.json +1 -0
  50. package/directives/for/for.directive.d.ts +1 -1
  51. package/directives/for/taiga-ui-cdk-directives-for.metadata.json +1 -1
  52. package/directives/media/media.directive.d.ts +1 -1
  53. package/directives/media/taiga-ui-cdk-directives-media.metadata.json +1 -1
  54. package/esm2015/abstract/control.js +1 -1
  55. package/esm2015/abstract/interactive.js +4 -4
  56. package/esm2015/date-time/date-separator.js +5 -0
  57. package/esm2015/date-time/day-range.js +46 -23
  58. package/esm2015/date-time/day.js +164 -122
  59. package/esm2015/date-time/index.js +2 -1
  60. package/esm2015/date-time/month-range.js +6 -6
  61. package/esm2015/date-time/month.js +56 -56
  62. package/esm2015/date-time/time.js +40 -40
  63. package/esm2015/date-time/year.js +49 -49
  64. package/esm2015/directives/copy-processor/copy-processor.directive.js +37 -0
  65. package/esm2015/directives/copy-processor/copy-processor.module.js +13 -0
  66. package/esm2015/directives/copy-processor/index.js +3 -0
  67. package/esm2015/directives/copy-processor/taiga-ui-cdk-directives-copy-processor.js +5 -0
  68. package/esm2015/directives/for/for.directive.js +1 -1
  69. package/esm2015/directives/media/media.directive.js +2 -2
  70. package/esm2015/services/destroy.service.js +6 -3
  71. package/esm2015/services/obscured.service.js +1 -1
  72. package/esm2015/services/pan.service.js +3 -3
  73. package/esm2015/services/static-request.service.js +1 -1
  74. package/esm2015/tokens/index.js +2 -1
  75. package/esm2015/tokens/touch-supported.js +6 -0
  76. package/esm2015/utils/miscellaneous/ease-in-out-quad.js +2 -2
  77. package/esm2015/utils/miscellaneous/identity.js +4 -1
  78. package/esm5/abstract/control.js +1 -1
  79. package/esm5/abstract/interactive.js +4 -4
  80. package/esm5/date-time/date-separator.js +5 -0
  81. package/esm5/date-time/day-range.js +51 -23
  82. package/esm5/date-time/day.js +168 -122
  83. package/esm5/date-time/index.js +2 -1
  84. package/esm5/date-time/month-range.js +6 -6
  85. package/esm5/date-time/month.js +56 -56
  86. package/esm5/date-time/time.js +41 -41
  87. package/esm5/date-time/year.js +49 -49
  88. package/esm5/directives/copy-processor/copy-processor.directive.js +38 -0
  89. package/esm5/directives/copy-processor/copy-processor.module.js +16 -0
  90. package/esm5/directives/copy-processor/index.js +3 -0
  91. package/esm5/directives/copy-processor/taiga-ui-cdk-directives-copy-processor.js +5 -0
  92. package/esm5/directives/for/for.directive.js +1 -1
  93. package/esm5/directives/media/media.directive.js +2 -2
  94. package/esm5/services/destroy.service.js +4 -4
  95. package/esm5/services/obscured.service.js +1 -1
  96. package/esm5/services/pan.service.js +3 -3
  97. package/esm5/services/static-request.service.js +1 -1
  98. package/esm5/tokens/index.js +2 -1
  99. package/esm5/tokens/touch-supported.js +6 -0
  100. package/esm5/utils/miscellaneous/ease-in-out-quad.js +2 -2
  101. package/esm5/utils/miscellaneous/identity.js +4 -1
  102. package/fesm2015/taiga-ui-cdk-abstract.js +3 -3
  103. package/fesm2015/taiga-ui-cdk-abstract.js.map +1 -1
  104. package/fesm2015/taiga-ui-cdk-date-time.js +343 -275
  105. package/fesm2015/taiga-ui-cdk-date-time.js.map +1 -1
  106. package/fesm2015/taiga-ui-cdk-directives-copy-processor.js +52 -0
  107. package/fesm2015/taiga-ui-cdk-directives-copy-processor.js.map +1 -0
  108. package/fesm2015/taiga-ui-cdk-directives-for.js.map +1 -1
  109. package/fesm2015/taiga-ui-cdk-directives-media.js +1 -1
  110. package/fesm2015/taiga-ui-cdk-directives-media.js.map +1 -1
  111. package/fesm2015/taiga-ui-cdk-services.js +7 -4
  112. package/fesm2015/taiga-ui-cdk-services.js.map +1 -1
  113. package/fesm2015/taiga-ui-cdk-tokens.js +5 -1
  114. package/fesm2015/taiga-ui-cdk-tokens.js.map +1 -1
  115. package/fesm2015/taiga-ui-cdk-utils-miscellaneous.js +4 -1
  116. package/fesm2015/taiga-ui-cdk-utils-miscellaneous.js.map +1 -1
  117. package/fesm5/taiga-ui-cdk-abstract.js +3 -3
  118. package/fesm5/taiga-ui-cdk-abstract.js.map +1 -1
  119. package/fesm5/taiga-ui-cdk-date-time.js +364 -287
  120. package/fesm5/taiga-ui-cdk-date-time.js.map +1 -1
  121. package/fesm5/taiga-ui-cdk-directives-copy-processor.js +56 -0
  122. package/fesm5/taiga-ui-cdk-directives-copy-processor.js.map +1 -0
  123. package/fesm5/taiga-ui-cdk-directives-for.js.map +1 -1
  124. package/fesm5/taiga-ui-cdk-directives-media.js +1 -1
  125. package/fesm5/taiga-ui-cdk-directives-media.js.map +1 -1
  126. package/fesm5/taiga-ui-cdk-services.js +5 -5
  127. package/fesm5/taiga-ui-cdk-services.js.map +1 -1
  128. package/fesm5/taiga-ui-cdk-tokens.js +5 -1
  129. package/fesm5/taiga-ui-cdk-tokens.js.map +1 -1
  130. package/fesm5/taiga-ui-cdk-utils-miscellaneous.js +4 -1
  131. package/fesm5/taiga-ui-cdk-utils-miscellaneous.js.map +1 -1
  132. package/package.json +4 -4
  133. package/services/destroy.service.d.ts +3 -2
  134. package/services/obscured.service.d.ts +1 -1
  135. package/services/static-request.service.d.ts +1 -1
  136. package/services/taiga-ui-cdk-services.metadata.json +1 -1
  137. package/tokens/index.d.ts +1 -0
  138. package/tokens/taiga-ui-cdk-tokens.metadata.json +1 -1
  139. package/tokens/touch-supported.d.ts +2 -0
  140. package/utils/miscellaneous/identity.d.ts +3 -0
@@ -279,6 +279,10 @@
279
279
  factory: function () { return 'DMY'; },
280
280
  });
281
281
 
282
+ var TUI_DATE_SEPARATOR = new core.InjectionToken('Date separator for Taiga UI components', {
283
+ factory: function () { return '.'; },
284
+ });
285
+
282
286
  /**
283
287
  * Immutable year object
284
288
  * @nosideeffects
@@ -288,6 +292,54 @@
288
292
  this.year = year;
289
293
  classes.tuiAssert.assert(TuiYear.isValidYear(year));
290
294
  }
295
+ /**
296
+ * Checks year for validity
297
+ */
298
+ TuiYear.isValidYear = function (year) {
299
+ return Number.isInteger(year) && math.inRange(year, MIN_YEAR, MAX_YEAR + 1);
300
+ };
301
+ /**
302
+ * Check if passed year is a leap year
303
+ */
304
+ TuiYear.isLeapYear = function (year) {
305
+ classes.tuiAssert.assert(TuiYear.isValidYear(year));
306
+ return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
307
+ };
308
+ /**
309
+ * Returns amount of leap years from year 0 to the passed one
310
+ */
311
+ TuiYear.getAbsoluteLeapYears = function (year) {
312
+ classes.tuiAssert.assert(TuiYear.isValidYear(year));
313
+ return Math.ceil(year / 400) + (Math.ceil(year / 4) - Math.ceil(year / 100));
314
+ };
315
+ /**
316
+ * @deprecated DONT USE IT (will be deleted soon)
317
+ *
318
+ * Returns day of week offset of the beginning of the passed year
319
+ *
320
+ * @param year
321
+ * @param absoluteLeapYears amount of leap years prior to the passed one
322
+ * @return offset in days
323
+ */
324
+ TuiYear.getYearStartDaysOffset = function (year, absoluteLeapYears) {
325
+ classes.tuiAssert.assert(TuiYear.isValidYear(year));
326
+ classes.tuiAssert.assert(Number.isInteger(absoluteLeapYears));
327
+ classes.tuiAssert.assert(year >= absoluteLeapYears);
328
+ classes.tuiAssert.assert(absoluteLeapYears >= 0);
329
+ return ((absoluteLeapYears * DAYS_IN_LEAP_YEAR +
330
+ (year - absoluteLeapYears) * DAYS_IN_NORMAL_YEAR +
331
+ 5) %
332
+ DAYS_IN_WEEK);
333
+ };
334
+ TuiYear.lengthBetween = function (from, to) {
335
+ return to.year - from.year;
336
+ };
337
+ /**
338
+ * Normalizes year by clamping it between min and max years
339
+ */
340
+ TuiYear.normalizeYearPart = function (year) {
341
+ return math.normalizeToIntNumber(year, MIN_YEAR, MAX_YEAR);
342
+ };
291
343
  Object.defineProperty(TuiYear.prototype, "formattedYear", {
292
344
  get: function () {
293
345
  return format.padStart(this.year.toString(), 4, '0');
@@ -380,54 +432,6 @@
380
432
  TuiYear.prototype.toJSON = function () {
381
433
  return this.formattedYear;
382
434
  };
383
- /**
384
- * Checks year for validity
385
- */
386
- TuiYear.isValidYear = function (year) {
387
- return Number.isInteger(year) && math.inRange(year, MIN_YEAR, MAX_YEAR + 1);
388
- };
389
- /**
390
- * Check if passed year is a leap year
391
- */
392
- TuiYear.isLeapYear = function (year) {
393
- classes.tuiAssert.assert(TuiYear.isValidYear(year));
394
- return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
395
- };
396
- /**
397
- * Returns amount of leap years from year 0 to the passed one
398
- */
399
- TuiYear.getAbsoluteLeapYears = function (year) {
400
- classes.tuiAssert.assert(TuiYear.isValidYear(year));
401
- return Math.ceil(year / 400) + (Math.ceil(year / 4) - Math.ceil(year / 100));
402
- };
403
- /**
404
- * @deprecated DONT USE IT (will be deleted soon)
405
- *
406
- * Returns day of week offset of the beginning of the passed year
407
- *
408
- * @param year
409
- * @param absoluteLeapYears amount of leap years prior to the passed one
410
- * @return offset in days
411
- */
412
- TuiYear.getYearStartDaysOffset = function (year, absoluteLeapYears) {
413
- classes.tuiAssert.assert(TuiYear.isValidYear(year));
414
- classes.tuiAssert.assert(Number.isInteger(absoluteLeapYears));
415
- classes.tuiAssert.assert(year >= absoluteLeapYears);
416
- classes.tuiAssert.assert(absoluteLeapYears >= 0);
417
- return ((absoluteLeapYears * DAYS_IN_LEAP_YEAR +
418
- (year - absoluteLeapYears) * DAYS_IN_NORMAL_YEAR +
419
- 5) %
420
- DAYS_IN_WEEK);
421
- };
422
- TuiYear.lengthBetween = function (from, to) {
423
- return to.year - from.year;
424
- };
425
- /**
426
- * Normalizes year by clamping it between min and max years
427
- */
428
- TuiYear.normalizeYearPart = function (year) {
429
- return math.normalizeToIntNumber(year, MIN_YEAR, MAX_YEAR);
430
- };
431
435
  return TuiYear;
432
436
  }());
433
437
 
@@ -446,6 +450,61 @@
446
450
  classes.tuiAssert.assert(TuiMonth.isValidMonth(year, month));
447
451
  return _this;
448
452
  }
453
+ /**
454
+ * Tests month and year for validity
455
+ */
456
+ TuiMonth.isValidMonth = function (year, month) {
457
+ return TuiYear.isValidYear(year) && TuiMonth.isValidMonthPart(month);
458
+ };
459
+ /**
460
+ * Returns number of days in a month
461
+ */
462
+ TuiMonth.getMonthDaysCount = function (month, isLeapYear) {
463
+ classes.tuiAssert.assert(TuiMonth.isValidMonthPart(month));
464
+ switch (month) {
465
+ case 1 /* February */:
466
+ return isLeapYear ? 29 : 28;
467
+ case 3 /* April */:
468
+ case 5 /* June */:
469
+ case 8 /* September */:
470
+ case 10 /* November */:
471
+ return 30;
472
+ default:
473
+ return 31;
474
+ }
475
+ };
476
+ /**
477
+ * Returns current month and year based on local time zone
478
+ * @nosideeffects
479
+ */
480
+ TuiMonth.currentLocal = function () {
481
+ var nativeDate = new Date();
482
+ return new TuiMonth(nativeDate.getFullYear(), nativeDate.getMonth());
483
+ };
484
+ /**
485
+ * Returns current month and year based on UTC
486
+ */
487
+ TuiMonth.currentUtc = function () {
488
+ var nativeDate = new Date();
489
+ return new TuiMonth(nativeDate.getUTCFullYear(), nativeDate.getUTCMonth());
490
+ };
491
+ TuiMonth.lengthBetween = function (from, to) {
492
+ var absoluteFrom = from.month + from.year * 12;
493
+ var absoluteTo = to.month + to.year * 12;
494
+ return absoluteTo - absoluteFrom;
495
+ };
496
+ /**
497
+ * Normalizes number by clamping it between min and max month
498
+ */
499
+ TuiMonth.normalizeMonthPart = function (month) {
500
+ return math.normalizeToIntNumber(month, MIN_MONTH, MAX_MONTH);
501
+ };
502
+ /**
503
+ * Tests month for validity
504
+ */
505
+ TuiMonth.isValidMonthPart = function (month) {
506
+ return Number.isInteger(month) && math.inRange(month, MIN_MONTH, MAX_MONTH + 1);
507
+ };
449
508
  Object.defineProperty(TuiMonth.prototype, "formattedMonthPart", {
450
509
  get: function () {
451
510
  return format.padStart((this.month + 1).toString(), 2, '0');
@@ -571,76 +630,163 @@
571
630
  TuiMonth.prototype.toUtcNativeDate = function () {
572
631
  return new Date(Date.UTC(this.year, this.month));
573
632
  };
633
+ return TuiMonth;
634
+ }(TuiYear));
635
+
636
+ // TODO: Localized formatting
637
+ /**
638
+ * Immutable date object, consisting of day, month and year
639
+ */
640
+ var TuiDay = /** @class */ (function (_super) {
641
+ __extends(TuiDay, _super);
642
+ function TuiDay(year, month, day) {
643
+ var _this = _super.call(this, year, month) || this;
644
+ _this.day = day;
645
+ classes.tuiAssert.assert(TuiDay.isValidDay(year, month, day));
646
+ return _this;
647
+ }
574
648
  /**
575
- * Tests month and year for validity
649
+ * Creates {@link TuiDay} from native {@link Date} based on local time zone
576
650
  */
577
- TuiMonth.isValidMonth = function (year, month) {
578
- return TuiYear.isValidYear(year) && TuiMonth.isValidMonthPart(month);
651
+ TuiDay.fromLocalNativeDate = function (date) {
652
+ return new TuiDay(date.getFullYear(), date.getMonth(), date.getDate());
579
653
  };
580
654
  /**
581
- * Returns number of days in a month
655
+ * Creates {@link TuiDay} from native {@link Date} using UTC
582
656
  */
583
- TuiMonth.getMonthDaysCount = function (month, isLeapYear) {
584
- classes.tuiAssert.assert(TuiMonth.isValidMonthPart(month));
585
- switch (month) {
586
- case 1 /* February */:
587
- return isLeapYear ? 29 : 28;
588
- case 3 /* April */:
589
- case 5 /* June */:
590
- case 8 /* September */:
591
- case 10 /* November */:
592
- return 30;
593
- default:
594
- return 31;
657
+ TuiDay.fromUtcNativeDate = function (date) {
658
+ return new TuiDay(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
659
+ };
660
+ /**
661
+ * Check validity of year, month and day
662
+ *
663
+ * @param year
664
+ * @param month
665
+ * @param day
666
+ * @return boolean validity
667
+ */
668
+ TuiDay.isValidDay = function (year, month, day) {
669
+ return (TuiMonth.isValidMonth(year, month) &&
670
+ Number.isInteger(day) &&
671
+ math.inRange(day, MIN_DAY, TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year)) + 1));
672
+ };
673
+ /**
674
+ * @deprecated DONT USE IT (will be deleted soon)
675
+ *
676
+ * Calculated day on a calendar grid
677
+ *
678
+ * @param month
679
+ * @param row row in a calendar
680
+ * @param col column in a calendar
681
+ * @return resulting day on these coordinates (could exceed passed month)
682
+ */
683
+ TuiDay.getDayFromMonthRowCol = function (month, row, col) {
684
+ classes.tuiAssert.assert(Number.isInteger(row));
685
+ classes.tuiAssert.assert(math.inRange(row, 0, 6));
686
+ classes.tuiAssert.assert(Number.isInteger(col));
687
+ classes.tuiAssert.assert(math.inRange(col, 0, DAYS_IN_WEEK));
688
+ var day = row * DAYS_IN_WEEK + col - month.monthStartDaysOffset + 1;
689
+ if (day > month.daysCount) {
690
+ day = day - month.daysCount;
691
+ month = month.append({ month: 1 });
595
692
  }
693
+ if (day <= 0) {
694
+ month = month.append({ month: -1 });
695
+ day = month.daysCount + day;
696
+ }
697
+ return new TuiDay(month.year, month.month, day);
596
698
  };
597
699
  /**
598
- * Returns current month and year based on local time zone
599
- * @nosideeffects
700
+ * Current day based on local time zone
600
701
  */
601
- TuiMonth.currentLocal = function () {
702
+ TuiDay.currentLocal = function () {
602
703
  var nativeDate = new Date();
603
- return new TuiMonth(nativeDate.getFullYear(), nativeDate.getMonth());
704
+ var year = nativeDate.getFullYear();
705
+ var month = nativeDate.getMonth();
706
+ var day = nativeDate.getDate();
707
+ return new TuiDay(year, month, day);
604
708
  };
605
709
  /**
606
- * Returns current month and year based on UTC
710
+ * Calculates {@link TuiDay} normalizing year, month and day. {@link NaN} is turned into minimal value.
711
+ *
712
+ * @param year any year value, including invalid
713
+ * @param month any month value, including invalid (months start with 0)
714
+ * @param day any day value, including invalid
715
+ * @return normalized date
607
716
  */
608
- TuiMonth.currentUtc = function () {
609
- var nativeDate = new Date();
610
- return new TuiMonth(nativeDate.getUTCFullYear(), nativeDate.getUTCMonth());
717
+ TuiDay.normalizeOf = function (year, month, day) {
718
+ var normalizedYear = TuiYear.normalizeYearPart(year);
719
+ var normalizedMonth = TuiMonth.normalizeMonthPart(month);
720
+ var normalizedDay = TuiDay.normalizeDayPart(day, normalizedMonth, normalizedYear);
721
+ return new TuiDay(normalizedYear, normalizedMonth, normalizedDay);
611
722
  };
612
- TuiMonth.lengthBetween = function (from, to) {
613
- var absoluteFrom = from.month + from.year * 12;
614
- var absoluteTo = to.month + to.year * 12;
615
- return absoluteTo - absoluteFrom;
723
+ TuiDay.lengthBetween = function (from, to) {
724
+ return Math.round((to.toLocalNativeDate().getTime() - from.toLocalNativeDate().getTime()) /
725
+ (1000 * 60 * 60 * 24));
726
+ };
727
+ TuiDay.parseRawDateString = function (date, dateMode) {
728
+ if (dateMode === void 0) { dateMode = 'DMY'; }
729
+ classes.tuiAssert.assert(date.length === DATE_FILLER_LENGTH, '[parseRawDateString]: wrong date string length');
730
+ switch (dateMode) {
731
+ case 'YMD':
732
+ return {
733
+ day: parseInt(date.slice(8, 10), 10),
734
+ month: parseInt(date.slice(5, 7), 10) - 1,
735
+ year: parseInt(date.slice(0, 4), 10),
736
+ };
737
+ case 'MDY':
738
+ return {
739
+ day: parseInt(date.slice(3, 5), 10),
740
+ month: parseInt(date.slice(0, 2), 10) - 1,
741
+ year: parseInt(date.slice(6, 10), 10),
742
+ };
743
+ default:
744
+ case 'DMY':
745
+ return {
746
+ day: parseInt(date.slice(0, 2), 10),
747
+ month: parseInt(date.slice(3, 5), 10) - 1,
748
+ year: parseInt(date.slice(6, 10), 10),
749
+ };
750
+ }
616
751
  };
752
+ // TODO: Move month and year related code corresponding classes
617
753
  /**
618
- * Normalizes number by clamping it between min and max month
754
+ * Parsing a string with date with normalization
755
+ *
756
+ * @param rawDate date string
757
+ * @param dateMode date format of the date string (DMY | MDY | YMD)
758
+ * @return normalized date
619
759
  */
620
- TuiMonth.normalizeMonthPart = function (month) {
621
- return math.normalizeToIntNumber(month, MIN_MONTH, MAX_MONTH);
760
+ TuiDay.normalizeParse = function (rawDate, dateMode) {
761
+ if (dateMode === void 0) { dateMode = 'DMY'; }
762
+ var _a = this.parseRawDateString(rawDate, dateMode), day = _a.day, month = _a.month, year = _a.year;
763
+ return TuiDay.normalizeOf(year, month, day);
622
764
  };
623
765
  /**
624
- * Tests month for validity
766
+ * Parsing a date stringified in a toJSON format
767
+ * @param yearMonthDayString date string in format of YYYY-MM-DD
768
+ * @return date
769
+ * @throws exceptions if any part of the date is invalid
625
770
  */
626
- TuiMonth.isValidMonthPart = function (month) {
627
- return Number.isInteger(month) && math.inRange(month, MIN_MONTH, MAX_MONTH + 1);
628
- };
629
- return TuiMonth;
630
- }(TuiYear));
631
-
632
- // TODO: Localized formatting
633
- /**
634
- * Immutable date object, consisting of day, month and year
635
- */
636
- var TuiDay = /** @class */ (function (_super) {
637
- __extends(TuiDay, _super);
638
- function TuiDay(year, month, day) {
639
- var _this = _super.call(this, year, month) || this;
640
- _this.day = day;
641
- classes.tuiAssert.assert(TuiDay.isValidDay(year, month, day));
642
- return _this;
643
- }
771
+ TuiDay.jsonParse = function (yearMonthDayString) {
772
+ var _a = this.parseRawDateString(yearMonthDayString, 'YMD'), day = _a.day, month = _a.month, year = _a.year;
773
+ if (!TuiYear.isValidYear(year)) {
774
+ throw new Error('Invalid year: ' + year);
775
+ }
776
+ if (!TuiMonth.isValidMonth(year, month)) {
777
+ throw new Error('Invalid month: ' + month);
778
+ }
779
+ if (!Number.isInteger(day) ||
780
+ !math.inRange(day, MIN_DAY, TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year)) + 1)) {
781
+ throw new Error('Invalid day: ' + day);
782
+ }
783
+ return new TuiDay(year, month, day);
784
+ };
785
+ TuiDay.normalizeDayPart = function (day, month, year) {
786
+ classes.tuiAssert.assert(TuiMonth.isValidMonth(year, month));
787
+ var monthDaysCount = TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year));
788
+ return math.normalizeToIntNumber(day, 1, monthDaysCount);
789
+ };
644
790
  Object.defineProperty(TuiDay.prototype, "formattedDayPart", {
645
791
  get: function () {
646
792
  return format.padStart(this.day.toString(), 2, '0');
@@ -650,6 +796,8 @@
650
796
  });
651
797
  Object.defineProperty(TuiDay.prototype, "formattedDay", {
652
798
  /**
799
+ * @deprecated use {@link getFormattedDay} instead
800
+ * TODO remove in 3.0
653
801
  * Formatted whole date
654
802
  */
655
803
  get: function () {
@@ -775,8 +923,28 @@
775
923
  }
776
924
  return new TuiDay(years, months, days);
777
925
  };
778
- TuiDay.prototype.toString = function () {
779
- return this.formattedDay;
926
+ /**
927
+ * Returns formatted whole date
928
+ */
929
+ TuiDay.prototype.getFormattedDay = function (dateFormat, separator) {
930
+ classes.tuiAssert.assert(separator.length === 1, 'Separator should consist of only 1 symbol');
931
+ var dd = this.formattedDayPart;
932
+ var mm = this.formattedMonthPart;
933
+ var yyyy = this.formattedYear;
934
+ switch (dateFormat) {
935
+ case 'YMD':
936
+ return "" + yyyy + separator + mm + separator + dd;
937
+ case 'MDY':
938
+ return "" + mm + separator + dd + separator + yyyy;
939
+ case 'DMY':
940
+ default:
941
+ return "" + dd + separator + mm + separator + yyyy;
942
+ }
943
+ };
944
+ TuiDay.prototype.toString = function (dateFormat, separator) {
945
+ if (dateFormat === void 0) { dateFormat = 'DMY'; }
946
+ if (separator === void 0) { separator = '.'; }
947
+ return this.getFormattedDay(dateFormat, separator);
780
948
  };
781
949
  TuiDay.prototype.toJSON = function () {
782
950
  return _super.prototype.toJSON.call(this) + "-" + this.formattedDayPart;
@@ -793,125 +961,6 @@
793
961
  TuiDay.prototype.toUtcNativeDate = function () {
794
962
  return new Date(Date.UTC(this.year, this.month, this.day));
795
963
  };
796
- /**
797
- * Creates {@link TuiDay} from native {@link Date} based on local time zone
798
- */
799
- TuiDay.fromLocalNativeDate = function (date) {
800
- return new TuiDay(date.getFullYear(), date.getMonth(), date.getDate());
801
- };
802
- /**
803
- * Creates {@link TuiDay} from native {@link Date} using UTC
804
- */
805
- TuiDay.fromUtcNativeDate = function (date) {
806
- return new TuiDay(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
807
- };
808
- /**
809
- * Check validity of year, month and day
810
- *
811
- * @param year
812
- * @param month
813
- * @param day
814
- * @return boolean validity
815
- */
816
- TuiDay.isValidDay = function (year, month, day) {
817
- return (TuiMonth.isValidMonth(year, month) &&
818
- Number.isInteger(day) &&
819
- math.inRange(day, MIN_DAY, TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year)) + 1));
820
- };
821
- /**
822
- * @deprecated DONT USE IT (will be deleted soon)
823
- *
824
- * Calculated day on a calendar grid
825
- *
826
- * @param month
827
- * @param row row in a calendar
828
- * @param col column in a calendar
829
- * @return resulting day on these coordinates (could exceed passed month)
830
- */
831
- TuiDay.getDayFromMonthRowCol = function (month, row, col) {
832
- classes.tuiAssert.assert(Number.isInteger(row));
833
- classes.tuiAssert.assert(math.inRange(row, 0, 6));
834
- classes.tuiAssert.assert(Number.isInteger(col));
835
- classes.tuiAssert.assert(math.inRange(col, 0, DAYS_IN_WEEK));
836
- var day = row * DAYS_IN_WEEK + col - month.monthStartDaysOffset + 1;
837
- if (day > month.daysCount) {
838
- day = day - month.daysCount;
839
- month = month.append({ month: 1 });
840
- }
841
- if (day <= 0) {
842
- month = month.append({ month: -1 });
843
- day = month.daysCount + day;
844
- }
845
- return new TuiDay(month.year, month.month, day);
846
- };
847
- /**
848
- * Current day based on local time zone
849
- */
850
- TuiDay.currentLocal = function () {
851
- var nativeDate = new Date();
852
- var year = nativeDate.getFullYear();
853
- var month = nativeDate.getMonth();
854
- var day = nativeDate.getDate();
855
- return new TuiDay(year, month, day);
856
- };
857
- /**
858
- * Calculates {@link TuiDay} normalizing year, month and day. {@link NaN} is turned into minimal value.
859
- *
860
- * @param year any year value, including invalid
861
- * @param month any month value, including invalid (months start with 0)
862
- * @param day any day value, including invalid
863
- * @return normalized date
864
- */
865
- TuiDay.normalizeOf = function (year, month, day) {
866
- var normalizedYear = TuiYear.normalizeYearPart(year);
867
- var normalizedMonth = TuiMonth.normalizeMonthPart(month);
868
- var normalizedDay = TuiDay.normalizeDayPart(day, normalizedMonth, normalizedYear);
869
- return new TuiDay(normalizedYear, normalizedMonth, normalizedDay);
870
- };
871
- TuiDay.lengthBetween = function (from, to) {
872
- return Math.round((to.toLocalNativeDate().getTime() - from.toLocalNativeDate().getTime()) /
873
- (1000 * 60 * 60 * 24));
874
- };
875
- // TODO: Move month and year related code corresponding classes
876
- /**
877
- * Parsing a string with date with normalization
878
- *
879
- * @param yearMonthDayString date string in format of DD.MM.Yyyy
880
- * @return normalized date
881
- */
882
- TuiDay.normalizeParse = function (yearMonthDayString) {
883
- var day = parseInt(yearMonthDayString.slice(0, 2), 10);
884
- var month = parseInt(yearMonthDayString.slice(3, 5), 10) - 1;
885
- var year = parseInt(yearMonthDayString.slice(6, 10), 10);
886
- return TuiDay.normalizeOf(year, month, day);
887
- };
888
- /**
889
- * Parsing a date stringified in a toJSON format
890
- * @param yearMonthDayString date string in format of YYYY-MM-DD
891
- * @return date
892
- * @throws exceptions if any part of the date is invalid
893
- */
894
- TuiDay.jsonParse = function (yearMonthDayString) {
895
- var day = parseInt(yearMonthDayString.slice(8, 10), 10);
896
- var month = parseInt(yearMonthDayString.slice(5, 7), 10) - 1;
897
- var year = parseInt(yearMonthDayString.slice(0, 4), 10);
898
- if (!TuiYear.isValidYear(year)) {
899
- throw new Error('Invalid year: ' + year);
900
- }
901
- if (!TuiMonth.isValidMonth(year, month)) {
902
- throw new Error('Invalid month: ' + month);
903
- }
904
- if (!Number.isInteger(day) ||
905
- !math.inRange(day, MIN_DAY, TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year)) + 1)) {
906
- throw new Error('Invalid day: ' + day);
907
- }
908
- return new TuiDay(year, month, day);
909
- };
910
- TuiDay.normalizeDayPart = function (day, month, year) {
911
- classes.tuiAssert.assert(TuiMonth.isValidMonth(year, month));
912
- var monthDaysCount = TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year));
913
- return math.normalizeToIntNumber(day, 1, monthDaysCount);
914
- };
915
964
  return TuiDay;
916
965
  }(TuiMonth));
917
966
 
@@ -924,6 +973,11 @@
924
973
  this.to = to;
925
974
  classes.tuiAssert.assert(from.monthSameOrBefore(to));
926
975
  }
976
+ TuiMonthRange.sort = function (month1, month2) {
977
+ return month1.monthSameOrBefore(month2)
978
+ ? new TuiMonthRange(month1, month2)
979
+ : new TuiMonthRange(month2, month1);
980
+ };
927
981
  Object.defineProperty(TuiMonthRange.prototype, "isSingleMonth", {
928
982
  get: function () {
929
983
  return this.from.monthSame(this.to);
@@ -944,14 +998,16 @@
944
998
  TuiMonthRange.prototype.toString = function () {
945
999
  return "" + this.from + RANGE_SEPARATOR_CHAR + this.to;
946
1000
  };
947
- TuiMonthRange.sort = function (month1, month2) {
948
- return month1.monthSameOrBefore(month2)
949
- ? new TuiMonthRange(month1, month2)
950
- : new TuiMonthRange(month2, month1);
951
- };
952
1001
  return TuiMonthRange;
953
1002
  }());
954
1003
 
1004
+ /**
1005
+ * Temporary type guard to satisfy ts-overloading of normalizeParse method
1006
+ * @deprecated TODO rm in v3.0
1007
+ */
1008
+ var isDateMode = function (dateMode) {
1009
+ return ['DMY', 'YMD', 'MDY'].includes(dateMode);
1010
+ };
955
1011
  /**
956
1012
  * An immutable range of two {@link TuiDay} objects
957
1013
  */
@@ -964,6 +1020,34 @@
964
1020
  classes.tuiAssert.assert(from.daySameOrBefore(to));
965
1021
  return _this;
966
1022
  }
1023
+ /**
1024
+ * Creates range from two days after sorting them
1025
+ *
1026
+ * @param day1
1027
+ * @param day2
1028
+ * @return new range with sorted days
1029
+ */
1030
+ TuiDayRange.sort = function (day1, day2) {
1031
+ return day1.daySameOrBefore(day2)
1032
+ ? new TuiDayRange(day1, day2)
1033
+ : new TuiDayRange(day2, day1);
1034
+ };
1035
+ /**
1036
+ * Parse and correct a day range in string format
1037
+ *
1038
+ * @param rangeString a string of dates in a format dd.mm.yyyy - dd.mm.yyyy
1039
+ * @param dateMode {@link TuiDateMode}
1040
+ * @return normalized day range object
1041
+ */
1042
+ TuiDayRange.normalizeParse = function (rangeString, dateMode) {
1043
+ if (dateMode === void 0) { dateMode = 'DMY'; }
1044
+ var dateFormat = isDateMode(dateMode) ? dateMode : 'DMY';
1045
+ var leftDay = TuiDay.normalizeParse(rangeString.slice(0, DATE_FILLER_LENGTH), dateFormat);
1046
+ if (rangeString.length < DATE_RANGE_FILLER_LENGTH) {
1047
+ return new TuiDayRange(leftDay, leftDay);
1048
+ }
1049
+ return TuiDayRange.sort(leftDay, TuiDay.normalizeParse(rangeString.slice(DATE_FILLER_LENGTH + RANGE_SEPARATOR_CHAR.length), dateFormat));
1050
+ };
967
1051
  Object.defineProperty(TuiDayRange.prototype, "isSingleDay", {
968
1052
  get: function () {
969
1053
  return this.from.daySame(this.to);
@@ -974,9 +1058,12 @@
974
1058
  Object.defineProperty(TuiDayRange.prototype, "formattedDayRange", {
975
1059
  /**
976
1060
  * Human readable format.
1061
+ * @deprecated use {@link getFormattedDayRange} instead
977
1062
  */
978
1063
  get: function () {
979
- return "" + this.from.formattedDay + RANGE_SEPARATOR_CHAR + this.to.formattedDay;
1064
+ var from = this.from.getFormattedDay('DMY', '.');
1065
+ var to = this.to.getFormattedDay('DMY', '.');
1066
+ return "" + from + RANGE_SEPARATOR_CHAR + to;
980
1067
  },
981
1068
  enumerable: true,
982
1069
  configurable: true
@@ -1001,29 +1088,19 @@
1001
1088
  return new TuiDayRange(this.from.dayLimit(min, max), this.to.dayLimit(min, max));
1002
1089
  };
1003
1090
  /**
1004
- * Creates range from two days after sorting them
1005
- *
1006
- * @param day1
1007
- * @param day2
1008
- * @return new range with sorted days
1009
- */
1010
- TuiDayRange.sort = function (day1, day2) {
1011
- return day1.daySameOrBefore(day2)
1012
- ? new TuiDayRange(day1, day2)
1013
- : new TuiDayRange(day2, day1);
1014
- };
1015
- /**
1016
- * Parse and correct a day range in string format
1017
- *
1018
- * @param rangeString a string of dates in a format dd.mm.yyyy - dd.mm.yyyy
1019
- * @return normalized day range object
1091
+ * Human readable format.
1020
1092
  */
1021
- TuiDayRange.normalizeParse = function (rangeString) {
1022
- var leftDay = TuiDay.normalizeParse(rangeString.slice(0, DATE_FILLER_LENGTH));
1023
- if (rangeString.length < DATE_RANGE_FILLER_LENGTH) {
1024
- return new TuiDayRange(leftDay, leftDay);
1025
- }
1026
- return TuiDayRange.sort(leftDay, TuiDay.normalizeParse(rangeString.slice(DATE_FILLER_LENGTH + RANGE_SEPARATOR_CHAR.length)));
1093
+ TuiDayRange.prototype.getFormattedDayRange = function (dateFormat, dateSeparator) {
1094
+ var from = this.from.getFormattedDay(dateFormat, dateSeparator);
1095
+ var to = this.to.getFormattedDay(dateFormat, dateSeparator);
1096
+ return "" + from + RANGE_SEPARATOR_CHAR + to;
1097
+ };
1098
+ TuiDayRange.prototype.toString = function (dateFormat, dateSeparator) {
1099
+ if (dateFormat === void 0) { dateFormat = 'DMY'; }
1100
+ if (dateSeparator === void 0) { dateSeparator = '.'; }
1101
+ var from = this.from.getFormattedDay(dateFormat, dateSeparator);
1102
+ var to = this.to.getFormattedDay(dateFormat, dateSeparator);
1103
+ return "" + from + RANGE_SEPARATOR_CHAR + to;
1027
1104
  };
1028
1105
  return TuiDayRange;
1029
1106
  }(TuiMonthRange));
@@ -1044,46 +1121,6 @@
1044
1121
  this.ms = ms;
1045
1122
  classes.tuiAssert.assert(TuiTime.isValidTime(hours, minutes, seconds, ms), 'Time must be real, but got:', hours, minutes, seconds, ms);
1046
1123
  }
1047
- /**
1048
- * Shifts time by hours and minutes
1049
- */
1050
- TuiTime.prototype.shift = function (_a) {
1051
- var _b = _a.hours, hours = _b === void 0 ? 0 : _b, _c = _a.minutes, minutes = _c === void 0 ? 0 : _c, _d = _a.seconds, seconds = _d === void 0 ? 0 : _d, _e = _a.ms, ms = _e === void 0 ? 0 : _e;
1052
- var newMs = (1000 + this.ms + (ms % 1000)) % 1000;
1053
- var secondsInMs = ms < 0 ? Math.ceil(ms / 1000) : Math.floor(ms / 1000);
1054
- var secondsToAdd = secondsInMs + seconds;
1055
- var newSeconds = (60 + this.seconds + (secondsToAdd % 60)) % 60;
1056
- var minutesInSeconds = secondsToAdd < 0
1057
- ? Math.ceil(secondsToAdd / 60)
1058
- : Math.floor(secondsToAdd / 60);
1059
- var minutesToAdd = minutesInSeconds + minutes;
1060
- var newMinutes = (60 + this.minutes + (minutesToAdd % 60)) % 60;
1061
- var hoursInMinutes = minutesToAdd < 0
1062
- ? Math.ceil(minutesToAdd / 60)
1063
- : Math.floor(minutesToAdd / 60);
1064
- var hoursToAdd = hoursInMinutes + hours;
1065
- var newHours = (24 + this.hours + (hoursToAdd % 24)) % 24;
1066
- return new TuiTime(newHours, newMinutes, newSeconds, newMs);
1067
- };
1068
- /**
1069
- * Converts TuiTime to string
1070
- */
1071
- TuiTime.prototype.toString = function (mode) {
1072
- var needAddMs = mode === 'HH:MM:SS.MSS' || (!mode && this.ms > 0);
1073
- var needAddSeconds = needAddMs || mode === 'HH:MM:SS' || (!mode && this.seconds > 0);
1074
- return (this.formatTime(this.hours) + ":" + this.formatTime(this.minutes) +
1075
- ("" + (needAddSeconds ? ':' + this.formatTime(this.seconds) : '')) +
1076
- ("" + (needAddMs ? '.' + this.formatTime(this.ms, 3) : '')));
1077
- };
1078
- /**
1079
- * Converts TuiTime to milliseconds
1080
- */
1081
- TuiTime.prototype.toAbsoluteMilliseconds = function () {
1082
- return (this.hours * MILLISECONDS_IN_HOUR +
1083
- this.minutes * MILLISECONDS_IN_MINUTE +
1084
- this.seconds * 1000 +
1085
- this.ms);
1086
- };
1087
1124
  /**
1088
1125
  * Checks if time is valid
1089
1126
  */
@@ -1142,6 +1179,46 @@
1142
1179
  TuiTime.fromLocalNativeDate = function (date) {
1143
1180
  return new TuiTime(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
1144
1181
  };
1182
+ /**
1183
+ * Shifts time by hours and minutes
1184
+ */
1185
+ TuiTime.prototype.shift = function (_a) {
1186
+ var _b = _a.hours, hours = _b === void 0 ? 0 : _b, _c = _a.minutes, minutes = _c === void 0 ? 0 : _c, _d = _a.seconds, seconds = _d === void 0 ? 0 : _d, _e = _a.ms, ms = _e === void 0 ? 0 : _e;
1187
+ var newMs = (1000 + this.ms + (ms % 1000)) % 1000;
1188
+ var secondsInMs = ms < 0 ? Math.ceil(ms / 1000) : Math.floor(ms / 1000);
1189
+ var secondsToAdd = secondsInMs + seconds;
1190
+ var newSeconds = (60 + this.seconds + (secondsToAdd % 60)) % 60;
1191
+ var minutesInSeconds = secondsToAdd < 0
1192
+ ? Math.ceil(secondsToAdd / 60)
1193
+ : Math.floor(secondsToAdd / 60);
1194
+ var minutesToAdd = minutesInSeconds + minutes;
1195
+ var newMinutes = (60 + this.minutes + (minutesToAdd % 60)) % 60;
1196
+ var hoursInMinutes = minutesToAdd < 0
1197
+ ? Math.ceil(minutesToAdd / 60)
1198
+ : Math.floor(minutesToAdd / 60);
1199
+ var hoursToAdd = hoursInMinutes + hours;
1200
+ var newHours = (24 + this.hours + (hoursToAdd % 24)) % 24;
1201
+ return new TuiTime(newHours, newMinutes, newSeconds, newMs);
1202
+ };
1203
+ /**
1204
+ * Converts TuiTime to string
1205
+ */
1206
+ TuiTime.prototype.toString = function (mode) {
1207
+ var needAddMs = mode === 'HH:MM:SS.MSS' || (!mode && this.ms > 0);
1208
+ var needAddSeconds = needAddMs || mode === 'HH:MM:SS' || (!mode && this.seconds > 0);
1209
+ return (this.formatTime(this.hours) + ":" + this.formatTime(this.minutes) +
1210
+ ("" + (needAddSeconds ? ':' + this.formatTime(this.seconds) : '')) +
1211
+ ("" + (needAddMs ? '.' + this.formatTime(this.ms, 3) : '')));
1212
+ };
1213
+ /**
1214
+ * Converts TuiTime to milliseconds
1215
+ */
1216
+ TuiTime.prototype.toAbsoluteMilliseconds = function () {
1217
+ return (this.hours * MILLISECONDS_IN_HOUR +
1218
+ this.minutes * MILLISECONDS_IN_MINUTE +
1219
+ this.seconds * 1000 +
1220
+ this.ms);
1221
+ };
1145
1222
  TuiTime.prototype.formatTime = function (time, digits) {
1146
1223
  if (digits === void 0) { digits = 2; }
1147
1224
  return format.padStart(time.toString(), digits, '0');
@@ -1171,6 +1248,7 @@
1171
1248
  exports.TUI_DATE_FILLER = TUI_DATE_FILLER;
1172
1249
  exports.TUI_DATE_FORMAT = TUI_DATE_FORMAT;
1173
1250
  exports.TUI_DATE_RANGE_FILLER = TUI_DATE_RANGE_FILLER;
1251
+ exports.TUI_DATE_SEPARATOR = TUI_DATE_SEPARATOR;
1174
1252
  exports.TUI_FIRST_DAY = TUI_FIRST_DAY;
1175
1253
  exports.TUI_LAST_DAY = TUI_LAST_DAY;
1176
1254
  exports.TuiDay = TuiDay;
@@ -1179,6 +1257,7 @@
1179
1257
  exports.TuiMonthRange = TuiMonthRange;
1180
1258
  exports.TuiTime = TuiTime;
1181
1259
  exports.TuiYear = TuiYear;
1260
+ exports.isDateMode = isDateMode;
1182
1261
 
1183
1262
  Object.defineProperty(exports, '__esModule', { value: true });
1184
1263