ts-time-utils 4.1.0 → 4.4.1
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/README.md +83 -32
- package/dist/{age.js → age.cjs} +14 -6
- package/dist/{calculate.js → calculate.cjs} +42 -18
- package/dist/calculate.d.ts +7 -0
- package/dist/calculate.d.ts.map +1 -1
- package/dist/{calendar.js → calendar.cjs} +80 -39
- package/dist/{calendars.js → calendars.cjs} +48 -23
- package/dist/{chain.js → chain.cjs} +41 -40
- package/dist/{compare.js → compare.cjs} +58 -28
- package/dist/constants.cjs +19 -0
- package/dist/{countdown.js → countdown.cjs} +16 -7
- package/dist/{cron.js → cron.cjs} +20 -9
- package/dist/{dateRange.js → dateRange.cjs} +42 -26
- package/dist/{duration.js → duration.cjs} +56 -44
- package/dist/esm/calculate.d.ts +7 -0
- package/dist/esm/calculate.d.ts.map +1 -1
- package/dist/esm/calculate.js +11 -0
- package/dist/esm/chain.js +0 -5
- package/dist/esm/format.d.ts.map +1 -1
- package/dist/esm/format.js +3 -3
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/naturalLanguage.d.ts +1 -3
- package/dist/esm/naturalLanguage.d.ts.map +1 -1
- package/dist/esm/naturalLanguage.js +9 -2
- package/dist/esm/plugins.d.ts +0 -6
- package/dist/esm/plugins.d.ts.map +1 -1
- package/dist/esm/plugins.js +36 -42
- package/dist/esm/recurrence.d.ts.map +1 -1
- package/dist/esm/recurrence.js +3 -5
- package/dist/esm/timezone.d.ts +6 -1
- package/dist/esm/timezone.d.ts.map +1 -1
- package/dist/esm/timezone.js +106 -66
- package/dist/esm/types.d.ts +0 -4
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/{finance.js → finance.cjs} +39 -22
- package/dist/{fiscal.js → fiscal.cjs} +36 -17
- package/dist/{format.js → format.cjs} +85 -72
- package/dist/format.d.ts.map +1 -1
- package/dist/{healthcare.js → healthcare.cjs} +37 -22
- package/dist/{holidays.js → holidays.cjs} +52 -25
- package/dist/index.cjs +596 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/{interval.js → interval.cjs} +24 -11
- package/dist/{iterate.js → iterate.cjs} +84 -41
- package/dist/{locale.js → locale.cjs} +54 -26
- package/dist/{naturalLanguage.js → naturalLanguage.cjs} +36 -23
- package/dist/naturalLanguage.d.ts +1 -3
- package/dist/naturalLanguage.d.ts.map +1 -1
- package/dist/{parse.js → parse.cjs} +24 -11
- package/dist/{performance.js → performance.cjs} +23 -10
- package/dist/{plugins.js → plugins.cjs} +48 -47
- package/dist/plugins.d.ts +0 -6
- package/dist/plugins.d.ts.map +1 -1
- package/dist/{precision.js → precision.cjs} +74 -37
- package/dist/{rangePresets.js → rangePresets.cjs} +40 -19
- package/dist/{recurrence.js → recurrence.cjs} +27 -21
- package/dist/recurrence.d.ts.map +1 -1
- package/dist/{scheduling.js → scheduling.cjs} +46 -31
- package/dist/{serialize.js → serialize.cjs} +36 -17
- package/dist/{temporal.js → temporal.cjs} +28 -13
- package/dist/{timezone.js → timezone.cjs} +140 -82
- package/dist/timezone.d.ts +6 -1
- package/dist/timezone.d.ts.map +1 -1
- package/dist/{types.js → types.cjs} +9 -3
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/{validate.js → validate.cjs} +54 -26
- package/dist/{workingHours.js → workingHours.cjs} +36 -17
- package/package.json +41 -38
- package/dist/constants.js +0 -16
- package/dist/index.js +0 -72
|
@@ -1,7 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* @fileoverview International holiday utilities
|
|
3
4
|
* Calculate holidays for multiple countries including fixed, movable, and lunar-based holidays
|
|
4
5
|
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getUKHolidays = getUKHolidays;
|
|
8
|
+
exports.getNetherlandsHolidays = getNetherlandsHolidays;
|
|
9
|
+
exports.getGermanyHolidays = getGermanyHolidays;
|
|
10
|
+
exports.getCanadaHolidays = getCanadaHolidays;
|
|
11
|
+
exports.getAustraliaHolidays = getAustraliaHolidays;
|
|
12
|
+
exports.getItalyHolidays = getItalyHolidays;
|
|
13
|
+
exports.getSpainHolidays = getSpainHolidays;
|
|
14
|
+
exports.getChinaHolidays = getChinaHolidays;
|
|
15
|
+
exports.getIndiaHolidays = getIndiaHolidays;
|
|
16
|
+
exports.getJapanHolidays = getJapanHolidays;
|
|
17
|
+
exports.getFranceHolidays = getFranceHolidays;
|
|
18
|
+
exports.getBrazilHolidays = getBrazilHolidays;
|
|
19
|
+
exports.getMexicoHolidays = getMexicoHolidays;
|
|
20
|
+
exports.getSouthKoreaHolidays = getSouthKoreaHolidays;
|
|
21
|
+
exports.getSingaporeHolidays = getSingaporeHolidays;
|
|
22
|
+
exports.getPolandHolidays = getPolandHolidays;
|
|
23
|
+
exports.getSwedenHolidays = getSwedenHolidays;
|
|
24
|
+
exports.getBelgiumHolidays = getBelgiumHolidays;
|
|
25
|
+
exports.getSwitzerlandHolidays = getSwitzerlandHolidays;
|
|
26
|
+
exports.getHolidays = getHolidays;
|
|
27
|
+
exports.isHoliday = isHoliday;
|
|
28
|
+
exports.getHolidayName = getHolidayName;
|
|
29
|
+
exports.getNextHoliday = getNextHoliday;
|
|
30
|
+
exports.getUpcomingHolidays = getUpcomingHolidays;
|
|
31
|
+
exports.getSupportedCountries = getSupportedCountries;
|
|
5
32
|
/**
|
|
6
33
|
* Calculate Easter Sunday using the Anonymous Gregorian algorithm
|
|
7
34
|
* @param year - The year
|
|
@@ -64,7 +91,7 @@ function adjustForWeekend(date) {
|
|
|
64
91
|
// ============================================================================
|
|
65
92
|
// UK HOLIDAYS
|
|
66
93
|
// ============================================================================
|
|
67
|
-
|
|
94
|
+
function getUKHolidays(year) {
|
|
68
95
|
const holidays = [];
|
|
69
96
|
// New Year's Day (or substitute)
|
|
70
97
|
holidays.push({
|
|
@@ -139,7 +166,7 @@ export function getUKHolidays(year) {
|
|
|
139
166
|
// ============================================================================
|
|
140
167
|
// NETHERLANDS HOLIDAYS
|
|
141
168
|
// ============================================================================
|
|
142
|
-
|
|
169
|
+
function getNetherlandsHolidays(year) {
|
|
143
170
|
const holidays = [];
|
|
144
171
|
const easter = getEasterSunday(year);
|
|
145
172
|
// New Year's Day
|
|
@@ -235,7 +262,7 @@ export function getNetherlandsHolidays(year) {
|
|
|
235
262
|
// ============================================================================
|
|
236
263
|
// GERMANY HOLIDAYS
|
|
237
264
|
// ============================================================================
|
|
238
|
-
|
|
265
|
+
function getGermanyHolidays(year) {
|
|
239
266
|
const holidays = [];
|
|
240
267
|
const easter = getEasterSunday(year);
|
|
241
268
|
// New Year's Day
|
|
@@ -306,7 +333,7 @@ export function getGermanyHolidays(year) {
|
|
|
306
333
|
// ============================================================================
|
|
307
334
|
// CANADA HOLIDAYS
|
|
308
335
|
// ============================================================================
|
|
309
|
-
|
|
336
|
+
function getCanadaHolidays(year) {
|
|
310
337
|
const holidays = [];
|
|
311
338
|
const easter = getEasterSunday(year);
|
|
312
339
|
// New Year's Day
|
|
@@ -379,7 +406,7 @@ export function getCanadaHolidays(year) {
|
|
|
379
406
|
// ============================================================================
|
|
380
407
|
// AUSTRALIA HOLIDAYS
|
|
381
408
|
// ============================================================================
|
|
382
|
-
|
|
409
|
+
function getAustraliaHolidays(year) {
|
|
383
410
|
const holidays = [];
|
|
384
411
|
const easter = getEasterSunday(year);
|
|
385
412
|
// New Year's Day
|
|
@@ -450,7 +477,7 @@ export function getAustraliaHolidays(year) {
|
|
|
450
477
|
// ============================================================================
|
|
451
478
|
// ITALY HOLIDAYS
|
|
452
479
|
// ============================================================================
|
|
453
|
-
|
|
480
|
+
function getItalyHolidays(year) {
|
|
454
481
|
const holidays = [];
|
|
455
482
|
const easter = getEasterSunday(year);
|
|
456
483
|
// New Year's Day
|
|
@@ -535,7 +562,7 @@ export function getItalyHolidays(year) {
|
|
|
535
562
|
// ============================================================================
|
|
536
563
|
// SPAIN HOLIDAYS
|
|
537
564
|
// ============================================================================
|
|
538
|
-
|
|
565
|
+
function getSpainHolidays(year) {
|
|
539
566
|
const holidays = [];
|
|
540
567
|
const easter = getEasterSunday(year);
|
|
541
568
|
// New Year's Day
|
|
@@ -613,7 +640,7 @@ export function getSpainHolidays(year) {
|
|
|
613
640
|
// ============================================================================
|
|
614
641
|
// CHINA HOLIDAYS (Simplified - some are lunar calendar based)
|
|
615
642
|
// ============================================================================
|
|
616
|
-
|
|
643
|
+
function getChinaHolidays(year) {
|
|
617
644
|
const holidays = [];
|
|
618
645
|
// New Year's Day
|
|
619
646
|
holidays.push({
|
|
@@ -655,7 +682,7 @@ export function getChinaHolidays(year) {
|
|
|
655
682
|
// ============================================================================
|
|
656
683
|
// INDIA HOLIDAYS (Simplified - many are lunar calendar based)
|
|
657
684
|
// ============================================================================
|
|
658
|
-
|
|
685
|
+
function getIndiaHolidays(year) {
|
|
659
686
|
const holidays = [];
|
|
660
687
|
// Republic Day
|
|
661
688
|
holidays.push({
|
|
@@ -685,7 +712,7 @@ export function getIndiaHolidays(year) {
|
|
|
685
712
|
// ============================================================================
|
|
686
713
|
// JAPAN HOLIDAYS
|
|
687
714
|
// ============================================================================
|
|
688
|
-
|
|
715
|
+
function getJapanHolidays(year) {
|
|
689
716
|
const holidays = [];
|
|
690
717
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'JP', type: 'public' });
|
|
691
718
|
holidays.push({ name: 'Coming of Age Day', date: getNthWeekdayOfMonth(year, 0, 1, 2), countryCode: 'JP', type: 'public' });
|
|
@@ -708,7 +735,7 @@ export function getJapanHolidays(year) {
|
|
|
708
735
|
// ============================================================================
|
|
709
736
|
// FRANCE HOLIDAYS
|
|
710
737
|
// ============================================================================
|
|
711
|
-
|
|
738
|
+
function getFranceHolidays(year) {
|
|
712
739
|
const holidays = [];
|
|
713
740
|
const easter = getEasterSunday(year);
|
|
714
741
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'FR', type: 'public' });
|
|
@@ -727,7 +754,7 @@ export function getFranceHolidays(year) {
|
|
|
727
754
|
// ============================================================================
|
|
728
755
|
// BRAZIL HOLIDAYS
|
|
729
756
|
// ============================================================================
|
|
730
|
-
|
|
757
|
+
function getBrazilHolidays(year) {
|
|
731
758
|
const holidays = [];
|
|
732
759
|
const easter = getEasterSunday(year);
|
|
733
760
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'BR', type: 'public' });
|
|
@@ -746,7 +773,7 @@ export function getBrazilHolidays(year) {
|
|
|
746
773
|
// ============================================================================
|
|
747
774
|
// MEXICO HOLIDAYS
|
|
748
775
|
// ============================================================================
|
|
749
|
-
|
|
776
|
+
function getMexicoHolidays(year) {
|
|
750
777
|
const holidays = [];
|
|
751
778
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'MX', type: 'public' });
|
|
752
779
|
holidays.push({ name: 'Constitution Day', date: getNthWeekdayOfMonth(year, 1, 1, 1), countryCode: 'MX', type: 'public' });
|
|
@@ -760,7 +787,7 @@ export function getMexicoHolidays(year) {
|
|
|
760
787
|
// ============================================================================
|
|
761
788
|
// SOUTH KOREA HOLIDAYS
|
|
762
789
|
// ============================================================================
|
|
763
|
-
|
|
790
|
+
function getSouthKoreaHolidays(year) {
|
|
764
791
|
const holidays = [];
|
|
765
792
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'KR', type: 'public' });
|
|
766
793
|
holidays.push({ name: 'Independence Movement Day', date: new Date(year, 2, 1), countryCode: 'KR', type: 'public' });
|
|
@@ -776,7 +803,7 @@ export function getSouthKoreaHolidays(year) {
|
|
|
776
803
|
// ============================================================================
|
|
777
804
|
// SINGAPORE HOLIDAYS
|
|
778
805
|
// ============================================================================
|
|
779
|
-
|
|
806
|
+
function getSingaporeHolidays(year) {
|
|
780
807
|
const holidays = [];
|
|
781
808
|
const easter = getEasterSunday(year);
|
|
782
809
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'SG', type: 'public' });
|
|
@@ -790,7 +817,7 @@ export function getSingaporeHolidays(year) {
|
|
|
790
817
|
// ============================================================================
|
|
791
818
|
// POLAND HOLIDAYS
|
|
792
819
|
// ============================================================================
|
|
793
|
-
|
|
820
|
+
function getPolandHolidays(year) {
|
|
794
821
|
const holidays = [];
|
|
795
822
|
const easter = getEasterSunday(year);
|
|
796
823
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'PL', type: 'public' });
|
|
@@ -811,7 +838,7 @@ export function getPolandHolidays(year) {
|
|
|
811
838
|
// ============================================================================
|
|
812
839
|
// SWEDEN HOLIDAYS
|
|
813
840
|
// ============================================================================
|
|
814
|
-
|
|
841
|
+
function getSwedenHolidays(year) {
|
|
815
842
|
const holidays = [];
|
|
816
843
|
const easter = getEasterSunday(year);
|
|
817
844
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'SE', type: 'public' });
|
|
@@ -851,7 +878,7 @@ function getSaturdayBetween(year, startMonth, startDay, endMonth, endDay) {
|
|
|
851
878
|
// ============================================================================
|
|
852
879
|
// BELGIUM HOLIDAYS
|
|
853
880
|
// ============================================================================
|
|
854
|
-
|
|
881
|
+
function getBelgiumHolidays(year) {
|
|
855
882
|
const holidays = [];
|
|
856
883
|
const easter = getEasterSunday(year);
|
|
857
884
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'BE', type: 'public' });
|
|
@@ -869,7 +896,7 @@ export function getBelgiumHolidays(year) {
|
|
|
869
896
|
// ============================================================================
|
|
870
897
|
// SWITZERLAND HOLIDAYS (Federal only - cantons have additional)
|
|
871
898
|
// ============================================================================
|
|
872
|
-
|
|
899
|
+
function getSwitzerlandHolidays(year) {
|
|
873
900
|
const holidays = [];
|
|
874
901
|
const easter = getEasterSunday(year);
|
|
875
902
|
holidays.push({ name: "New Year's Day", date: new Date(year, 0, 1), countryCode: 'CH', type: 'public' });
|
|
@@ -890,7 +917,7 @@ export function getSwitzerlandHolidays(year) {
|
|
|
890
917
|
* @param countryCode - ISO country code
|
|
891
918
|
* @returns Array of holidays
|
|
892
919
|
*/
|
|
893
|
-
|
|
920
|
+
function getHolidays(year, countryCode) {
|
|
894
921
|
switch (countryCode) {
|
|
895
922
|
case 'UK':
|
|
896
923
|
return getUKHolidays(year);
|
|
@@ -943,7 +970,7 @@ export function getHolidays(year, countryCode) {
|
|
|
943
970
|
* @param countryCode - ISO country code
|
|
944
971
|
* @returns True if date is a holiday
|
|
945
972
|
*/
|
|
946
|
-
|
|
973
|
+
function isHoliday(date, countryCode) {
|
|
947
974
|
const holidays = getHolidays(date.getFullYear(), countryCode);
|
|
948
975
|
// Normalize to local date components for comparison
|
|
949
976
|
const targetYear = date.getFullYear();
|
|
@@ -959,7 +986,7 @@ export function isHoliday(date, countryCode) {
|
|
|
959
986
|
* @param countryCode - ISO country code
|
|
960
987
|
* @returns Holiday name or null if not a holiday
|
|
961
988
|
*/
|
|
962
|
-
|
|
989
|
+
function getHolidayName(date, countryCode) {
|
|
963
990
|
const holidays = getHolidays(date.getFullYear(), countryCode);
|
|
964
991
|
// Normalize to local date components for comparison
|
|
965
992
|
const targetYear = date.getFullYear();
|
|
@@ -976,7 +1003,7 @@ export function getHolidayName(date, countryCode) {
|
|
|
976
1003
|
* @param countryCode - ISO country code
|
|
977
1004
|
* @returns Next holiday or null
|
|
978
1005
|
*/
|
|
979
|
-
|
|
1006
|
+
function getNextHoliday(date, countryCode) {
|
|
980
1007
|
const year = date.getFullYear();
|
|
981
1008
|
let holidays = getHolidays(year, countryCode);
|
|
982
1009
|
// Also get next year's holidays
|
|
@@ -993,7 +1020,7 @@ export function getNextHoliday(date, countryCode) {
|
|
|
993
1020
|
* @param countryCode - ISO country code
|
|
994
1021
|
* @returns Array of upcoming holidays
|
|
995
1022
|
*/
|
|
996
|
-
|
|
1023
|
+
function getUpcomingHolidays(date, days, countryCode) {
|
|
997
1024
|
const year = date.getFullYear();
|
|
998
1025
|
let holidays = getHolidays(year, countryCode);
|
|
999
1026
|
// Also get next year's holidays
|
|
@@ -1007,6 +1034,6 @@ export function getUpcomingHolidays(date, days, countryCode) {
|
|
|
1007
1034
|
* Get all supported country codes
|
|
1008
1035
|
* @returns Array of country codes
|
|
1009
1036
|
*/
|
|
1010
|
-
|
|
1037
|
+
function getSupportedCountries() {
|
|
1011
1038
|
return ['UK', 'NL', 'DE', 'CA', 'AU', 'IT', 'ES', 'CN', 'IN', 'US', 'JP', 'FR', 'BR', 'MX', 'KR', 'SG', 'PL', 'SE', 'BE', 'CH'];
|
|
1012
1039
|
}
|