ts-time-utils 4.0.1 → 4.4.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/README.md +175 -30
- package/dist/{age.js → age.cjs} +14 -6
- package/dist/{calculate.js → calculate.cjs} +30 -18
- 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/chain.js +0 -5
- package/dist/esm/finance.d.ts +236 -0
- package/dist/esm/finance.d.ts.map +1 -0
- package/dist/esm/finance.js +495 -0
- package/dist/esm/healthcare.d.ts +260 -0
- package/dist/esm/healthcare.d.ts.map +1 -0
- package/dist/esm/healthcare.js +447 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -0
- 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/scheduling.d.ts +206 -0
- package/dist/esm/scheduling.d.ts.map +1 -0
- package/dist/esm/scheduling.js +329 -0
- 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.cjs +512 -0
- package/dist/finance.d.ts +236 -0
- package/dist/finance.d.ts.map +1 -0
- package/dist/{fiscal.js → fiscal.cjs} +36 -17
- package/dist/{format.js → format.cjs} +83 -70
- package/dist/healthcare.cjs +462 -0
- package/dist/healthcare.d.ts +260 -0
- package/dist/healthcare.d.ts.map +1 -0
- package/dist/{holidays.js → holidays.cjs} +52 -25
- package/dist/index.cjs +595 -0
- package/dist/index.d.ts +6 -0
- 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.cjs +344 -0
- package/dist/scheduling.d.ts +206 -0
- package/dist/scheduling.d.ts.map +1 -0
- 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 +52 -34
- package/dist/constants.js +0 -16
- package/dist/index.js +0 -66
package/dist/timezone.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timezone.d.ts","sourceRoot":"","sources":["../src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utils modules
|
|
3
4
|
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ValidationError = exports.ParseError = exports.TimeUtilsError = void 0;
|
|
4
7
|
/** Standardized error types */
|
|
5
|
-
|
|
8
|
+
class TimeUtilsError extends Error {
|
|
6
9
|
constructor(message, code) {
|
|
7
10
|
super(message);
|
|
8
11
|
this.code = code;
|
|
9
12
|
this.name = 'TimeUtilsError';
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
|
-
|
|
15
|
+
exports.TimeUtilsError = TimeUtilsError;
|
|
16
|
+
class ParseError extends TimeUtilsError {
|
|
13
17
|
constructor(message, input) {
|
|
14
18
|
super(message, 'PARSE_ERROR');
|
|
15
19
|
this.input = input;
|
|
16
20
|
this.name = 'ParseError';
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
|
-
|
|
23
|
+
exports.ParseError = ParseError;
|
|
24
|
+
class ValidationError extends TimeUtilsError {
|
|
20
25
|
constructor(message, value) {
|
|
21
26
|
super(message, 'VALIDATION_ERROR');
|
|
22
27
|
this.value = value;
|
|
23
28
|
this.name = 'ValidationError';
|
|
24
29
|
}
|
|
25
30
|
}
|
|
31
|
+
exports.ValidationError = ValidationError;
|
package/dist/types.d.ts
CHANGED
|
@@ -14,8 +14,6 @@ export interface ParseOptions {
|
|
|
14
14
|
strict?: boolean;
|
|
15
15
|
/** Timezone to use for parsing */
|
|
16
16
|
timezone?: string;
|
|
17
|
-
/** Default locale for parsing */
|
|
18
|
-
locale?: string;
|
|
19
17
|
}
|
|
20
18
|
/** Options for formatting operations */
|
|
21
19
|
export interface FormatOptions {
|
|
@@ -63,8 +61,6 @@ export interface WorkingHoursConfig {
|
|
|
63
61
|
start: number;
|
|
64
62
|
end: number;
|
|
65
63
|
}[];
|
|
66
|
-
/** Timezone for working hours calculation */
|
|
67
|
-
timezone?: string;
|
|
68
64
|
}
|
|
69
65
|
/** Result of age calculation */
|
|
70
66
|
export interface AgeResult {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/C,4CAA4C;AAC5C,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,IAAI,CAAC;IACZ,GAAG,EAAE,IAAI,CAAC;CACX;AAED,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/C,4CAA4C;AAC5C,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,IAAI,CAAC;IACZ,GAAG,EAAE,IAAI,CAAC;CACX;AAED,qCAAqC;AACrC,MAAM,WAAW,YAAY;IAC3B,+DAA+D;IAC/D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wCAAwC;AACxC,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,qCAAqC;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,8CAA8C;AAC9C,MAAM,MAAM,QAAQ,GAChB,aAAa,GAAG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CAAC;KACnD,CAAC;IACF,iCAAiC;IACjC,QAAQ,CAAC,EAAE;QACT,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACzC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QACtB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B,CAAC;IACF,wBAAwB;IACxB,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC,mCAAmC;IACnC,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,uDAAuD;IACvD,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,yDAAyD;IACzD,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,uCAAuC;IACvC,OAAO,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC5B,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;CACrC"}
|
|
@@ -1,8 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidDate = isValidDate;
|
|
4
|
+
exports.isLeapYear = isLeapYear;
|
|
5
|
+
exports.isPast = isPast;
|
|
6
|
+
exports.isFuture = isFuture;
|
|
7
|
+
exports.isToday = isToday;
|
|
8
|
+
exports.isYesterday = isYesterday;
|
|
9
|
+
exports.isTomorrow = isTomorrow;
|
|
10
|
+
exports.isSameDay = isSameDay;
|
|
11
|
+
exports.isWeekend = isWeekend;
|
|
12
|
+
exports.isWeekday = isWeekday;
|
|
13
|
+
exports.isValidTimeString = isValidTimeString;
|
|
14
|
+
exports.isValidISOString = isValidISOString;
|
|
15
|
+
exports.isSameWeek = isSameWeek;
|
|
16
|
+
exports.isSameMonth = isSameMonth;
|
|
17
|
+
exports.isSameYear = isSameYear;
|
|
18
|
+
exports.isThisWeek = isThisWeek;
|
|
19
|
+
exports.isThisMonth = isThisMonth;
|
|
20
|
+
exports.isThisYear = isThisYear;
|
|
21
|
+
exports.isBusinessDay = isBusinessDay;
|
|
22
|
+
exports.isInLastNDays = isInLastNDays;
|
|
23
|
+
exports.isInNextNDays = isInNextNDays;
|
|
24
|
+
exports.isSameHour = isSameHour;
|
|
25
|
+
exports.isSameMinute = isSameMinute;
|
|
26
|
+
exports.isSameSecond = isSameSecond;
|
|
27
|
+
exports.isInQuarter = isInQuarter;
|
|
28
|
+
exports.isSameQuarter = isSameQuarter;
|
|
1
29
|
/**
|
|
2
30
|
* Check if a date is valid
|
|
3
31
|
* @param date - date to validate
|
|
4
32
|
*/
|
|
5
|
-
|
|
33
|
+
function isValidDate(date) {
|
|
6
34
|
if (date instanceof Date) {
|
|
7
35
|
return !isNaN(date.getTime());
|
|
8
36
|
}
|
|
@@ -16,28 +44,28 @@ export function isValidDate(date) {
|
|
|
16
44
|
* Check if a year is a leap year
|
|
17
45
|
* @param year - year to check
|
|
18
46
|
*/
|
|
19
|
-
|
|
47
|
+
function isLeapYear(year) {
|
|
20
48
|
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
|
|
21
49
|
}
|
|
22
50
|
/**
|
|
23
51
|
* Check if a date is in the past
|
|
24
52
|
* @param date - date to check
|
|
25
53
|
*/
|
|
26
|
-
|
|
54
|
+
function isPast(date) {
|
|
27
55
|
return date.getTime() < new Date().getTime();
|
|
28
56
|
}
|
|
29
57
|
/**
|
|
30
58
|
* Check if a date is in the future
|
|
31
59
|
* @param date - date to check
|
|
32
60
|
*/
|
|
33
|
-
|
|
61
|
+
function isFuture(date) {
|
|
34
62
|
return date.getTime() > new Date().getTime();
|
|
35
63
|
}
|
|
36
64
|
/**
|
|
37
65
|
* Check if a date is today
|
|
38
66
|
* @param date - date to check
|
|
39
67
|
*/
|
|
40
|
-
|
|
68
|
+
function isToday(date) {
|
|
41
69
|
const today = new Date();
|
|
42
70
|
return (date.getDate() === today.getDate() &&
|
|
43
71
|
date.getMonth() === today.getMonth() &&
|
|
@@ -47,7 +75,7 @@ export function isToday(date) {
|
|
|
47
75
|
* Check if a date is yesterday
|
|
48
76
|
* @param date - date to check
|
|
49
77
|
*/
|
|
50
|
-
|
|
78
|
+
function isYesterday(date) {
|
|
51
79
|
const yesterday = new Date();
|
|
52
80
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
53
81
|
return (date.getDate() === yesterday.getDate() &&
|
|
@@ -58,7 +86,7 @@ export function isYesterday(date) {
|
|
|
58
86
|
* Check if a date is tomorrow
|
|
59
87
|
* @param date - date to check
|
|
60
88
|
*/
|
|
61
|
-
|
|
89
|
+
function isTomorrow(date) {
|
|
62
90
|
const tomorrow = new Date();
|
|
63
91
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
64
92
|
return (date.getDate() === tomorrow.getDate() &&
|
|
@@ -70,7 +98,7 @@ export function isTomorrow(date) {
|
|
|
70
98
|
* @param date1 - first date
|
|
71
99
|
* @param date2 - second date
|
|
72
100
|
*/
|
|
73
|
-
|
|
101
|
+
function isSameDay(date1, date2) {
|
|
74
102
|
return (date1.getDate() === date2.getDate() &&
|
|
75
103
|
date1.getMonth() === date2.getMonth() &&
|
|
76
104
|
date1.getFullYear() === date2.getFullYear());
|
|
@@ -79,7 +107,7 @@ export function isSameDay(date1, date2) {
|
|
|
79
107
|
* Check if a date is a weekend (Saturday or Sunday)
|
|
80
108
|
* @param date - date to check
|
|
81
109
|
*/
|
|
82
|
-
|
|
110
|
+
function isWeekend(date) {
|
|
83
111
|
const dayOfWeek = date.getDay();
|
|
84
112
|
return dayOfWeek === 0 || dayOfWeek === 6; // Sunday or Saturday
|
|
85
113
|
}
|
|
@@ -87,14 +115,14 @@ export function isWeekend(date) {
|
|
|
87
115
|
* Check if a date is a weekday (Monday through Friday)
|
|
88
116
|
* @param date - date to check
|
|
89
117
|
*/
|
|
90
|
-
|
|
118
|
+
function isWeekday(date) {
|
|
91
119
|
return !isWeekend(date);
|
|
92
120
|
}
|
|
93
121
|
/**
|
|
94
122
|
* Check if a time string is valid (HH:MM or HH:MM:SS format)
|
|
95
123
|
* @param time - time string to validate
|
|
96
124
|
*/
|
|
97
|
-
|
|
125
|
+
function isValidTimeString(time) {
|
|
98
126
|
const timeRegex = /^([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$/;
|
|
99
127
|
return timeRegex.test(time);
|
|
100
128
|
}
|
|
@@ -102,7 +130,7 @@ export function isValidTimeString(time) {
|
|
|
102
130
|
* Check if a date string is valid ISO 8601 format
|
|
103
131
|
* @param dateString - date string to validate
|
|
104
132
|
*/
|
|
105
|
-
|
|
133
|
+
function isValidISOString(dateString) {
|
|
106
134
|
const isoRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
|
|
107
135
|
return isoRegex.test(dateString) && isValidDate(dateString);
|
|
108
136
|
}
|
|
@@ -111,7 +139,7 @@ export function isValidISOString(dateString) {
|
|
|
111
139
|
* @param date1 - first date
|
|
112
140
|
* @param date2 - second date
|
|
113
141
|
*/
|
|
114
|
-
|
|
142
|
+
function isSameWeek(date1, date2) {
|
|
115
143
|
const getWeekStart = (d) => {
|
|
116
144
|
const date = new Date(d);
|
|
117
145
|
const day = date.getDay();
|
|
@@ -127,7 +155,7 @@ export function isSameWeek(date1, date2) {
|
|
|
127
155
|
* @param date1 - first date
|
|
128
156
|
* @param date2 - second date
|
|
129
157
|
*/
|
|
130
|
-
|
|
158
|
+
function isSameMonth(date1, date2) {
|
|
131
159
|
return (date1.getMonth() === date2.getMonth() &&
|
|
132
160
|
date1.getFullYear() === date2.getFullYear());
|
|
133
161
|
}
|
|
@@ -136,28 +164,28 @@ export function isSameMonth(date1, date2) {
|
|
|
136
164
|
* @param date1 - first date
|
|
137
165
|
* @param date2 - second date
|
|
138
166
|
*/
|
|
139
|
-
|
|
167
|
+
function isSameYear(date1, date2) {
|
|
140
168
|
return date1.getFullYear() === date2.getFullYear();
|
|
141
169
|
}
|
|
142
170
|
/**
|
|
143
171
|
* Check if a date is in the current week
|
|
144
172
|
* @param date - date to check
|
|
145
173
|
*/
|
|
146
|
-
|
|
174
|
+
function isThisWeek(date) {
|
|
147
175
|
return isSameWeek(date, new Date());
|
|
148
176
|
}
|
|
149
177
|
/**
|
|
150
178
|
* Check if a date is in the current month
|
|
151
179
|
* @param date - date to check
|
|
152
180
|
*/
|
|
153
|
-
|
|
181
|
+
function isThisMonth(date) {
|
|
154
182
|
return isSameMonth(date, new Date());
|
|
155
183
|
}
|
|
156
184
|
/**
|
|
157
185
|
* Check if a date is in the current year
|
|
158
186
|
* @param date - date to check
|
|
159
187
|
*/
|
|
160
|
-
|
|
188
|
+
function isThisYear(date) {
|
|
161
189
|
return isSameYear(date, new Date());
|
|
162
190
|
}
|
|
163
191
|
/**
|
|
@@ -165,7 +193,7 @@ export function isThisYear(date) {
|
|
|
165
193
|
* @param date - date to check
|
|
166
194
|
* @param holidays - optional array of holiday dates to exclude
|
|
167
195
|
*/
|
|
168
|
-
|
|
196
|
+
function isBusinessDay(date, holidays = []) {
|
|
169
197
|
if (isWeekend(date))
|
|
170
198
|
return false;
|
|
171
199
|
return !holidays.some(holiday => isSameDay(date, holiday));
|
|
@@ -175,7 +203,7 @@ export function isBusinessDay(date, holidays = []) {
|
|
|
175
203
|
* @param date - date to check
|
|
176
204
|
* @param n - number of days
|
|
177
205
|
*/
|
|
178
|
-
|
|
206
|
+
function isInLastNDays(date, n) {
|
|
179
207
|
const now = new Date();
|
|
180
208
|
const nDaysAgo = new Date(now);
|
|
181
209
|
nDaysAgo.setDate(nDaysAgo.getDate() - n);
|
|
@@ -189,7 +217,7 @@ export function isInLastNDays(date, n) {
|
|
|
189
217
|
* @param date - date to check
|
|
190
218
|
* @param n - number of days
|
|
191
219
|
*/
|
|
192
|
-
|
|
220
|
+
function isInNextNDays(date, n) {
|
|
193
221
|
const now = new Date();
|
|
194
222
|
const startOfToday = new Date(now);
|
|
195
223
|
startOfToday.setHours(0, 0, 0, 0);
|
|
@@ -203,7 +231,7 @@ export function isInNextNDays(date, n) {
|
|
|
203
231
|
* @param date1 - first date
|
|
204
232
|
* @param date2 - second date
|
|
205
233
|
*/
|
|
206
|
-
|
|
234
|
+
function isSameHour(date1, date2) {
|
|
207
235
|
return (date1.getFullYear() === date2.getFullYear() &&
|
|
208
236
|
date1.getMonth() === date2.getMonth() &&
|
|
209
237
|
date1.getDate() === date2.getDate() &&
|
|
@@ -214,7 +242,7 @@ export function isSameHour(date1, date2) {
|
|
|
214
242
|
* @param date1 - first date
|
|
215
243
|
* @param date2 - second date
|
|
216
244
|
*/
|
|
217
|
-
|
|
245
|
+
function isSameMinute(date1, date2) {
|
|
218
246
|
return (isSameHour(date1, date2) &&
|
|
219
247
|
date1.getMinutes() === date2.getMinutes());
|
|
220
248
|
}
|
|
@@ -223,7 +251,7 @@ export function isSameMinute(date1, date2) {
|
|
|
223
251
|
* @param date1 - first date
|
|
224
252
|
* @param date2 - second date
|
|
225
253
|
*/
|
|
226
|
-
|
|
254
|
+
function isSameSecond(date1, date2) {
|
|
227
255
|
return (isSameMinute(date1, date2) &&
|
|
228
256
|
date1.getSeconds() === date2.getSeconds());
|
|
229
257
|
}
|
|
@@ -232,7 +260,7 @@ export function isSameSecond(date1, date2) {
|
|
|
232
260
|
* @param date - date to check
|
|
233
261
|
* @param quarter - quarter (1-4)
|
|
234
262
|
*/
|
|
235
|
-
|
|
263
|
+
function isInQuarter(date, quarter) {
|
|
236
264
|
const month = date.getMonth();
|
|
237
265
|
const dateQuarter = Math.floor(month / 3) + 1;
|
|
238
266
|
return dateQuarter === quarter;
|
|
@@ -242,7 +270,7 @@ export function isInQuarter(date, quarter) {
|
|
|
242
270
|
* @param date1 - first date
|
|
243
271
|
* @param date2 - second date
|
|
244
272
|
*/
|
|
245
|
-
|
|
273
|
+
function isSameQuarter(date1, date2) {
|
|
246
274
|
return (date1.getFullYear() === date2.getFullYear() &&
|
|
247
275
|
Math.floor(date1.getMonth() / 3) === Math.floor(date2.getMonth() / 3));
|
|
248
276
|
}
|
|
@@ -1,13 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Working hours utilities for business time calculations
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_WORKING_HOURS = void 0;
|
|
7
|
+
exports.isWorkingDay = isWorkingDay;
|
|
8
|
+
exports.isWorkingTime = isWorkingTime;
|
|
9
|
+
exports.nextWorkingTime = nextWorkingTime;
|
|
10
|
+
exports.workingTimeBetween = workingTimeBetween;
|
|
11
|
+
exports.addWorkingHours = addWorkingHours;
|
|
12
|
+
exports.addWorkingDays = addWorkingDays;
|
|
13
|
+
exports.subtractWorkingDays = subtractWorkingDays;
|
|
14
|
+
exports.getNextWorkingDay = getNextWorkingDay;
|
|
15
|
+
exports.getPreviousWorkingDay = getPreviousWorkingDay;
|
|
16
|
+
exports.getWorkingDaysInMonth = getWorkingDaysInMonth;
|
|
17
|
+
exports.getWorkingDaysInMonthArray = getWorkingDaysInMonthArray;
|
|
18
|
+
exports.workingDaysBetween = workingDaysBetween;
|
|
19
|
+
exports.isBreakTime = isBreakTime;
|
|
20
|
+
exports.getWorkDayStart = getWorkDayStart;
|
|
21
|
+
exports.getWorkDayEnd = getWorkDayEnd;
|
|
22
|
+
exports.getWorkingHoursPerDay = getWorkingHoursPerDay;
|
|
23
|
+
exports.DEFAULT_WORKING_HOURS = {
|
|
5
24
|
workingDays: [1, 2, 3, 4, 5],
|
|
6
25
|
hours: { start: 9, end: 17 },
|
|
7
26
|
breaks: [{ start: 12, end: 13 }]
|
|
8
27
|
};
|
|
9
28
|
/** Check if a date is a configured working day */
|
|
10
|
-
|
|
29
|
+
function isWorkingDay(date, config = exports.DEFAULT_WORKING_HOURS) {
|
|
11
30
|
return config.workingDays.includes(date.getDay());
|
|
12
31
|
}
|
|
13
32
|
/** Convert date to fractional hour */
|
|
@@ -15,7 +34,7 @@ function toHourFraction(date) {
|
|
|
15
34
|
return date.getHours() + date.getMinutes() / 60 + date.getSeconds() / 3600;
|
|
16
35
|
}
|
|
17
36
|
/** Check if inside working hours (excluding breaks) */
|
|
18
|
-
|
|
37
|
+
function isWorkingTime(date, config = exports.DEFAULT_WORKING_HOURS) {
|
|
19
38
|
if (!isWorkingDay(date, config))
|
|
20
39
|
return false;
|
|
21
40
|
const h = toHourFraction(date);
|
|
@@ -30,7 +49,7 @@ export function isWorkingTime(date, config = DEFAULT_WORKING_HOURS) {
|
|
|
30
49
|
return true;
|
|
31
50
|
}
|
|
32
51
|
/** Move date forward to next working minute */
|
|
33
|
-
|
|
52
|
+
function nextWorkingTime(date, config = exports.DEFAULT_WORKING_HOURS) {
|
|
34
53
|
const d = new Date(date);
|
|
35
54
|
while (!isWorkingTime(d, config)) {
|
|
36
55
|
d.setMinutes(d.getMinutes() + 1);
|
|
@@ -52,7 +71,7 @@ function clampToWorkingWindow(date, config) {
|
|
|
52
71
|
return date;
|
|
53
72
|
}
|
|
54
73
|
/** Compute working time (ms) between two dates */
|
|
55
|
-
|
|
74
|
+
function workingTimeBetween(start, end, config = exports.DEFAULT_WORKING_HOURS) {
|
|
56
75
|
if (end <= start)
|
|
57
76
|
return 0;
|
|
58
77
|
let total = 0;
|
|
@@ -90,7 +109,7 @@ export function workingTimeBetween(start, end, config = DEFAULT_WORKING_HOURS) {
|
|
|
90
109
|
return total * 60 * 60 * 1000; // ms
|
|
91
110
|
}
|
|
92
111
|
/** Advance by working hours amount (simple iterative approach) */
|
|
93
|
-
|
|
112
|
+
function addWorkingHours(start, hours, config = exports.DEFAULT_WORKING_HOURS) {
|
|
94
113
|
if (hours <= 0)
|
|
95
114
|
return new Date(start);
|
|
96
115
|
let remaining = hours * 60; // minutes
|
|
@@ -113,7 +132,7 @@ export function addWorkingHours(start, hours, config = DEFAULT_WORKING_HOURS) {
|
|
|
113
132
|
* @param days - number of working days to add
|
|
114
133
|
* @param config - working hours configuration
|
|
115
134
|
*/
|
|
116
|
-
|
|
135
|
+
function addWorkingDays(start, days, config = exports.DEFAULT_WORKING_HOURS) {
|
|
117
136
|
if (days === 0)
|
|
118
137
|
return new Date(start);
|
|
119
138
|
const result = new Date(start);
|
|
@@ -133,7 +152,7 @@ export function addWorkingDays(start, days, config = DEFAULT_WORKING_HOURS) {
|
|
|
133
152
|
* @param days - number of working days to subtract
|
|
134
153
|
* @param config - working hours configuration
|
|
135
154
|
*/
|
|
136
|
-
|
|
155
|
+
function subtractWorkingDays(start, days, config = exports.DEFAULT_WORKING_HOURS) {
|
|
137
156
|
return addWorkingDays(start, -days, config);
|
|
138
157
|
}
|
|
139
158
|
/**
|
|
@@ -141,7 +160,7 @@ export function subtractWorkingDays(start, days, config = DEFAULT_WORKING_HOURS)
|
|
|
141
160
|
* @param date - start date
|
|
142
161
|
* @param config - working hours configuration
|
|
143
162
|
*/
|
|
144
|
-
|
|
163
|
+
function getNextWorkingDay(date, config = exports.DEFAULT_WORKING_HOURS) {
|
|
145
164
|
const result = new Date(date);
|
|
146
165
|
result.setDate(result.getDate() + 1);
|
|
147
166
|
while (!isWorkingDay(result, config)) {
|
|
@@ -154,7 +173,7 @@ export function getNextWorkingDay(date, config = DEFAULT_WORKING_HOURS) {
|
|
|
154
173
|
* @param date - start date
|
|
155
174
|
* @param config - working hours configuration
|
|
156
175
|
*/
|
|
157
|
-
|
|
176
|
+
function getPreviousWorkingDay(date, config = exports.DEFAULT_WORKING_HOURS) {
|
|
158
177
|
const result = new Date(date);
|
|
159
178
|
result.setDate(result.getDate() - 1);
|
|
160
179
|
while (!isWorkingDay(result, config)) {
|
|
@@ -168,7 +187,7 @@ export function getPreviousWorkingDay(date, config = DEFAULT_WORKING_HOURS) {
|
|
|
168
187
|
* @param month - month (0-11)
|
|
169
188
|
* @param config - working hours configuration
|
|
170
189
|
*/
|
|
171
|
-
|
|
190
|
+
function getWorkingDaysInMonth(year, month, config = exports.DEFAULT_WORKING_HOURS) {
|
|
172
191
|
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
|
173
192
|
let count = 0;
|
|
174
193
|
for (let day = 1; day <= daysInMonth; day++) {
|
|
@@ -185,7 +204,7 @@ export function getWorkingDaysInMonth(year, month, config = DEFAULT_WORKING_HOUR
|
|
|
185
204
|
* @param month - month (0-11)
|
|
186
205
|
* @param config - working hours configuration
|
|
187
206
|
*/
|
|
188
|
-
|
|
207
|
+
function getWorkingDaysInMonthArray(year, month, config = exports.DEFAULT_WORKING_HOURS) {
|
|
189
208
|
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
|
190
209
|
const workingDays = [];
|
|
191
210
|
for (let day = 1; day <= daysInMonth; day++) {
|
|
@@ -202,7 +221,7 @@ export function getWorkingDaysInMonthArray(year, month, config = DEFAULT_WORKING
|
|
|
202
221
|
* @param end - end date
|
|
203
222
|
* @param config - working hours configuration
|
|
204
223
|
*/
|
|
205
|
-
|
|
224
|
+
function workingDaysBetween(start, end, config = exports.DEFAULT_WORKING_HOURS) {
|
|
206
225
|
if (end < start)
|
|
207
226
|
return 0;
|
|
208
227
|
let count = 0;
|
|
@@ -223,7 +242,7 @@ export function workingDaysBetween(start, end, config = DEFAULT_WORKING_HOURS) {
|
|
|
223
242
|
* @param date - date to check
|
|
224
243
|
* @param config - working hours configuration
|
|
225
244
|
*/
|
|
226
|
-
|
|
245
|
+
function isBreakTime(date, config = exports.DEFAULT_WORKING_HOURS) {
|
|
227
246
|
if (!isWorkingDay(date, config))
|
|
228
247
|
return false;
|
|
229
248
|
if (!config.breaks || config.breaks.length === 0)
|
|
@@ -240,7 +259,7 @@ export function isBreakTime(date, config = DEFAULT_WORKING_HOURS) {
|
|
|
240
259
|
* @param date - date to get work start for
|
|
241
260
|
* @param config - working hours configuration
|
|
242
261
|
*/
|
|
243
|
-
|
|
262
|
+
function getWorkDayStart(date, config = exports.DEFAULT_WORKING_HOURS) {
|
|
244
263
|
const result = new Date(date);
|
|
245
264
|
result.setHours(config.hours.start, 0, 0, 0);
|
|
246
265
|
return result;
|
|
@@ -250,7 +269,7 @@ export function getWorkDayStart(date, config = DEFAULT_WORKING_HOURS) {
|
|
|
250
269
|
* @param date - date to get work end for
|
|
251
270
|
* @param config - working hours configuration
|
|
252
271
|
*/
|
|
253
|
-
|
|
272
|
+
function getWorkDayEnd(date, config = exports.DEFAULT_WORKING_HOURS) {
|
|
254
273
|
const result = new Date(date);
|
|
255
274
|
result.setHours(config.hours.end, 0, 0, 0);
|
|
256
275
|
return result;
|
|
@@ -259,7 +278,7 @@ export function getWorkDayEnd(date, config = DEFAULT_WORKING_HOURS) {
|
|
|
259
278
|
* Get the total working hours per day (excluding breaks)
|
|
260
279
|
* @param config - working hours configuration
|
|
261
280
|
*/
|
|
262
|
-
|
|
281
|
+
function getWorkingHoursPerDay(config = exports.DEFAULT_WORKING_HOURS) {
|
|
263
282
|
let hours = config.hours.end - config.hours.start;
|
|
264
283
|
if (config.breaks) {
|
|
265
284
|
for (const b of config.breaks) {
|