@taiga-ui/cdk 2.26.0 → 2.27.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.
- package/abstract/control.d.ts +1 -1
- package/abstract/interactive.d.ts +4 -4
- package/abstract/taiga-ui-cdk-abstract.metadata.json +1 -1
- package/bundles/taiga-ui-cdk-abstract.umd.js +3 -3
- package/bundles/taiga-ui-cdk-abstract.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-abstract.umd.min.js +1 -1
- package/bundles/taiga-ui-cdk-abstract.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-date-time.umd.js +331 -331
- package/bundles/taiga-ui-cdk-date-time.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-date-time.umd.min.js +1 -1
- package/bundles/taiga-ui-cdk-date-time.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-directives-copy-processor.umd.js +276 -0
- package/bundles/taiga-ui-cdk-directives-copy-processor.umd.js.map +1 -0
- package/bundles/taiga-ui-cdk-directives-copy-processor.umd.min.js +16 -0
- package/bundles/taiga-ui-cdk-directives-copy-processor.umd.min.js.map +1 -0
- package/bundles/taiga-ui-cdk-directives-for.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-directives-for.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-directives-media.umd.js +1 -1
- package/bundles/taiga-ui-cdk-directives-media.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-directives-media.umd.min.js +1 -1
- package/bundles/taiga-ui-cdk-directives-media.umd.min.js.map +1 -1
- package/bundles/taiga-ui-cdk-services.umd.js +2 -2
- package/bundles/taiga-ui-cdk-services.umd.js.map +1 -1
- package/bundles/taiga-ui-cdk-services.umd.min.js +1 -1
- package/bundles/taiga-ui-cdk-services.umd.min.js.map +1 -1
- package/date-time/day-range.d.ts +14 -14
- package/date-time/day.d.ts +57 -57
- package/date-time/month-range.d.ts +1 -1
- package/date-time/month.d.ts +26 -26
- package/date-time/taiga-ui-cdk-date-time.metadata.json +1 -1
- package/date-time/time.d.ts +12 -12
- package/date-time/year.d.ts +27 -27
- package/directives/copy-processor/copy-processor.directive.d.ts +7 -0
- package/directives/copy-processor/copy-processor.module.d.ts +2 -0
- package/directives/copy-processor/index.d.ts +2 -0
- package/directives/copy-processor/package.json +13 -0
- package/directives/copy-processor/taiga-ui-cdk-directives-copy-processor.d.ts +4 -0
- package/directives/copy-processor/taiga-ui-cdk-directives-copy-processor.metadata.json +1 -0
- package/directives/for/for.directive.d.ts +1 -1
- package/directives/for/taiga-ui-cdk-directives-for.metadata.json +1 -1
- package/directives/media/media.directive.d.ts +1 -1
- package/directives/media/taiga-ui-cdk-directives-media.metadata.json +1 -1
- package/esm2015/abstract/control.js +1 -1
- package/esm2015/abstract/interactive.js +4 -4
- package/esm2015/date-time/day-range.js +26 -26
- package/esm2015/date-time/day.js +120 -120
- package/esm2015/date-time/month-range.js +6 -6
- package/esm2015/date-time/month.js +56 -56
- package/esm2015/date-time/time.js +40 -40
- package/esm2015/date-time/year.js +49 -49
- package/esm2015/directives/copy-processor/copy-processor.directive.js +37 -0
- package/esm2015/directives/copy-processor/copy-processor.module.js +13 -0
- package/esm2015/directives/copy-processor/index.js +3 -0
- package/esm2015/directives/copy-processor/taiga-ui-cdk-directives-copy-processor.js +5 -0
- package/esm2015/directives/for/for.directive.js +1 -1
- package/esm2015/directives/media/media.directive.js +2 -2
- package/esm2015/services/pan.service.js +3 -3
- package/esm5/abstract/control.js +1 -1
- package/esm5/abstract/interactive.js +4 -4
- package/esm5/date-time/day-range.js +26 -26
- package/esm5/date-time/day.js +120 -120
- package/esm5/date-time/month-range.js +6 -6
- package/esm5/date-time/month.js +56 -56
- package/esm5/date-time/time.js +41 -41
- package/esm5/date-time/year.js +49 -49
- package/esm5/directives/copy-processor/copy-processor.directive.js +38 -0
- package/esm5/directives/copy-processor/copy-processor.module.js +16 -0
- package/esm5/directives/copy-processor/index.js +3 -0
- package/esm5/directives/copy-processor/taiga-ui-cdk-directives-copy-processor.js +5 -0
- package/esm5/directives/for/for.directive.js +1 -1
- package/esm5/directives/media/media.directive.js +2 -2
- package/esm5/services/pan.service.js +3 -3
- package/fesm2015/taiga-ui-cdk-abstract.js +3 -3
- package/fesm2015/taiga-ui-cdk-abstract.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-date-time.js +322 -322
- package/fesm2015/taiga-ui-cdk-date-time.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-directives-copy-processor.js +52 -0
- package/fesm2015/taiga-ui-cdk-directives-copy-processor.js.map +1 -0
- package/fesm2015/taiga-ui-cdk-directives-for.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-directives-media.js +1 -1
- package/fesm2015/taiga-ui-cdk-directives-media.js.map +1 -1
- package/fesm2015/taiga-ui-cdk-services.js +2 -2
- package/fesm2015/taiga-ui-cdk-services.js.map +1 -1
- package/fesm5/taiga-ui-cdk-abstract.js +3 -3
- package/fesm5/taiga-ui-cdk-abstract.js.map +1 -1
- package/fesm5/taiga-ui-cdk-date-time.js +331 -331
- package/fesm5/taiga-ui-cdk-date-time.js.map +1 -1
- package/fesm5/taiga-ui-cdk-directives-copy-processor.js +56 -0
- package/fesm5/taiga-ui-cdk-directives-copy-processor.js.map +1 -0
- package/fesm5/taiga-ui-cdk-directives-for.js.map +1 -1
- package/fesm5/taiga-ui-cdk-directives-media.js +1 -1
- package/fesm5/taiga-ui-cdk-directives-media.js.map +1 -1
- package/fesm5/taiga-ui-cdk-services.js +2 -2
- package/fesm5/taiga-ui-cdk-services.js.map +1 -1
- package/package.json +2 -2
|
@@ -288,6 +288,54 @@
|
|
|
288
288
|
this.year = year;
|
|
289
289
|
classes.tuiAssert.assert(TuiYear.isValidYear(year));
|
|
290
290
|
}
|
|
291
|
+
/**
|
|
292
|
+
* Checks year for validity
|
|
293
|
+
*/
|
|
294
|
+
TuiYear.isValidYear = function (year) {
|
|
295
|
+
return Number.isInteger(year) && math.inRange(year, MIN_YEAR, MAX_YEAR + 1);
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Check if passed year is a leap year
|
|
299
|
+
*/
|
|
300
|
+
TuiYear.isLeapYear = function (year) {
|
|
301
|
+
classes.tuiAssert.assert(TuiYear.isValidYear(year));
|
|
302
|
+
return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Returns amount of leap years from year 0 to the passed one
|
|
306
|
+
*/
|
|
307
|
+
TuiYear.getAbsoluteLeapYears = function (year) {
|
|
308
|
+
classes.tuiAssert.assert(TuiYear.isValidYear(year));
|
|
309
|
+
return Math.ceil(year / 400) + (Math.ceil(year / 4) - Math.ceil(year / 100));
|
|
310
|
+
};
|
|
311
|
+
/**
|
|
312
|
+
* @deprecated DONT USE IT (will be deleted soon)
|
|
313
|
+
*
|
|
314
|
+
* Returns day of week offset of the beginning of the passed year
|
|
315
|
+
*
|
|
316
|
+
* @param year
|
|
317
|
+
* @param absoluteLeapYears amount of leap years prior to the passed one
|
|
318
|
+
* @return offset in days
|
|
319
|
+
*/
|
|
320
|
+
TuiYear.getYearStartDaysOffset = function (year, absoluteLeapYears) {
|
|
321
|
+
classes.tuiAssert.assert(TuiYear.isValidYear(year));
|
|
322
|
+
classes.tuiAssert.assert(Number.isInteger(absoluteLeapYears));
|
|
323
|
+
classes.tuiAssert.assert(year >= absoluteLeapYears);
|
|
324
|
+
classes.tuiAssert.assert(absoluteLeapYears >= 0);
|
|
325
|
+
return ((absoluteLeapYears * DAYS_IN_LEAP_YEAR +
|
|
326
|
+
(year - absoluteLeapYears) * DAYS_IN_NORMAL_YEAR +
|
|
327
|
+
5) %
|
|
328
|
+
DAYS_IN_WEEK);
|
|
329
|
+
};
|
|
330
|
+
TuiYear.lengthBetween = function (from, to) {
|
|
331
|
+
return to.year - from.year;
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Normalizes year by clamping it between min and max years
|
|
335
|
+
*/
|
|
336
|
+
TuiYear.normalizeYearPart = function (year) {
|
|
337
|
+
return math.normalizeToIntNumber(year, MIN_YEAR, MAX_YEAR);
|
|
338
|
+
};
|
|
291
339
|
Object.defineProperty(TuiYear.prototype, "formattedYear", {
|
|
292
340
|
get: function () {
|
|
293
341
|
return format.padStart(this.year.toString(), 4, '0');
|
|
@@ -380,54 +428,6 @@
|
|
|
380
428
|
TuiYear.prototype.toJSON = function () {
|
|
381
429
|
return this.formattedYear;
|
|
382
430
|
};
|
|
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
431
|
return TuiYear;
|
|
432
432
|
}());
|
|
433
433
|
|
|
@@ -446,6 +446,61 @@
|
|
|
446
446
|
classes.tuiAssert.assert(TuiMonth.isValidMonth(year, month));
|
|
447
447
|
return _this;
|
|
448
448
|
}
|
|
449
|
+
/**
|
|
450
|
+
* Tests month and year for validity
|
|
451
|
+
*/
|
|
452
|
+
TuiMonth.isValidMonth = function (year, month) {
|
|
453
|
+
return TuiYear.isValidYear(year) && TuiMonth.isValidMonthPart(month);
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Returns number of days in a month
|
|
457
|
+
*/
|
|
458
|
+
TuiMonth.getMonthDaysCount = function (month, isLeapYear) {
|
|
459
|
+
classes.tuiAssert.assert(TuiMonth.isValidMonthPart(month));
|
|
460
|
+
switch (month) {
|
|
461
|
+
case 1 /* February */:
|
|
462
|
+
return isLeapYear ? 29 : 28;
|
|
463
|
+
case 3 /* April */:
|
|
464
|
+
case 5 /* June */:
|
|
465
|
+
case 8 /* September */:
|
|
466
|
+
case 10 /* November */:
|
|
467
|
+
return 30;
|
|
468
|
+
default:
|
|
469
|
+
return 31;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
/**
|
|
473
|
+
* Returns current month and year based on local time zone
|
|
474
|
+
* @nosideeffects
|
|
475
|
+
*/
|
|
476
|
+
TuiMonth.currentLocal = function () {
|
|
477
|
+
var nativeDate = new Date();
|
|
478
|
+
return new TuiMonth(nativeDate.getFullYear(), nativeDate.getMonth());
|
|
479
|
+
};
|
|
480
|
+
/**
|
|
481
|
+
* Returns current month and year based on UTC
|
|
482
|
+
*/
|
|
483
|
+
TuiMonth.currentUtc = function () {
|
|
484
|
+
var nativeDate = new Date();
|
|
485
|
+
return new TuiMonth(nativeDate.getUTCFullYear(), nativeDate.getUTCMonth());
|
|
486
|
+
};
|
|
487
|
+
TuiMonth.lengthBetween = function (from, to) {
|
|
488
|
+
var absoluteFrom = from.month + from.year * 12;
|
|
489
|
+
var absoluteTo = to.month + to.year * 12;
|
|
490
|
+
return absoluteTo - absoluteFrom;
|
|
491
|
+
};
|
|
492
|
+
/**
|
|
493
|
+
* Normalizes number by clamping it between min and max month
|
|
494
|
+
*/
|
|
495
|
+
TuiMonth.normalizeMonthPart = function (month) {
|
|
496
|
+
return math.normalizeToIntNumber(month, MIN_MONTH, MAX_MONTH);
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* Tests month for validity
|
|
500
|
+
*/
|
|
501
|
+
TuiMonth.isValidMonthPart = function (month) {
|
|
502
|
+
return Number.isInteger(month) && math.inRange(month, MIN_MONTH, MAX_MONTH + 1);
|
|
503
|
+
};
|
|
449
504
|
Object.defineProperty(TuiMonth.prototype, "formattedMonthPart", {
|
|
450
505
|
get: function () {
|
|
451
506
|
return format.padStart((this.month + 1).toString(), 2, '0');
|
|
@@ -571,61 +626,6 @@
|
|
|
571
626
|
TuiMonth.prototype.toUtcNativeDate = function () {
|
|
572
627
|
return new Date(Date.UTC(this.year, this.month));
|
|
573
628
|
};
|
|
574
|
-
/**
|
|
575
|
-
* Tests month and year for validity
|
|
576
|
-
*/
|
|
577
|
-
TuiMonth.isValidMonth = function (year, month) {
|
|
578
|
-
return TuiYear.isValidYear(year) && TuiMonth.isValidMonthPart(month);
|
|
579
|
-
};
|
|
580
|
-
/**
|
|
581
|
-
* Returns number of days in a month
|
|
582
|
-
*/
|
|
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;
|
|
595
|
-
}
|
|
596
|
-
};
|
|
597
|
-
/**
|
|
598
|
-
* Returns current month and year based on local time zone
|
|
599
|
-
* @nosideeffects
|
|
600
|
-
*/
|
|
601
|
-
TuiMonth.currentLocal = function () {
|
|
602
|
-
var nativeDate = new Date();
|
|
603
|
-
return new TuiMonth(nativeDate.getFullYear(), nativeDate.getMonth());
|
|
604
|
-
};
|
|
605
|
-
/**
|
|
606
|
-
* Returns current month and year based on UTC
|
|
607
|
-
*/
|
|
608
|
-
TuiMonth.currentUtc = function () {
|
|
609
|
-
var nativeDate = new Date();
|
|
610
|
-
return new TuiMonth(nativeDate.getUTCFullYear(), nativeDate.getUTCMonth());
|
|
611
|
-
};
|
|
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;
|
|
616
|
-
};
|
|
617
|
-
/**
|
|
618
|
-
* Normalizes number by clamping it between min and max month
|
|
619
|
-
*/
|
|
620
|
-
TuiMonth.normalizeMonthPart = function (month) {
|
|
621
|
-
return math.normalizeToIntNumber(month, MIN_MONTH, MAX_MONTH);
|
|
622
|
-
};
|
|
623
|
-
/**
|
|
624
|
-
* Tests month for validity
|
|
625
|
-
*/
|
|
626
|
-
TuiMonth.isValidMonthPart = function (month) {
|
|
627
|
-
return Number.isInteger(month) && math.inRange(month, MIN_MONTH, MAX_MONTH + 1);
|
|
628
|
-
};
|
|
629
629
|
return TuiMonth;
|
|
630
630
|
}(TuiYear));
|
|
631
631
|
|
|
@@ -641,169 +641,17 @@
|
|
|
641
641
|
classes.tuiAssert.assert(TuiDay.isValidDay(year, month, day));
|
|
642
642
|
return _this;
|
|
643
643
|
}
|
|
644
|
-
Object.defineProperty(TuiDay.prototype, "formattedDayPart", {
|
|
645
|
-
get: function () {
|
|
646
|
-
return format.padStart(this.day.toString(), 2, '0');
|
|
647
|
-
},
|
|
648
|
-
enumerable: true,
|
|
649
|
-
configurable: true
|
|
650
|
-
});
|
|
651
|
-
Object.defineProperty(TuiDay.prototype, "formattedDay", {
|
|
652
|
-
/**
|
|
653
|
-
* Formatted whole date
|
|
654
|
-
*/
|
|
655
|
-
get: function () {
|
|
656
|
-
return this.formattedDayPart + "." + this.formattedMonth;
|
|
657
|
-
},
|
|
658
|
-
enumerable: true,
|
|
659
|
-
configurable: true
|
|
660
|
-
});
|
|
661
|
-
Object.defineProperty(TuiDay.prototype, "isWeekend", {
|
|
662
|
-
get: function () {
|
|
663
|
-
var dayOfWeek = this.dayOfWeek(false);
|
|
664
|
-
return dayOfWeek === 6 /* Saturday */ || dayOfWeek === 0 /* Sunday */;
|
|
665
|
-
},
|
|
666
|
-
enumerable: true,
|
|
667
|
-
configurable: true
|
|
668
|
-
});
|
|
669
644
|
/**
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
* @param startFromMonday whether week starts from Monday and not from Sunday
|
|
673
|
-
* @return day of week (from 0 to 6)
|
|
645
|
+
* Creates {@link TuiDay} from native {@link Date} based on local time zone
|
|
674
646
|
*/
|
|
675
|
-
TuiDay.
|
|
676
|
-
|
|
677
|
-
var dayOfWeek = startFromMonday
|
|
678
|
-
? this.toLocalNativeDate().getDay() - 1
|
|
679
|
-
: this.toLocalNativeDate().getDay();
|
|
680
|
-
return dayOfWeek < 0 ? 6 : dayOfWeek;
|
|
647
|
+
TuiDay.fromLocalNativeDate = function (date) {
|
|
648
|
+
return new TuiDay(date.getFullYear(), date.getMonth(), date.getDate());
|
|
681
649
|
};
|
|
682
650
|
/**
|
|
683
|
-
*
|
|
651
|
+
* Creates {@link TuiDay} from native {@link Date} using UTC
|
|
684
652
|
*/
|
|
685
|
-
TuiDay.
|
|
686
|
-
return (
|
|
687
|
-
(this.monthSame(another) && this.day < another.day));
|
|
688
|
-
};
|
|
689
|
-
/**
|
|
690
|
-
* Passed date is after or equals to current
|
|
691
|
-
*/
|
|
692
|
-
TuiDay.prototype.daySameOrBefore = function (another) {
|
|
693
|
-
return (this.monthBefore(another) ||
|
|
694
|
-
(this.monthSame(another) && this.day <= another.day));
|
|
695
|
-
};
|
|
696
|
-
/**
|
|
697
|
-
* Passed date is the same as current
|
|
698
|
-
*/
|
|
699
|
-
TuiDay.prototype.daySame = function (another) {
|
|
700
|
-
return this.monthSame(another) && this.day === another.day;
|
|
701
|
-
};
|
|
702
|
-
/**
|
|
703
|
-
* Passed date is either before or the same as current
|
|
704
|
-
*/
|
|
705
|
-
TuiDay.prototype.daySameOrAfter = function (another) {
|
|
706
|
-
return (this.monthAfter(another) ||
|
|
707
|
-
(this.monthSame(another) && this.day >= another.day));
|
|
708
|
-
};
|
|
709
|
-
/**
|
|
710
|
-
* Passed date is before current
|
|
711
|
-
*/
|
|
712
|
-
TuiDay.prototype.dayAfter = function (another) {
|
|
713
|
-
return (this.monthAfter(another) ||
|
|
714
|
-
(this.monthSame(another) && this.day > another.day));
|
|
715
|
-
};
|
|
716
|
-
/**
|
|
717
|
-
* Clamping date between two limits
|
|
718
|
-
*
|
|
719
|
-
* @param min
|
|
720
|
-
* @param max
|
|
721
|
-
* @return clamped date
|
|
722
|
-
*/
|
|
723
|
-
TuiDay.prototype.dayLimit = function (min, max) {
|
|
724
|
-
if (min !== null && this.dayBefore(min)) {
|
|
725
|
-
return min;
|
|
726
|
-
}
|
|
727
|
-
if (max !== null && this.dayAfter(max)) {
|
|
728
|
-
return max;
|
|
729
|
-
}
|
|
730
|
-
return this;
|
|
731
|
-
};
|
|
732
|
-
// TODO: Consider removing `backwards` option
|
|
733
|
-
/**
|
|
734
|
-
* Immutably alters current day by passed offset
|
|
735
|
-
*
|
|
736
|
-
* If resulting month has more days than original one, date is rounded to the maximum day
|
|
737
|
-
* in the resulting month. Offset of days will be calculated based on the resulted year and month
|
|
738
|
-
* to not interfere with parent classes methods
|
|
739
|
-
*
|
|
740
|
-
* @param offset
|
|
741
|
-
* @param backwards shift date backwards
|
|
742
|
-
* @return new date object as a result of offsetting current
|
|
743
|
-
*/
|
|
744
|
-
TuiDay.prototype.append = function (_a, backwards) {
|
|
745
|
-
var _b = _a.year, year = _b === void 0 ? 0 : _b, _c = _a.month, month = _c === void 0 ? 0 : _c, _d = _a.day, day = _d === void 0 ? 0 : _d;
|
|
746
|
-
if (backwards === void 0) { backwards = false; }
|
|
747
|
-
if (backwards) {
|
|
748
|
-
year *= -1;
|
|
749
|
-
month *= -1;
|
|
750
|
-
day *= -1;
|
|
751
|
-
}
|
|
752
|
-
var totalMonths = (this.year + year) * MONTHS_IN_YEAR + this.month + month;
|
|
753
|
-
var years = Math.floor(totalMonths / MONTHS_IN_YEAR);
|
|
754
|
-
var months = totalMonths % MONTHS_IN_YEAR;
|
|
755
|
-
var days = Math.min(this.day, TuiMonth.getMonthDaysCount(months, TuiYear.isLeapYear(years))) + day;
|
|
756
|
-
while (days > TuiMonth.getMonthDaysCount(months, TuiYear.isLeapYear(years))) {
|
|
757
|
-
days -= TuiMonth.getMonthDaysCount(months, TuiYear.isLeapYear(years));
|
|
758
|
-
if (months === 11 /* December */) {
|
|
759
|
-
years++;
|
|
760
|
-
months = 0 /* January */;
|
|
761
|
-
}
|
|
762
|
-
else {
|
|
763
|
-
months++;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
while (days < MIN_DAY) {
|
|
767
|
-
if (months === 0 /* January */) {
|
|
768
|
-
years--;
|
|
769
|
-
months = 11 /* December */;
|
|
770
|
-
}
|
|
771
|
-
else {
|
|
772
|
-
months--;
|
|
773
|
-
}
|
|
774
|
-
days += TuiMonth.getMonthDaysCount(months, TuiYear.isLeapYear(years));
|
|
775
|
-
}
|
|
776
|
-
return new TuiDay(years, months, days);
|
|
777
|
-
};
|
|
778
|
-
TuiDay.prototype.toString = function () {
|
|
779
|
-
return this.formattedDay;
|
|
780
|
-
};
|
|
781
|
-
TuiDay.prototype.toJSON = function () {
|
|
782
|
-
return _super.prototype.toJSON.call(this) + "-" + this.formattedDayPart;
|
|
783
|
-
};
|
|
784
|
-
/**
|
|
785
|
-
* Returns native {@link Date} based on local time zone
|
|
786
|
-
*/
|
|
787
|
-
TuiDay.prototype.toLocalNativeDate = function () {
|
|
788
|
-
return new Date(this.year, this.month, this.day);
|
|
789
|
-
};
|
|
790
|
-
/**
|
|
791
|
-
* Returns native {@link Date} based on UTC
|
|
792
|
-
*/
|
|
793
|
-
TuiDay.prototype.toUtcNativeDate = function () {
|
|
794
|
-
return new Date(Date.UTC(this.year, this.month, this.day));
|
|
795
|
-
};
|
|
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());
|
|
653
|
+
TuiDay.fromUtcNativeDate = function (date) {
|
|
654
|
+
return new TuiDay(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate());
|
|
807
655
|
};
|
|
808
656
|
/**
|
|
809
657
|
* Check validity of year, month and day
|
|
@@ -912,6 +760,158 @@
|
|
|
912
760
|
var monthDaysCount = TuiMonth.getMonthDaysCount(month, TuiYear.isLeapYear(year));
|
|
913
761
|
return math.normalizeToIntNumber(day, 1, monthDaysCount);
|
|
914
762
|
};
|
|
763
|
+
Object.defineProperty(TuiDay.prototype, "formattedDayPart", {
|
|
764
|
+
get: function () {
|
|
765
|
+
return format.padStart(this.day.toString(), 2, '0');
|
|
766
|
+
},
|
|
767
|
+
enumerable: true,
|
|
768
|
+
configurable: true
|
|
769
|
+
});
|
|
770
|
+
Object.defineProperty(TuiDay.prototype, "formattedDay", {
|
|
771
|
+
/**
|
|
772
|
+
* Formatted whole date
|
|
773
|
+
*/
|
|
774
|
+
get: function () {
|
|
775
|
+
return this.formattedDayPart + "." + this.formattedMonth;
|
|
776
|
+
},
|
|
777
|
+
enumerable: true,
|
|
778
|
+
configurable: true
|
|
779
|
+
});
|
|
780
|
+
Object.defineProperty(TuiDay.prototype, "isWeekend", {
|
|
781
|
+
get: function () {
|
|
782
|
+
var dayOfWeek = this.dayOfWeek(false);
|
|
783
|
+
return dayOfWeek === 6 /* Saturday */ || dayOfWeek === 0 /* Sunday */;
|
|
784
|
+
},
|
|
785
|
+
enumerable: true,
|
|
786
|
+
configurable: true
|
|
787
|
+
});
|
|
788
|
+
/**
|
|
789
|
+
* Returns day of week
|
|
790
|
+
*
|
|
791
|
+
* @param startFromMonday whether week starts from Monday and not from Sunday
|
|
792
|
+
* @return day of week (from 0 to 6)
|
|
793
|
+
*/
|
|
794
|
+
TuiDay.prototype.dayOfWeek = function (startFromMonday) {
|
|
795
|
+
if (startFromMonday === void 0) { startFromMonday = true; }
|
|
796
|
+
var dayOfWeek = startFromMonday
|
|
797
|
+
? this.toLocalNativeDate().getDay() - 1
|
|
798
|
+
: this.toLocalNativeDate().getDay();
|
|
799
|
+
return dayOfWeek < 0 ? 6 : dayOfWeek;
|
|
800
|
+
};
|
|
801
|
+
/**
|
|
802
|
+
* Passed date is after current
|
|
803
|
+
*/
|
|
804
|
+
TuiDay.prototype.dayBefore = function (another) {
|
|
805
|
+
return (this.monthBefore(another) ||
|
|
806
|
+
(this.monthSame(another) && this.day < another.day));
|
|
807
|
+
};
|
|
808
|
+
/**
|
|
809
|
+
* Passed date is after or equals to current
|
|
810
|
+
*/
|
|
811
|
+
TuiDay.prototype.daySameOrBefore = function (another) {
|
|
812
|
+
return (this.monthBefore(another) ||
|
|
813
|
+
(this.monthSame(another) && this.day <= another.day));
|
|
814
|
+
};
|
|
815
|
+
/**
|
|
816
|
+
* Passed date is the same as current
|
|
817
|
+
*/
|
|
818
|
+
TuiDay.prototype.daySame = function (another) {
|
|
819
|
+
return this.monthSame(another) && this.day === another.day;
|
|
820
|
+
};
|
|
821
|
+
/**
|
|
822
|
+
* Passed date is either before or the same as current
|
|
823
|
+
*/
|
|
824
|
+
TuiDay.prototype.daySameOrAfter = function (another) {
|
|
825
|
+
return (this.monthAfter(another) ||
|
|
826
|
+
(this.monthSame(another) && this.day >= another.day));
|
|
827
|
+
};
|
|
828
|
+
/**
|
|
829
|
+
* Passed date is before current
|
|
830
|
+
*/
|
|
831
|
+
TuiDay.prototype.dayAfter = function (another) {
|
|
832
|
+
return (this.monthAfter(another) ||
|
|
833
|
+
(this.monthSame(another) && this.day > another.day));
|
|
834
|
+
};
|
|
835
|
+
/**
|
|
836
|
+
* Clamping date between two limits
|
|
837
|
+
*
|
|
838
|
+
* @param min
|
|
839
|
+
* @param max
|
|
840
|
+
* @return clamped date
|
|
841
|
+
*/
|
|
842
|
+
TuiDay.prototype.dayLimit = function (min, max) {
|
|
843
|
+
if (min !== null && this.dayBefore(min)) {
|
|
844
|
+
return min;
|
|
845
|
+
}
|
|
846
|
+
if (max !== null && this.dayAfter(max)) {
|
|
847
|
+
return max;
|
|
848
|
+
}
|
|
849
|
+
return this;
|
|
850
|
+
};
|
|
851
|
+
// TODO: Consider removing `backwards` option
|
|
852
|
+
/**
|
|
853
|
+
* Immutably alters current day by passed offset
|
|
854
|
+
*
|
|
855
|
+
* If resulting month has more days than original one, date is rounded to the maximum day
|
|
856
|
+
* in the resulting month. Offset of days will be calculated based on the resulted year and month
|
|
857
|
+
* to not interfere with parent classes methods
|
|
858
|
+
*
|
|
859
|
+
* @param offset
|
|
860
|
+
* @param backwards shift date backwards
|
|
861
|
+
* @return new date object as a result of offsetting current
|
|
862
|
+
*/
|
|
863
|
+
TuiDay.prototype.append = function (_a, backwards) {
|
|
864
|
+
var _b = _a.year, year = _b === void 0 ? 0 : _b, _c = _a.month, month = _c === void 0 ? 0 : _c, _d = _a.day, day = _d === void 0 ? 0 : _d;
|
|
865
|
+
if (backwards === void 0) { backwards = false; }
|
|
866
|
+
if (backwards) {
|
|
867
|
+
year *= -1;
|
|
868
|
+
month *= -1;
|
|
869
|
+
day *= -1;
|
|
870
|
+
}
|
|
871
|
+
var totalMonths = (this.year + year) * MONTHS_IN_YEAR + this.month + month;
|
|
872
|
+
var years = Math.floor(totalMonths / MONTHS_IN_YEAR);
|
|
873
|
+
var months = totalMonths % MONTHS_IN_YEAR;
|
|
874
|
+
var days = Math.min(this.day, TuiMonth.getMonthDaysCount(months, TuiYear.isLeapYear(years))) + day;
|
|
875
|
+
while (days > TuiMonth.getMonthDaysCount(months, TuiYear.isLeapYear(years))) {
|
|
876
|
+
days -= TuiMonth.getMonthDaysCount(months, TuiYear.isLeapYear(years));
|
|
877
|
+
if (months === 11 /* December */) {
|
|
878
|
+
years++;
|
|
879
|
+
months = 0 /* January */;
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
months++;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
while (days < MIN_DAY) {
|
|
886
|
+
if (months === 0 /* January */) {
|
|
887
|
+
years--;
|
|
888
|
+
months = 11 /* December */;
|
|
889
|
+
}
|
|
890
|
+
else {
|
|
891
|
+
months--;
|
|
892
|
+
}
|
|
893
|
+
days += TuiMonth.getMonthDaysCount(months, TuiYear.isLeapYear(years));
|
|
894
|
+
}
|
|
895
|
+
return new TuiDay(years, months, days);
|
|
896
|
+
};
|
|
897
|
+
TuiDay.prototype.toString = function () {
|
|
898
|
+
return this.formattedDay;
|
|
899
|
+
};
|
|
900
|
+
TuiDay.prototype.toJSON = function () {
|
|
901
|
+
return _super.prototype.toJSON.call(this) + "-" + this.formattedDayPart;
|
|
902
|
+
};
|
|
903
|
+
/**
|
|
904
|
+
* Returns native {@link Date} based on local time zone
|
|
905
|
+
*/
|
|
906
|
+
TuiDay.prototype.toLocalNativeDate = function () {
|
|
907
|
+
return new Date(this.year, this.month, this.day);
|
|
908
|
+
};
|
|
909
|
+
/**
|
|
910
|
+
* Returns native {@link Date} based on UTC
|
|
911
|
+
*/
|
|
912
|
+
TuiDay.prototype.toUtcNativeDate = function () {
|
|
913
|
+
return new Date(Date.UTC(this.year, this.month, this.day));
|
|
914
|
+
};
|
|
915
915
|
return TuiDay;
|
|
916
916
|
}(TuiMonth));
|
|
917
917
|
|
|
@@ -924,6 +924,11 @@
|
|
|
924
924
|
this.to = to;
|
|
925
925
|
classes.tuiAssert.assert(from.monthSameOrBefore(to));
|
|
926
926
|
}
|
|
927
|
+
TuiMonthRange.sort = function (month1, month2) {
|
|
928
|
+
return month1.monthSameOrBefore(month2)
|
|
929
|
+
? new TuiMonthRange(month1, month2)
|
|
930
|
+
: new TuiMonthRange(month2, month1);
|
|
931
|
+
};
|
|
927
932
|
Object.defineProperty(TuiMonthRange.prototype, "isSingleMonth", {
|
|
928
933
|
get: function () {
|
|
929
934
|
return this.from.monthSame(this.to);
|
|
@@ -944,11 +949,6 @@
|
|
|
944
949
|
TuiMonthRange.prototype.toString = function () {
|
|
945
950
|
return "" + this.from + RANGE_SEPARATOR_CHAR + this.to;
|
|
946
951
|
};
|
|
947
|
-
TuiMonthRange.sort = function (month1, month2) {
|
|
948
|
-
return month1.monthSameOrBefore(month2)
|
|
949
|
-
? new TuiMonthRange(month1, month2)
|
|
950
|
-
: new TuiMonthRange(month2, month1);
|
|
951
|
-
};
|
|
952
952
|
return TuiMonthRange;
|
|
953
953
|
}());
|
|
954
954
|
|
|
@@ -964,6 +964,31 @@
|
|
|
964
964
|
classes.tuiAssert.assert(from.daySameOrBefore(to));
|
|
965
965
|
return _this;
|
|
966
966
|
}
|
|
967
|
+
/**
|
|
968
|
+
* Creates range from two days after sorting them
|
|
969
|
+
*
|
|
970
|
+
* @param day1
|
|
971
|
+
* @param day2
|
|
972
|
+
* @return new range with sorted days
|
|
973
|
+
*/
|
|
974
|
+
TuiDayRange.sort = function (day1, day2) {
|
|
975
|
+
return day1.daySameOrBefore(day2)
|
|
976
|
+
? new TuiDayRange(day1, day2)
|
|
977
|
+
: new TuiDayRange(day2, day1);
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* Parse and correct a day range in string format
|
|
981
|
+
*
|
|
982
|
+
* @param rangeString a string of dates in a format dd.mm.yyyy - dd.mm.yyyy
|
|
983
|
+
* @return normalized day range object
|
|
984
|
+
*/
|
|
985
|
+
TuiDayRange.normalizeParse = function (rangeString) {
|
|
986
|
+
var leftDay = TuiDay.normalizeParse(rangeString.slice(0, DATE_FILLER_LENGTH));
|
|
987
|
+
if (rangeString.length < DATE_RANGE_FILLER_LENGTH) {
|
|
988
|
+
return new TuiDayRange(leftDay, leftDay);
|
|
989
|
+
}
|
|
990
|
+
return TuiDayRange.sort(leftDay, TuiDay.normalizeParse(rangeString.slice(DATE_FILLER_LENGTH + RANGE_SEPARATOR_CHAR.length)));
|
|
991
|
+
};
|
|
967
992
|
Object.defineProperty(TuiDayRange.prototype, "isSingleDay", {
|
|
968
993
|
get: function () {
|
|
969
994
|
return this.from.daySame(this.to);
|
|
@@ -1000,31 +1025,6 @@
|
|
|
1000
1025
|
TuiDayRange.prototype.dayLimit = function (min, max) {
|
|
1001
1026
|
return new TuiDayRange(this.from.dayLimit(min, max), this.to.dayLimit(min, max));
|
|
1002
1027
|
};
|
|
1003
|
-
/**
|
|
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
|
|
1020
|
-
*/
|
|
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)));
|
|
1027
|
-
};
|
|
1028
1028
|
return TuiDayRange;
|
|
1029
1029
|
}(TuiMonthRange));
|
|
1030
1030
|
|
|
@@ -1044,46 +1044,6 @@
|
|
|
1044
1044
|
this.ms = ms;
|
|
1045
1045
|
classes.tuiAssert.assert(TuiTime.isValidTime(hours, minutes, seconds, ms), 'Time must be real, but got:', hours, minutes, seconds, ms);
|
|
1046
1046
|
}
|
|
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
1047
|
/**
|
|
1088
1048
|
* Checks if time is valid
|
|
1089
1049
|
*/
|
|
@@ -1142,6 +1102,46 @@
|
|
|
1142
1102
|
TuiTime.fromLocalNativeDate = function (date) {
|
|
1143
1103
|
return new TuiTime(date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
|
|
1144
1104
|
};
|
|
1105
|
+
/**
|
|
1106
|
+
* Shifts time by hours and minutes
|
|
1107
|
+
*/
|
|
1108
|
+
TuiTime.prototype.shift = function (_a) {
|
|
1109
|
+
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;
|
|
1110
|
+
var newMs = (1000 + this.ms + (ms % 1000)) % 1000;
|
|
1111
|
+
var secondsInMs = ms < 0 ? Math.ceil(ms / 1000) : Math.floor(ms / 1000);
|
|
1112
|
+
var secondsToAdd = secondsInMs + seconds;
|
|
1113
|
+
var newSeconds = (60 + this.seconds + (secondsToAdd % 60)) % 60;
|
|
1114
|
+
var minutesInSeconds = secondsToAdd < 0
|
|
1115
|
+
? Math.ceil(secondsToAdd / 60)
|
|
1116
|
+
: Math.floor(secondsToAdd / 60);
|
|
1117
|
+
var minutesToAdd = minutesInSeconds + minutes;
|
|
1118
|
+
var newMinutes = (60 + this.minutes + (minutesToAdd % 60)) % 60;
|
|
1119
|
+
var hoursInMinutes = minutesToAdd < 0
|
|
1120
|
+
? Math.ceil(minutesToAdd / 60)
|
|
1121
|
+
: Math.floor(minutesToAdd / 60);
|
|
1122
|
+
var hoursToAdd = hoursInMinutes + hours;
|
|
1123
|
+
var newHours = (24 + this.hours + (hoursToAdd % 24)) % 24;
|
|
1124
|
+
return new TuiTime(newHours, newMinutes, newSeconds, newMs);
|
|
1125
|
+
};
|
|
1126
|
+
/**
|
|
1127
|
+
* Converts TuiTime to string
|
|
1128
|
+
*/
|
|
1129
|
+
TuiTime.prototype.toString = function (mode) {
|
|
1130
|
+
var needAddMs = mode === 'HH:MM:SS.MSS' || (!mode && this.ms > 0);
|
|
1131
|
+
var needAddSeconds = needAddMs || mode === 'HH:MM:SS' || (!mode && this.seconds > 0);
|
|
1132
|
+
return (this.formatTime(this.hours) + ":" + this.formatTime(this.minutes) +
|
|
1133
|
+
("" + (needAddSeconds ? ':' + this.formatTime(this.seconds) : '')) +
|
|
1134
|
+
("" + (needAddMs ? '.' + this.formatTime(this.ms, 3) : '')));
|
|
1135
|
+
};
|
|
1136
|
+
/**
|
|
1137
|
+
* Converts TuiTime to milliseconds
|
|
1138
|
+
*/
|
|
1139
|
+
TuiTime.prototype.toAbsoluteMilliseconds = function () {
|
|
1140
|
+
return (this.hours * MILLISECONDS_IN_HOUR +
|
|
1141
|
+
this.minutes * MILLISECONDS_IN_MINUTE +
|
|
1142
|
+
this.seconds * 1000 +
|
|
1143
|
+
this.ms);
|
|
1144
|
+
};
|
|
1145
1145
|
TuiTime.prototype.formatTime = function (time, digits) {
|
|
1146
1146
|
if (digits === void 0) { digits = 2; }
|
|
1147
1147
|
return format.padStart(time.toString(), digits, '0');
|