ts-time-utils 3.0.4 → 4.0.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 +91 -6
- package/dist/calculate.d.ts +25 -0
- package/dist/calculate.d.ts.map +1 -1
- package/dist/calculate.js +125 -0
- package/dist/calendar.d.ts +45 -0
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +68 -0
- package/dist/calendars.d.ts +156 -0
- package/dist/calendars.d.ts.map +1 -0
- package/dist/calendars.js +348 -0
- package/dist/compare.d.ts +27 -0
- package/dist/compare.d.ts.map +1 -1
- package/dist/compare.js +46 -0
- package/dist/esm/calculate.d.ts +25 -0
- package/dist/esm/calculate.d.ts.map +1 -1
- package/dist/esm/calculate.js +125 -0
- package/dist/esm/calendar.d.ts +45 -0
- package/dist/esm/calendar.d.ts.map +1 -1
- package/dist/esm/calendar.js +68 -0
- package/dist/esm/calendars.d.ts +156 -0
- package/dist/esm/calendars.d.ts.map +1 -0
- package/dist/esm/calendars.js +348 -0
- package/dist/esm/compare.d.ts +27 -0
- package/dist/esm/compare.d.ts.map +1 -1
- package/dist/esm/compare.js +46 -0
- package/dist/esm/holidays.d.ts +11 -1
- package/dist/esm/holidays.d.ts.map +1 -1
- package/dist/esm/holidays.js +220 -1
- package/dist/esm/index.d.ts +13 -7
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +17 -9
- package/dist/esm/iterate.d.ts +55 -0
- package/dist/esm/iterate.d.ts.map +1 -1
- package/dist/esm/iterate.js +86 -0
- package/dist/esm/locale.d.ts +53 -0
- package/dist/esm/locale.d.ts.map +1 -1
- package/dist/esm/locale.js +141 -0
- package/dist/esm/precision.d.ts +225 -0
- package/dist/esm/precision.d.ts.map +1 -0
- package/dist/esm/precision.js +491 -0
- package/dist/esm/temporal.d.ts +237 -0
- package/dist/esm/temporal.d.ts.map +1 -0
- package/dist/esm/temporal.js +660 -0
- package/dist/esm/validate.d.ts +30 -0
- package/dist/esm/validate.d.ts.map +1 -1
- package/dist/esm/validate.js +48 -0
- package/dist/holidays.d.ts +11 -1
- package/dist/holidays.d.ts.map +1 -1
- package/dist/holidays.js +220 -1
- package/dist/index.d.ts +13 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -9
- package/dist/iterate.d.ts +55 -0
- package/dist/iterate.d.ts.map +1 -1
- package/dist/iterate.js +86 -0
- package/dist/locale.d.ts +53 -0
- package/dist/locale.d.ts.map +1 -1
- package/dist/locale.js +141 -0
- package/dist/precision.d.ts +225 -0
- package/dist/precision.d.ts.map +1 -0
- package/dist/precision.js +491 -0
- package/dist/temporal.d.ts +237 -0
- package/dist/temporal.d.ts.map +1 -0
- package/dist/temporal.js +660 -0
- package/dist/validate.d.ts +30 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +48 -0
- package/package.json +16 -1
package/dist/validate.js
CHANGED
|
@@ -198,3 +198,51 @@ export function isInNextNDays(date, n) {
|
|
|
198
198
|
nDaysFromNow.setHours(23, 59, 59, 999);
|
|
199
199
|
return date >= startOfToday && date <= nDaysFromNow;
|
|
200
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Check if two dates are in the same hour
|
|
203
|
+
* @param date1 - first date
|
|
204
|
+
* @param date2 - second date
|
|
205
|
+
*/
|
|
206
|
+
export function isSameHour(date1, date2) {
|
|
207
|
+
return (date1.getFullYear() === date2.getFullYear() &&
|
|
208
|
+
date1.getMonth() === date2.getMonth() &&
|
|
209
|
+
date1.getDate() === date2.getDate() &&
|
|
210
|
+
date1.getHours() === date2.getHours());
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Check if two dates are in the same minute
|
|
214
|
+
* @param date1 - first date
|
|
215
|
+
* @param date2 - second date
|
|
216
|
+
*/
|
|
217
|
+
export function isSameMinute(date1, date2) {
|
|
218
|
+
return (isSameHour(date1, date2) &&
|
|
219
|
+
date1.getMinutes() === date2.getMinutes());
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Check if two dates are in the same second
|
|
223
|
+
* @param date1 - first date
|
|
224
|
+
* @param date2 - second date
|
|
225
|
+
*/
|
|
226
|
+
export function isSameSecond(date1, date2) {
|
|
227
|
+
return (isSameMinute(date1, date2) &&
|
|
228
|
+
date1.getSeconds() === date2.getSeconds());
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Check if a date is in a specific quarter
|
|
232
|
+
* @param date - date to check
|
|
233
|
+
* @param quarter - quarter (1-4)
|
|
234
|
+
*/
|
|
235
|
+
export function isInQuarter(date, quarter) {
|
|
236
|
+
const month = date.getMonth();
|
|
237
|
+
const dateQuarter = Math.floor(month / 3) + 1;
|
|
238
|
+
return dateQuarter === quarter;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Check if two dates are in the same quarter
|
|
242
|
+
* @param date1 - first date
|
|
243
|
+
* @param date2 - second date
|
|
244
|
+
*/
|
|
245
|
+
export function isSameQuarter(date1, date2) {
|
|
246
|
+
return (date1.getFullYear() === date2.getFullYear() &&
|
|
247
|
+
Math.floor(date1.getMonth() / 3) === Math.floor(date2.getMonth() / 3));
|
|
248
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-time-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "A comprehensive TypeScript utility library for time, dates, durations, and calendar operations with full tree-shaking support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -141,6 +141,21 @@
|
|
|
141
141
|
"import": "./dist/esm/plugins.js",
|
|
142
142
|
"require": "./dist/plugins.js",
|
|
143
143
|
"types": "./dist/plugins.d.ts"
|
|
144
|
+
},
|
|
145
|
+
"./calendars": {
|
|
146
|
+
"import": "./dist/esm/calendars.js",
|
|
147
|
+
"require": "./dist/calendars.js",
|
|
148
|
+
"types": "./dist/calendars.d.ts"
|
|
149
|
+
},
|
|
150
|
+
"./temporal": {
|
|
151
|
+
"import": "./dist/esm/temporal.js",
|
|
152
|
+
"require": "./dist/temporal.js",
|
|
153
|
+
"types": "./dist/temporal.d.ts"
|
|
154
|
+
},
|
|
155
|
+
"./precision": {
|
|
156
|
+
"import": "./dist/esm/precision.js",
|
|
157
|
+
"require": "./dist/precision.js",
|
|
158
|
+
"types": "./dist/precision.d.ts"
|
|
144
159
|
}
|
|
145
160
|
},
|
|
146
161
|
"files": [
|