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.
Files changed (68) hide show
  1. package/README.md +91 -6
  2. package/dist/calculate.d.ts +25 -0
  3. package/dist/calculate.d.ts.map +1 -1
  4. package/dist/calculate.js +125 -0
  5. package/dist/calendar.d.ts +45 -0
  6. package/dist/calendar.d.ts.map +1 -1
  7. package/dist/calendar.js +68 -0
  8. package/dist/calendars.d.ts +156 -0
  9. package/dist/calendars.d.ts.map +1 -0
  10. package/dist/calendars.js +348 -0
  11. package/dist/compare.d.ts +27 -0
  12. package/dist/compare.d.ts.map +1 -1
  13. package/dist/compare.js +46 -0
  14. package/dist/esm/calculate.d.ts +25 -0
  15. package/dist/esm/calculate.d.ts.map +1 -1
  16. package/dist/esm/calculate.js +125 -0
  17. package/dist/esm/calendar.d.ts +45 -0
  18. package/dist/esm/calendar.d.ts.map +1 -1
  19. package/dist/esm/calendar.js +68 -0
  20. package/dist/esm/calendars.d.ts +156 -0
  21. package/dist/esm/calendars.d.ts.map +1 -0
  22. package/dist/esm/calendars.js +348 -0
  23. package/dist/esm/compare.d.ts +27 -0
  24. package/dist/esm/compare.d.ts.map +1 -1
  25. package/dist/esm/compare.js +46 -0
  26. package/dist/esm/holidays.d.ts +11 -1
  27. package/dist/esm/holidays.d.ts.map +1 -1
  28. package/dist/esm/holidays.js +220 -1
  29. package/dist/esm/index.d.ts +13 -7
  30. package/dist/esm/index.d.ts.map +1 -1
  31. package/dist/esm/index.js +17 -9
  32. package/dist/esm/iterate.d.ts +55 -0
  33. package/dist/esm/iterate.d.ts.map +1 -1
  34. package/dist/esm/iterate.js +86 -0
  35. package/dist/esm/locale.d.ts +53 -0
  36. package/dist/esm/locale.d.ts.map +1 -1
  37. package/dist/esm/locale.js +141 -0
  38. package/dist/esm/precision.d.ts +225 -0
  39. package/dist/esm/precision.d.ts.map +1 -0
  40. package/dist/esm/precision.js +491 -0
  41. package/dist/esm/temporal.d.ts +237 -0
  42. package/dist/esm/temporal.d.ts.map +1 -0
  43. package/dist/esm/temporal.js +660 -0
  44. package/dist/esm/validate.d.ts +30 -0
  45. package/dist/esm/validate.d.ts.map +1 -1
  46. package/dist/esm/validate.js +48 -0
  47. package/dist/holidays.d.ts +11 -1
  48. package/dist/holidays.d.ts.map +1 -1
  49. package/dist/holidays.js +220 -1
  50. package/dist/index.d.ts +13 -7
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +17 -9
  53. package/dist/iterate.d.ts +55 -0
  54. package/dist/iterate.d.ts.map +1 -1
  55. package/dist/iterate.js +86 -0
  56. package/dist/locale.d.ts +53 -0
  57. package/dist/locale.d.ts.map +1 -1
  58. package/dist/locale.js +141 -0
  59. package/dist/precision.d.ts +225 -0
  60. package/dist/precision.d.ts.map +1 -0
  61. package/dist/precision.js +491 -0
  62. package/dist/temporal.d.ts +237 -0
  63. package/dist/temporal.d.ts.map +1 -0
  64. package/dist/temporal.js +660 -0
  65. package/dist/validate.d.ts +30 -0
  66. package/dist/validate.d.ts.map +1 -1
  67. package/dist/validate.js +48 -0
  68. 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.0.4",
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": [