@himanshu-sorathiya/datetime 1.0.1 → 1.0.2
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 +14 -0
- package/dist/index.d.ts +49 -3
- package/dist/index.js +249 -159
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,8 +57,11 @@ The immutability gateway and primitive getters. Every other function in the libr
|
|
|
57
57
|
| `getTimestamp(date)` | `number` | Epoch milliseconds — prefer this over repeated `isBefore()` calls in hot loops. |
|
|
58
58
|
| `getDayOfWeek(date)` | `number` | 0 = Sunday … 6 = Saturday (local time). |
|
|
59
59
|
| `getDaysInMonth(date)` | `number` | Leap-year aware. |
|
|
60
|
+
| `getDaysInYear(date)` | `number` | 365 or 366. |
|
|
60
61
|
| `getQuarter(date)` | `number` | 1–4. |
|
|
61
62
|
| `getDayOfYear(date)` | `number` | 1–366, DST-safe (computed from start-of-day timestamps). |
|
|
63
|
+
| `getWeekOfMonth(date, weekStartsOn?)` | `number` | 1–6 (depends on day-of-week overflow). |
|
|
64
|
+
| `getWeeksInMonth(date, weekStartsOn?)` | `number` | Total calendar rows needed to render the month. |
|
|
62
65
|
|
|
63
66
|
### Queries (Predicates)
|
|
64
67
|
|
|
@@ -71,12 +74,15 @@ Pure boolean functions. No date values are ever returned here — only `true` or
|
|
|
71
74
|
| `isSameYear(a, b)` | |
|
|
72
75
|
| `isSameQuarter(a, b)` | Checks year too. |
|
|
73
76
|
| `isSameWeek(a, b, weekStartsOn?)` | Defaults to Sunday start (`0`); pass `1` for Monday / ISO. |
|
|
77
|
+
| `isSameISOWeekYear(a, b)` | Compares the ISO-8601 week-numbering year. |
|
|
74
78
|
| `isSameHour(a, b)` | Checks full date + hour. |
|
|
75
79
|
| `isSameMinute(a, b)` | Checks full date + hour + minute. |
|
|
76
80
|
| `isSameSecond(a, b)` | Checks full date + H:M:S. |
|
|
77
81
|
| `isSameTime(a, b)` | Checks H:M:S only — ignores the calendar date entirely. |
|
|
78
82
|
| `isBefore(date, compareDate)` | Strict millisecond comparison. |
|
|
79
83
|
| `isAfter(date, compareDate)` | Strict millisecond comparison. |
|
|
84
|
+
| `isSameOrBefore(date, compareDate)` | Inclusive boundary check. |
|
|
85
|
+
| `isSameOrAfter(date, compareDate)` | Inclusive boundary check. |
|
|
80
86
|
| `isEqual(a, b)` | Fixes native `Date` object-reference inequality by comparing timestamps. |
|
|
81
87
|
| `compareAsc(left, right)` | Array sort comparator: returns `-1`, `0`, or `1`. |
|
|
82
88
|
| `compareDesc(left, right)` | Reverse array sort comparator: returns `1`, `0`, or `-1`. |
|
|
@@ -115,6 +121,8 @@ Date arithmetic, field setters, period snapping, difference calculations, and ra
|
|
|
115
121
|
| `addWeeks` / `subWeeks` | Delegates to `addDays(date, amount * 7)`. |
|
|
116
122
|
| `addMonths` / `subMonths` | End-of-month clamped: `addMonths(Jan 31, 1)` → Feb 28, not Mar 3. |
|
|
117
123
|
| `addYears` / `subYears` | Leap-year clamped: `addYears(Feb 29 2024, 1)` → Feb 28 2025. |
|
|
124
|
+
| `add` / `sub` | Applies a complex `Duration` object (e.g. `{ months: 1, days: 5 }`). Processes largest-to-smallest units to prevent drift. |
|
|
125
|
+
| `nextDay` / `previousDay` | Skips forward/backward to the next/previous occurrence of a specific weekday (0-6). |
|
|
118
126
|
|
|
119
127
|
**Set** (same overflow-clamping guarantees as their `add` counterparts)
|
|
120
128
|
|
|
@@ -127,6 +135,8 @@ Date arithmetic, field setters, period snapping, difference calculations, and ra
|
|
|
127
135
|
| `setMinutes(date, minutes)` | |
|
|
128
136
|
| `setSeconds(date, seconds)` | |
|
|
129
137
|
| `setMilliseconds(date, ms)` | |
|
|
138
|
+
| `set(date, values)` | Updates multiple fields at once via a `DateValues` object. |
|
|
139
|
+
| `setDay(date, dayOfWeek, options?)` | Sets the day of the week *within the current week*. |
|
|
130
140
|
|
|
131
141
|
**Start / End of Period**
|
|
132
142
|
|
|
@@ -187,8 +197,12 @@ Date arithmetic, field setters, period snapping, difference calculations, and ra
|
|
|
187
197
|
| Function | Notes |
|
|
188
198
|
| --- | --- |
|
|
189
199
|
| `roundToNearestMinutes(date, step)` | Snaps to the nearest multiple of `step` minutes. |
|
|
200
|
+
| `roundToNearestHours(date, step)` | Snaps to the nearest multiple of `step` hours. |
|
|
190
201
|
| `getISOWeek(date)` | ISO-8601 week number (1–53); Week 1 contains the year's first Thursday. |
|
|
191
202
|
| `setISOWeek(date, week)` | Shifts the date to the same weekday within the target ISO week. |
|
|
203
|
+
| `getISOWeekYear(date)` | The ISO week-numbering year. |
|
|
204
|
+
| `getISOWeeksInYear(date)` | Total ISO weeks in the given date's year (52 or 53). |
|
|
205
|
+
| `startOfISOWeekYear` / `endOfISOWeekYear` | The exact start/end boundary of the ISO year. |
|
|
192
206
|
|
|
193
207
|
**Duration**
|
|
194
208
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export declare function add(date: DateInput, duration: Duration): Date;
|
|
2
|
+
|
|
1
3
|
export declare function addBusinessDays(date: DateInput, amount: number): Date;
|
|
2
4
|
|
|
3
5
|
export declare function addDays(date: DateInput, amount: number): Date;
|
|
@@ -38,6 +40,16 @@ declare type DateRange = {
|
|
|
38
40
|
end: Date;
|
|
39
41
|
};
|
|
40
42
|
|
|
43
|
+
declare type DateValues = {
|
|
44
|
+
year?: number;
|
|
45
|
+
month?: number;
|
|
46
|
+
date?: number;
|
|
47
|
+
hours?: number;
|
|
48
|
+
minutes?: number;
|
|
49
|
+
seconds?: number;
|
|
50
|
+
milliseconds?: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
41
53
|
export declare function differenceInBusinessDays(dateLeft: DateInput, dateRight: DateInput): number;
|
|
42
54
|
|
|
43
55
|
export declare function differenceInDays(dateLeft: DateInput, dateRight: DateInput): number;
|
|
@@ -84,6 +96,8 @@ export declare function endOfDay(date: DateInput): Date;
|
|
|
84
96
|
|
|
85
97
|
export declare function endOfHour(date: DateInput): Date;
|
|
86
98
|
|
|
99
|
+
export declare function endOfISOWeekYear(date: DateInput): Date;
|
|
100
|
+
|
|
87
101
|
export declare function endOfMinute(date: DateInput): Date;
|
|
88
102
|
|
|
89
103
|
export declare function endOfMonth(date: DateInput): Date;
|
|
@@ -108,12 +122,12 @@ export declare function formatDuration(duration: Duration, options?: {
|
|
|
108
122
|
}): string;
|
|
109
123
|
|
|
110
124
|
export declare function formatISO(date: DateInput, options?: {
|
|
111
|
-
format?:
|
|
112
|
-
representation?:
|
|
125
|
+
format?: "extended" | "basic";
|
|
126
|
+
representation?: "complete" | "date" | "time";
|
|
113
127
|
}): string;
|
|
114
128
|
|
|
115
129
|
export declare function formatISO9075(date: DateInput, options?: {
|
|
116
|
-
representation?:
|
|
130
|
+
representation?: "complete" | "date" | "time";
|
|
117
131
|
}): string;
|
|
118
132
|
|
|
119
133
|
export declare function formatRelativeTime(date: DateInput, baseDate?: DateInput, locale?: string | string[]): string;
|
|
@@ -134,10 +148,16 @@ export declare function getDayOfYear(date: DateInput): number;
|
|
|
134
148
|
|
|
135
149
|
export declare function getDaysInMonth(date: DateInput): number;
|
|
136
150
|
|
|
151
|
+
export declare function getDaysInYear(date: DateInput): number;
|
|
152
|
+
|
|
137
153
|
export declare function getHours(date: DateInput): number;
|
|
138
154
|
|
|
139
155
|
export declare function getISOWeek(date: DateInput): number;
|
|
140
156
|
|
|
157
|
+
export declare function getISOWeeksInYear(date: DateInput): number;
|
|
158
|
+
|
|
159
|
+
export declare function getISOWeekYear(date: DateInput): number;
|
|
160
|
+
|
|
141
161
|
export declare function getMilliseconds(date: DateInput): number;
|
|
142
162
|
|
|
143
163
|
export declare function getMinutes(date: DateInput): number;
|
|
@@ -152,6 +172,10 @@ export declare function getSeconds(date: DateInput): number;
|
|
|
152
172
|
|
|
153
173
|
export declare function getTimestamp(date: DateInput): number;
|
|
154
174
|
|
|
175
|
+
export declare function getWeekOfMonth(date: DateInput, weekStartsOn?: WeekStartsOn): number;
|
|
176
|
+
|
|
177
|
+
export declare function getWeeksInMonth(date: DateInput, weekStartsOn?: WeekStartsOn): number;
|
|
178
|
+
|
|
155
179
|
export declare function getYear(date: DateInput): number;
|
|
156
180
|
|
|
157
181
|
export declare function intervalToDuration(interval: DateInterval): Duration;
|
|
@@ -186,10 +210,16 @@ export declare function isSameDay(dateA: DateInput, dateB: DateInput): boolean;
|
|
|
186
210
|
|
|
187
211
|
export declare function isSameHour(dateA: DateInput, dateB: DateInput): boolean;
|
|
188
212
|
|
|
213
|
+
export declare function isSameISOWeekYear(dateA: DateInput, dateB: DateInput): boolean;
|
|
214
|
+
|
|
189
215
|
export declare function isSameMinute(dateA: DateInput, dateB: DateInput): boolean;
|
|
190
216
|
|
|
191
217
|
export declare function isSameMonth(dateA: DateInput, dateB: DateInput): boolean;
|
|
192
218
|
|
|
219
|
+
export declare function isSameOrAfter(date: DateInput, compareDate: DateInput): boolean;
|
|
220
|
+
|
|
221
|
+
export declare function isSameOrBefore(date: DateInput, compareDate: DateInput): boolean;
|
|
222
|
+
|
|
193
223
|
export declare function isSameQuarter(dateA: DateInput, dateB: DateInput): boolean;
|
|
194
224
|
|
|
195
225
|
export declare function isSameSecond(dateA: DateInput, dateB: DateInput): boolean;
|
|
@@ -224,12 +254,24 @@ export declare function max(dates: Date[]): Date | null;
|
|
|
224
254
|
|
|
225
255
|
export declare function min(dates: Date[]): Date | null;
|
|
226
256
|
|
|
257
|
+
export declare function nextDay(date: DateInput, dayOfWeek: number): Date;
|
|
258
|
+
|
|
227
259
|
export declare function parseISO(isoString: string): Date;
|
|
228
260
|
|
|
261
|
+
export declare function previousDay(date: DateInput, dayOfWeek: number): Date;
|
|
262
|
+
|
|
263
|
+
export declare function roundToNearestHours(date: DateInput, step?: number): Date;
|
|
264
|
+
|
|
229
265
|
export declare function roundToNearestMinutes(date: DateInput, step: number): Date;
|
|
230
266
|
|
|
267
|
+
export declare function set(date: DateInput, values: DateValues): Date;
|
|
268
|
+
|
|
231
269
|
export declare function setDate(date: DateInput, day: number): Date;
|
|
232
270
|
|
|
271
|
+
export declare function setDay(date: DateInput, dayOfWeek: number, options?: {
|
|
272
|
+
weekStartsOn?: WeekStartsOn;
|
|
273
|
+
}): Date;
|
|
274
|
+
|
|
233
275
|
export declare function setHours(date: DateInput, hours: number): Date;
|
|
234
276
|
|
|
235
277
|
export declare function setISOWeek(date: DateInput, week: number): Date;
|
|
@@ -248,6 +290,8 @@ export declare function startOfDay(date: DateInput): Date;
|
|
|
248
290
|
|
|
249
291
|
export declare function startOfHour(date: DateInput): Date;
|
|
250
292
|
|
|
293
|
+
export declare function startOfISOWeekYear(date: DateInput): Date;
|
|
294
|
+
|
|
251
295
|
export declare function startOfMinute(date: DateInput): Date;
|
|
252
296
|
|
|
253
297
|
export declare function startOfMonth(date: DateInput): Date;
|
|
@@ -258,6 +302,8 @@ export declare function startOfWeek(date: DateInput, weekStartsOn?: WeekStartsOn
|
|
|
258
302
|
|
|
259
303
|
export declare function startOfYear(date: DateInput): Date;
|
|
260
304
|
|
|
305
|
+
export declare function sub(date: DateInput, duration: Duration): Date;
|
|
306
|
+
|
|
261
307
|
export declare function subDays(date: DateInput, amount: number): Date;
|
|
262
308
|
|
|
263
309
|
export declare function subHours(date: DateInput, amount: number): Date;
|
package/dist/index.js
CHANGED
|
@@ -50,40 +50,48 @@ function h(t) {
|
|
|
50
50
|
let n = e(t), r = new Date(n.getFullYear(), 0, 1, 0, 0, 0, 0), i = new Date(n.getFullYear(), n.getMonth(), n.getDate(), 0, 0, 0, 0);
|
|
51
51
|
return Math.round((i.getTime() - r.getTime()) / 864e5) + 1;
|
|
52
52
|
}
|
|
53
|
+
function g(t) {
|
|
54
|
+
let r = e(t);
|
|
55
|
+
if (!n(r)) return NaN;
|
|
56
|
+
let i = r.getFullYear();
|
|
57
|
+
return i % 400 == 0 || i % 4 == 0 && i % 100 != 0 ? 366 : 365;
|
|
58
|
+
}
|
|
53
59
|
//#endregion
|
|
54
60
|
//#region src/manipulation.ts
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
function _(t, n) {
|
|
59
|
-
return new Date(e(t).getTime() + n * V);
|
|
61
|
+
function _(t, r) {
|
|
62
|
+
let i = e(t);
|
|
63
|
+
return n(i) ? (r.years && (i = T(i, r.years)), r.months && (i = w(i, r.months)), r.weeks && (i = C(i, r.weeks)), r.days && (i = S(i, r.days)), r.hours && (i = x(i, r.hours)), r.minutes && (i = b(i, r.minutes)), r.seconds && (i = y(i, r.seconds)), i) : /* @__PURE__ */ new Date(NaN);
|
|
60
64
|
}
|
|
61
65
|
function v(t, n) {
|
|
62
|
-
return new Date(e(t).getTime() + n
|
|
66
|
+
return new Date(e(t).getTime() + n);
|
|
63
67
|
}
|
|
64
68
|
function y(t, n) {
|
|
65
|
-
return new Date(e(t).getTime() + n *
|
|
69
|
+
return new Date(e(t).getTime() + n * J);
|
|
66
70
|
}
|
|
67
71
|
function b(t, n) {
|
|
72
|
+
return new Date(e(t).getTime() + n * Y);
|
|
73
|
+
}
|
|
74
|
+
function x(t, n) {
|
|
75
|
+
return new Date(e(t).getTime() + n * X);
|
|
76
|
+
}
|
|
77
|
+
function S(t, n) {
|
|
68
78
|
let r = e(t);
|
|
69
79
|
return r.setDate(r.getDate() + n), r;
|
|
70
80
|
}
|
|
71
|
-
function
|
|
72
|
-
return
|
|
81
|
+
function C(e, t) {
|
|
82
|
+
return S(e, t * 7);
|
|
73
83
|
}
|
|
74
|
-
function
|
|
84
|
+
function w(t, n) {
|
|
75
85
|
let r = e(t), i = r.getDate();
|
|
76
86
|
return r.setDate(1), r.setMonth(r.getMonth() + n), r.setDate(Math.min(i, p(r))), r;
|
|
77
87
|
}
|
|
78
|
-
function
|
|
88
|
+
function T(t, n) {
|
|
79
89
|
let r = e(t), i = r.getMonth();
|
|
80
90
|
return r.setFullYear(r.getFullYear() + n), r.getMonth() !== i && r.setDate(0), r;
|
|
81
91
|
}
|
|
82
|
-
function
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
function ee(e, t) {
|
|
86
|
-
return _(e, -t);
|
|
92
|
+
function ee(t, r) {
|
|
93
|
+
let i = e(t);
|
|
94
|
+
return n(i) ? (r.years && (i = k(i, r.years)), r.months && (i = O(i, r.months)), r.weeks && (i = D(i, r.weeks)), r.days && (i = E(i, r.days)), r.hours && (i = ie(i, r.hours)), r.minutes && (i = re(i, r.minutes)), r.seconds && (i = ne(i, r.seconds)), i) : /* @__PURE__ */ new Date(NaN);
|
|
87
95
|
}
|
|
88
96
|
function te(e, t) {
|
|
89
97
|
return v(e, -t);
|
|
@@ -97,29 +105,45 @@ function re(e, t) {
|
|
|
97
105
|
function ie(e, t) {
|
|
98
106
|
return x(e, -t);
|
|
99
107
|
}
|
|
100
|
-
function
|
|
108
|
+
function E(e, t) {
|
|
101
109
|
return S(e, -t);
|
|
102
110
|
}
|
|
103
|
-
function
|
|
111
|
+
function D(e, t) {
|
|
104
112
|
return C(e, -t);
|
|
105
113
|
}
|
|
114
|
+
function O(e, t) {
|
|
115
|
+
return w(e, -t);
|
|
116
|
+
}
|
|
117
|
+
function k(e, t) {
|
|
118
|
+
return T(e, -t);
|
|
119
|
+
}
|
|
120
|
+
function ae(t, r) {
|
|
121
|
+
let i = e(t);
|
|
122
|
+
return n(i) ? (r.year !== void 0 && (i = se(i, r.year)), r.month !== void 0 && (i = ce(i, r.month)), r.date !== void 0 && (i = le(i, r.date)), r.hours !== void 0 && (i = ue(i, r.hours)), r.minutes !== void 0 && (i = A(i, r.minutes)), r.seconds !== void 0 && (i = de(i, r.seconds)), r.milliseconds !== void 0 && (i = j(i, r.milliseconds)), i) : /* @__PURE__ */ new Date(NaN);
|
|
123
|
+
}
|
|
124
|
+
function oe(t, r, i) {
|
|
125
|
+
let a = e(t);
|
|
126
|
+
if (!n(a)) return /* @__PURE__ */ new Date(NaN);
|
|
127
|
+
let o = i?.weekStartsOn ?? 0, s = a.getDay();
|
|
128
|
+
return S(a, (r < o ? 7 : 0) + r - (s < o ? 7 : 0) - s);
|
|
129
|
+
}
|
|
106
130
|
function se(t, n) {
|
|
107
131
|
let r = e(t), i = r.getMonth();
|
|
108
132
|
return r.setFullYear(n), r.getMonth() !== i && r.setDate(0), r;
|
|
109
133
|
}
|
|
110
|
-
function
|
|
134
|
+
function ce(t, n) {
|
|
111
135
|
let r = e(t), i = r.getDate();
|
|
112
136
|
return r.setDate(1), r.setMonth(n - 1), r.setDate(Math.min(i, p(r))), r;
|
|
113
137
|
}
|
|
114
|
-
function
|
|
138
|
+
function le(t, n) {
|
|
115
139
|
let r = e(t), i = p(r);
|
|
116
140
|
return r.setDate(Math.min(Math.max(1, n), i)), r;
|
|
117
141
|
}
|
|
118
|
-
function
|
|
142
|
+
function ue(t, n) {
|
|
119
143
|
let r = e(t);
|
|
120
144
|
return r.setHours(n), r;
|
|
121
145
|
}
|
|
122
|
-
function
|
|
146
|
+
function A(t, n) {
|
|
123
147
|
let r = e(t);
|
|
124
148
|
return r.setMinutes(n), r;
|
|
125
149
|
}
|
|
@@ -127,50 +151,62 @@ function de(t, n) {
|
|
|
127
151
|
let r = e(t);
|
|
128
152
|
return r.setSeconds(n), r;
|
|
129
153
|
}
|
|
130
|
-
function
|
|
154
|
+
function j(t, n) {
|
|
131
155
|
let r = e(t);
|
|
132
156
|
return r.setMilliseconds(n), r;
|
|
133
157
|
}
|
|
134
|
-
function
|
|
158
|
+
function M(t) {
|
|
135
159
|
let n = e(t);
|
|
136
160
|
return n.setHours(0, 0, 0, 0), n;
|
|
137
161
|
}
|
|
138
|
-
function
|
|
162
|
+
function fe(t) {
|
|
139
163
|
let n = e(t);
|
|
140
164
|
return n.setHours(23, 59, 59, 999), n;
|
|
141
165
|
}
|
|
142
|
-
function
|
|
166
|
+
function N(t) {
|
|
143
167
|
let n = e(t);
|
|
144
168
|
return n.setMinutes(0, 0, 0), n;
|
|
145
169
|
}
|
|
146
|
-
function
|
|
170
|
+
function pe(t) {
|
|
147
171
|
let n = e(t);
|
|
148
172
|
return n.setMinutes(59, 59, 999), n;
|
|
149
173
|
}
|
|
150
|
-
function
|
|
174
|
+
function P(t) {
|
|
151
175
|
let n = e(t);
|
|
152
176
|
return n.setSeconds(0, 0), n;
|
|
153
177
|
}
|
|
154
|
-
function
|
|
178
|
+
function me(t) {
|
|
155
179
|
let n = e(t);
|
|
156
180
|
return n.setSeconds(59, 999), n;
|
|
157
181
|
}
|
|
158
|
-
function
|
|
182
|
+
function F(t, n = 0) {
|
|
159
183
|
let r = e(t), i = (r.getDay() - n + 7) % 7;
|
|
160
184
|
return r.setDate(r.getDate() - i), r.setHours(0, 0, 0, 0), r;
|
|
161
185
|
}
|
|
162
|
-
function
|
|
163
|
-
let n =
|
|
186
|
+
function he(e, t = 0) {
|
|
187
|
+
let n = F(e, t);
|
|
164
188
|
return n.setDate(n.getDate() + 6), n.setHours(23, 59, 59, 999), n;
|
|
165
189
|
}
|
|
166
|
-
function
|
|
190
|
+
function I(t) {
|
|
167
191
|
let n = e(t);
|
|
168
192
|
return n.setDate(1), n.setHours(0, 0, 0, 0), n;
|
|
169
193
|
}
|
|
170
|
-
function
|
|
194
|
+
function L(t) {
|
|
171
195
|
let n = e(t);
|
|
172
196
|
return new Date(n.getFullYear(), n.getMonth() + 1, 0, 23, 59, 59, 999);
|
|
173
197
|
}
|
|
198
|
+
function ge(t, r = 0) {
|
|
199
|
+
let i = e(t);
|
|
200
|
+
if (!n(i)) return NaN;
|
|
201
|
+
let a = F(I(i), r), o = Math.round((M(i).getTime() - a.getTime()) / Z);
|
|
202
|
+
return Math.trunc(o / 7) + 1;
|
|
203
|
+
}
|
|
204
|
+
function _e(t, r = 0) {
|
|
205
|
+
let i = e(t);
|
|
206
|
+
if (!n(i)) return NaN;
|
|
207
|
+
let a = I(i), o = L(i), s = F(a, r), c = F(o, r), l = Math.round((c.getTime() - s.getTime()) / Z);
|
|
208
|
+
return Math.trunc(l / 7) + 1;
|
|
209
|
+
}
|
|
174
210
|
function ve(t) {
|
|
175
211
|
let n = e(t), r = n.getMonth() - n.getMonth() % 3;
|
|
176
212
|
return new Date(n.getFullYear(), r, 1, 0, 0, 0, 0);
|
|
@@ -179,42 +215,54 @@ function ye(t) {
|
|
|
179
215
|
let n = e(t), r = n.getMonth() - n.getMonth() % 3 + 2;
|
|
180
216
|
return new Date(n.getFullYear(), r + 1, 0, 23, 59, 59, 999);
|
|
181
217
|
}
|
|
182
|
-
function
|
|
218
|
+
function R(t) {
|
|
183
219
|
let n = e(t);
|
|
184
220
|
return new Date(n.getFullYear(), 0, 1, 0, 0, 0, 0);
|
|
185
221
|
}
|
|
186
|
-
function
|
|
222
|
+
function be(t) {
|
|
187
223
|
let n = e(t);
|
|
188
224
|
return new Date(n.getFullYear(), 11, 31, 23, 59, 59, 999);
|
|
189
225
|
}
|
|
190
|
-
function
|
|
226
|
+
function z(t, n) {
|
|
191
227
|
return e(t).getTime() - e(n).getTime();
|
|
192
228
|
}
|
|
193
|
-
function
|
|
194
|
-
return Math.trunc(
|
|
229
|
+
function B(e, t) {
|
|
230
|
+
return Math.trunc(z(e, t) / J);
|
|
195
231
|
}
|
|
196
|
-
function
|
|
197
|
-
return Math.trunc(
|
|
232
|
+
function V(e, t) {
|
|
233
|
+
return Math.trunc(z(e, t) / Y);
|
|
198
234
|
}
|
|
199
|
-
function
|
|
200
|
-
return Math.trunc(
|
|
235
|
+
function H(e, t) {
|
|
236
|
+
return Math.trunc(z(e, t) / X);
|
|
201
237
|
}
|
|
202
|
-
function
|
|
203
|
-
let r =
|
|
204
|
-
return Math.round((r.getTime() - i.getTime()) /
|
|
238
|
+
function U(t, n) {
|
|
239
|
+
let r = M(e(t)), i = M(e(n));
|
|
240
|
+
return Math.round((r.getTime() - i.getTime()) / Z);
|
|
205
241
|
}
|
|
206
|
-
function
|
|
207
|
-
return Math.trunc(
|
|
242
|
+
function xe(e, t) {
|
|
243
|
+
return Math.trunc(U(e, t) / 7);
|
|
208
244
|
}
|
|
209
|
-
function
|
|
210
|
-
let r = e(t), i = e(n), a = r.getFullYear() - i.getFullYear(), o = r.getMonth() - i.getMonth(), s = a * 12 + o, c =
|
|
245
|
+
function W(t, n) {
|
|
246
|
+
let r = e(t), i = e(n), a = r.getFullYear() - i.getFullYear(), o = r.getMonth() - i.getMonth(), s = a * 12 + o, c = w(i, s);
|
|
211
247
|
return s > 0 && c.getTime() > r.getTime() ? s - 1 : s < 0 && c.getTime() < r.getTime() ? s + 1 : s;
|
|
212
248
|
}
|
|
213
|
-
function
|
|
214
|
-
let r = e(t), i = e(n), a = r.getFullYear() - i.getFullYear(), o =
|
|
249
|
+
function G(t, n) {
|
|
250
|
+
let r = e(t), i = e(n), a = r.getFullYear() - i.getFullYear(), o = T(i, a);
|
|
215
251
|
return a > 0 && o.getTime() > r.getTime() ? a - 1 : a < 0 && o.getTime() < r.getTime() ? a + 1 : a;
|
|
216
252
|
}
|
|
217
|
-
function
|
|
253
|
+
function Se(t, r) {
|
|
254
|
+
let i = e(t);
|
|
255
|
+
if (!n(i)) return /* @__PURE__ */ new Date(NaN);
|
|
256
|
+
let a = i.getDay(), o = (r < a ? 7 : 0) + r - a;
|
|
257
|
+
return S(i, o === 0 ? 7 : o);
|
|
258
|
+
}
|
|
259
|
+
function Ce(t, r) {
|
|
260
|
+
let i = e(t);
|
|
261
|
+
if (!n(i)) return /* @__PURE__ */ new Date(NaN);
|
|
262
|
+
let a = i.getDay();
|
|
263
|
+
return E(i, a - r + (a <= r ? 7 : 0));
|
|
264
|
+
}
|
|
265
|
+
function we(t, n) {
|
|
218
266
|
let r = e(t), i = n < 0 ? -1 : 1, a = Math.abs(n);
|
|
219
267
|
for (; a > 0;) {
|
|
220
268
|
r.setDate(r.getDate() + i);
|
|
@@ -223,8 +271,8 @@ function xe(t, n) {
|
|
|
223
271
|
}
|
|
224
272
|
return r;
|
|
225
273
|
}
|
|
226
|
-
function
|
|
227
|
-
let r =
|
|
274
|
+
function Te(t, n) {
|
|
275
|
+
let r = M(e(t)), i = M(e(n)), a = U(r, i);
|
|
228
276
|
if (a === 0) return 0;
|
|
229
277
|
let o = a > 0 ? 1 : -1, s = Math.abs(a), c = Math.floor(s / 7) * 5, l = new Date(i);
|
|
230
278
|
for (let e = 0; e < s % 7; e++) {
|
|
@@ -234,99 +282,129 @@ function Se(t, n) {
|
|
|
234
282
|
}
|
|
235
283
|
return c * o;
|
|
236
284
|
}
|
|
237
|
-
function
|
|
285
|
+
function Ee(t, r, i) {
|
|
238
286
|
let a = e(t), o = e(r), s = e(i);
|
|
239
287
|
return !n(a) || !n(o) || !n(s) ? /* @__PURE__ */ new Date(NaN) : a.getTime() < o.getTime() ? o : a.getTime() > s.getTime() ? s : a;
|
|
240
288
|
}
|
|
241
|
-
function
|
|
289
|
+
function De(e) {
|
|
242
290
|
return e.length === 0 ? null : new Date(Math.min(...e.map((e) => e.getTime())));
|
|
243
291
|
}
|
|
244
|
-
function
|
|
292
|
+
function Oe(e) {
|
|
245
293
|
return e.length === 0 ? null : new Date(Math.max(...e.map((e) => e.getTime())));
|
|
246
294
|
}
|
|
247
|
-
function
|
|
295
|
+
function ke(t, r) {
|
|
248
296
|
if (r.length === 0) return null;
|
|
249
297
|
let i = e(t);
|
|
250
298
|
if (!n(i)) return /* @__PURE__ */ new Date(NaN);
|
|
251
299
|
let a = i.getTime();
|
|
252
300
|
return r.reduce((e, t) => n(t) && Math.abs(t.getTime() - a) < Math.abs(e.getTime() - a) ? t : e);
|
|
253
301
|
}
|
|
254
|
-
function
|
|
255
|
-
let r = [], i =
|
|
302
|
+
function Ae(t, n = 1) {
|
|
303
|
+
let r = [], i = P(e(t.start)), a = P(e(t.end)), o = new Date(i), s = Math.trunc(n);
|
|
256
304
|
if (s < 1 || Number.isNaN(s)) return r;
|
|
257
305
|
for (; o.getTime() <= a.getTime();) r.push(new Date(o)), o.setMinutes(o.getMinutes() + s);
|
|
258
306
|
return r;
|
|
259
307
|
}
|
|
260
|
-
function
|
|
261
|
-
let r = [], i =
|
|
308
|
+
function je(t, n = 1) {
|
|
309
|
+
let r = [], i = N(e(t.start)), a = N(e(t.end)), o = new Date(i), s = Math.trunc(n);
|
|
262
310
|
if (s < 1 || Number.isNaN(s)) return r;
|
|
263
311
|
for (; o.getTime() <= a.getTime();) r.push(new Date(o)), o.setHours(o.getHours() + s);
|
|
264
312
|
return r;
|
|
265
313
|
}
|
|
266
|
-
function
|
|
267
|
-
let n = [], r =
|
|
314
|
+
function Me(t) {
|
|
315
|
+
let n = [], r = M(e(t.start)), i = M(e(t.end)), a = new Date(r);
|
|
268
316
|
for (; a.getTime() <= i.getTime();) n.push(new Date(a)), a.setDate(a.getDate() + 1);
|
|
269
317
|
return n;
|
|
270
318
|
}
|
|
271
|
-
function
|
|
272
|
-
let r = [], i =
|
|
319
|
+
function Ne(t, n = 0) {
|
|
320
|
+
let r = [], i = F(e(t.start), n), a = F(e(t.end), n), o = new Date(i);
|
|
273
321
|
for (; o.getTime() <= a.getTime();) r.push(new Date(o)), o.setDate(o.getDate() + 7);
|
|
274
322
|
return r;
|
|
275
323
|
}
|
|
276
|
-
function
|
|
277
|
-
let n = [], r =
|
|
324
|
+
function Pe(t) {
|
|
325
|
+
let n = [], r = I(e(t.start)), i = I(e(t.end)), a = new Date(r);
|
|
278
326
|
for (; a.getTime() <= i.getTime();) n.push(new Date(a)), a.setMonth(a.getMonth() + 1);
|
|
279
327
|
return n;
|
|
280
328
|
}
|
|
281
|
-
function
|
|
282
|
-
let n = [], r =
|
|
329
|
+
function Fe(t) {
|
|
330
|
+
let n = [], r = R(e(t.start)), i = R(e(t.end)), a = new Date(r);
|
|
283
331
|
for (; a.getTime() <= i.getTime();) n.push(new Date(a)), a.setFullYear(a.getFullYear() + 1);
|
|
284
332
|
return n;
|
|
285
333
|
}
|
|
286
|
-
function
|
|
334
|
+
function Ie(e) {
|
|
287
335
|
return /* @__PURE__ */ new Date(e * 1e3);
|
|
288
336
|
}
|
|
289
|
-
function
|
|
337
|
+
function Le(t) {
|
|
290
338
|
return Math.floor(e(t).getTime() / 1e3);
|
|
291
339
|
}
|
|
292
|
-
function
|
|
293
|
-
let r = n *
|
|
340
|
+
function Re(t, n) {
|
|
341
|
+
let r = n * Y;
|
|
294
342
|
return new Date(Math.round(e(t).getTime() / r) * r);
|
|
295
343
|
}
|
|
296
|
-
function
|
|
344
|
+
function ze(t, r = 1) {
|
|
345
|
+
let i = e(t);
|
|
346
|
+
if (!n(i)) return /* @__PURE__ */ new Date(NaN);
|
|
347
|
+
let a = i.getHours(), o = i.getMinutes(), s = i.getMilliseconds() + i.getSeconds() * J + o * Y, c = X * r / 2, l = Math.trunc(a / r) * r, u = a % r * 36e5 + s >= c ? l + r : l, d = new Date(i.getTime());
|
|
348
|
+
return d.setHours(u, 0, 0, 0), d;
|
|
349
|
+
}
|
|
350
|
+
function K(t) {
|
|
297
351
|
let n = e(t), r = n.getDay() || 7;
|
|
298
352
|
n.setDate(n.getDate() + 4 - r);
|
|
299
353
|
let i = new Date(n.getFullYear(), 0, 1);
|
|
300
|
-
return Math.ceil(((n.getTime() - i.getTime()) /
|
|
354
|
+
return Math.ceil(((n.getTime() - i.getTime()) / Z + 1) / 7);
|
|
301
355
|
}
|
|
302
|
-
function
|
|
303
|
-
let r = e(t), i =
|
|
356
|
+
function Be(t, n) {
|
|
357
|
+
let r = e(t), i = K(r);
|
|
304
358
|
return r.setDate(r.getDate() + (n - i) * 7), r;
|
|
305
359
|
}
|
|
306
|
-
function
|
|
307
|
-
let
|
|
360
|
+
function q(t) {
|
|
361
|
+
let r = e(t);
|
|
362
|
+
if (!n(r)) return NaN;
|
|
363
|
+
let i = r.getFullYear(), a = F(new Date(i, 0, 4), 1);
|
|
364
|
+
if (r.getTime() < a.getTime()) return i - 1;
|
|
365
|
+
let o = F(new Date(i + 1, 0, 4), 1);
|
|
366
|
+
return r.getTime() >= o.getTime() ? i + 1 : i;
|
|
367
|
+
}
|
|
368
|
+
function Ve(e) {
|
|
369
|
+
let t = q(e);
|
|
370
|
+
if (Number.isNaN(t)) return NaN;
|
|
371
|
+
let n = He(e), r = F(new Date(t + 1, 0, 4), 1), i = Math.round((r.getTime() - n.getTime()) / Z);
|
|
372
|
+
return Math.trunc(i / 7);
|
|
373
|
+
}
|
|
374
|
+
function He(e) {
|
|
375
|
+
let t = q(e);
|
|
376
|
+
return Number.isNaN(t) ? /* @__PURE__ */ new Date(NaN) : F(new Date(t, 0, 4), 1);
|
|
377
|
+
}
|
|
378
|
+
function Ue(e) {
|
|
379
|
+
let t = q(e);
|
|
380
|
+
if (Number.isNaN(t)) return /* @__PURE__ */ new Date(NaN);
|
|
381
|
+
let n = F(new Date(t + 1, 0, 4), 1);
|
|
382
|
+
return /* @__PURE__ */ new Date(n.getTime() - 1);
|
|
383
|
+
}
|
|
384
|
+
function We(t) {
|
|
385
|
+
let n = e(t.start), r = e(t.end), [i, a] = n.getTime() <= r.getTime() ? [n, r] : [r, n], o = G(a, i), s = T(i, o), c = W(a, s), l = w(s, c), u = U(a, l), d = S(l, u), f = H(a, d), p = x(d, f), m = V(a, p);
|
|
308
386
|
return {
|
|
309
387
|
years: o,
|
|
310
388
|
months: c,
|
|
311
389
|
days: u,
|
|
312
390
|
hours: f,
|
|
313
391
|
minutes: m,
|
|
314
|
-
seconds:
|
|
392
|
+
seconds: B(a, b(p, m))
|
|
315
393
|
};
|
|
316
394
|
}
|
|
317
|
-
function
|
|
318
|
-
let t = 365.25 *
|
|
319
|
-
return (e.years ?? 0) * t + (e.months ?? 0) * n + (e.weeks ?? 0) * 7 *
|
|
395
|
+
function Ge(e) {
|
|
396
|
+
let t = 365.25 * Z, n = 30.4375 * Z;
|
|
397
|
+
return (e.years ?? 0) * t + (e.months ?? 0) * n + (e.weeks ?? 0) * 7 * Z + (e.days ?? 0) * Z + (e.hours ?? 0) * X + (e.minutes ?? 0) * Y + (e.seconds ?? 0) * J;
|
|
320
398
|
}
|
|
321
|
-
function
|
|
399
|
+
function Ke(t, r) {
|
|
322
400
|
let i = e(t.start), a = e(t.end), o = e(r.start), s = e(r.end);
|
|
323
401
|
if (!n(i) || !n(a) || !n(o) || !n(s)) return NaN;
|
|
324
402
|
let c = i.getTime(), l = a.getTime(), u = o.getTime(), d = s.getTime(), [f, p] = c <= l ? [c, l] : [l, c], [m, h] = u <= d ? [u, d] : [d, u];
|
|
325
|
-
return f < h && p > m ? Math.ceil(((p > h ? h : p) - (f < m ? m : f)) /
|
|
403
|
+
return f < h && p > m ? Math.ceil(((p > h ? h : p) - (f < m ? m : f)) / Z) : 0;
|
|
326
404
|
}
|
|
327
405
|
//#endregion
|
|
328
406
|
//#region src/constants.ts
|
|
329
|
-
var
|
|
407
|
+
var J = 1e3, Y = 6e4, X = 36e5, Z = 864e5, qe = {
|
|
330
408
|
yyyy: (e) => String(e.getFullYear()).padStart(4, "0"),
|
|
331
409
|
yy: (e) => String(e.getFullYear()).slice(-2),
|
|
332
410
|
MMMM: (e, t) => new Intl.DateTimeFormat(t, { month: "long" }).format(e),
|
|
@@ -350,21 +428,21 @@ var V = 1e3, H = 6e4, U = 36e5, W = 864e5, G = {
|
|
|
350
428
|
hour12: !0
|
|
351
429
|
}).formatToParts(e).find((e) => e.type === "dayPeriod")?.value ?? "",
|
|
352
430
|
Q: (e) => String(Math.ceil((e.getMonth() + 1) / 3)),
|
|
353
|
-
w: (e) => String(
|
|
431
|
+
w: (e) => String(K(e)),
|
|
354
432
|
D: (e) => String(h(e)),
|
|
355
433
|
xxx: (e) => {
|
|
356
|
-
let t =
|
|
434
|
+
let t = Q(e);
|
|
357
435
|
return `${t.sign}${t.hours}:${t.minutes}`;
|
|
358
436
|
},
|
|
359
437
|
xx: (e) => {
|
|
360
|
-
let t =
|
|
438
|
+
let t = Q(e);
|
|
361
439
|
return `${t.sign}${t.hours}${t.minutes}`;
|
|
362
440
|
},
|
|
363
441
|
x: (e) => {
|
|
364
|
-
let t =
|
|
442
|
+
let t = Q(e);
|
|
365
443
|
return `${t.sign}${t.hours}`;
|
|
366
444
|
}
|
|
367
|
-
},
|
|
445
|
+
}, Je = RegExp("'[^']*'|" + Object.keys(qe).sort((e, t) => t.length - e.length).join("|"), "g"), Ye = [
|
|
368
446
|
"Sun",
|
|
369
447
|
"Mon",
|
|
370
448
|
"Tue",
|
|
@@ -372,7 +450,7 @@ var V = 1e3, H = 6e4, U = 36e5, W = 864e5, G = {
|
|
|
372
450
|
"Thu",
|
|
373
451
|
"Fri",
|
|
374
452
|
"Sat"
|
|
375
|
-
],
|
|
453
|
+
], Xe = [
|
|
376
454
|
"Jan",
|
|
377
455
|
"Feb",
|
|
378
456
|
"Mar",
|
|
@@ -385,7 +463,7 @@ var V = 1e3, H = 6e4, U = 36e5, W = 864e5, G = {
|
|
|
385
463
|
"Oct",
|
|
386
464
|
"Nov",
|
|
387
465
|
"Dec"
|
|
388
|
-
],
|
|
466
|
+
], Ze = [
|
|
389
467
|
"years",
|
|
390
468
|
"months",
|
|
391
469
|
"weeks",
|
|
@@ -393,7 +471,7 @@ var V = 1e3, H = 6e4, U = 36e5, W = 864e5, G = {
|
|
|
393
471
|
"hours",
|
|
394
472
|
"minutes",
|
|
395
473
|
"seconds"
|
|
396
|
-
],
|
|
474
|
+
], Qe = {
|
|
397
475
|
years: ["year", "years"],
|
|
398
476
|
months: ["month", "months"],
|
|
399
477
|
weeks: ["week", "weeks"],
|
|
@@ -401,10 +479,10 @@ var V = 1e3, H = 6e4, U = 36e5, W = 864e5, G = {
|
|
|
401
479
|
hours: ["hour", "hours"],
|
|
402
480
|
minutes: ["minute", "minutes"],
|
|
403
481
|
seconds: ["second", "seconds"]
|
|
404
|
-
},
|
|
482
|
+
}, $e = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
405
483
|
//#endregion
|
|
406
484
|
//#region src/internals.ts
|
|
407
|
-
function
|
|
485
|
+
function Q(e) {
|
|
408
486
|
let t = e.getTimezoneOffset(), n = t <= 0 ? "+" : "-", r = Math.abs(t);
|
|
409
487
|
return {
|
|
410
488
|
sign: n,
|
|
@@ -412,140 +490,152 @@ function q(e) {
|
|
|
412
490
|
minutes: String(r % 60).padStart(2, "0")
|
|
413
491
|
};
|
|
414
492
|
}
|
|
415
|
-
function
|
|
493
|
+
function et(e, t) {
|
|
416
494
|
let n = new Date(e), r = (n.getDay() - t + 7) % 7;
|
|
417
495
|
return n.setDate(n.getDate() - r), n.setHours(0, 0, 0, 0), n;
|
|
418
496
|
}
|
|
419
497
|
//#endregion
|
|
420
498
|
//#region src/queries.ts
|
|
421
|
-
function
|
|
499
|
+
function $(t, r) {
|
|
422
500
|
let i = e(t), a = e(r);
|
|
423
501
|
return !n(i) || !n(a) ? !1 : i.getFullYear() === a.getFullYear() && i.getMonth() === a.getMonth() && i.getDate() === a.getDate();
|
|
424
502
|
}
|
|
425
|
-
function
|
|
503
|
+
function tt(t, r) {
|
|
426
504
|
let i = e(t), a = e(r);
|
|
427
505
|
return !n(i) || !n(a) ? !1 : i.getFullYear() === a.getFullYear() && i.getMonth() === a.getMonth();
|
|
428
506
|
}
|
|
429
|
-
function
|
|
507
|
+
function nt(t, r) {
|
|
430
508
|
let i = e(t), a = e(r);
|
|
431
509
|
return !n(i) || !n(a) ? !1 : i.getFullYear() === a.getFullYear();
|
|
432
510
|
}
|
|
433
|
-
function
|
|
511
|
+
function rt(t, r) {
|
|
434
512
|
let i = e(t), a = e(r);
|
|
435
513
|
if (!n(i) || !n(a)) return !1;
|
|
436
514
|
let o = Math.ceil((i.getMonth() + 1) / 3), s = Math.ceil((a.getMonth() + 1) / 3);
|
|
437
515
|
return i.getFullYear() === a.getFullYear() && o === s;
|
|
438
516
|
}
|
|
439
|
-
function
|
|
517
|
+
function it(t, r, i = 0) {
|
|
440
518
|
let a = e(t), o = e(r);
|
|
441
|
-
return !n(a) || !n(o) ? !1 :
|
|
519
|
+
return !n(a) || !n(o) ? !1 : et(a, i).getTime() === et(o, i).getTime();
|
|
442
520
|
}
|
|
443
|
-
function
|
|
521
|
+
function at(t, r) {
|
|
444
522
|
let i = e(t), a = e(r);
|
|
445
523
|
return !n(i) || !n(a) ? !1 : i.getFullYear() === a.getFullYear() && i.getMonth() === a.getMonth() && i.getDate() === a.getDate() && i.getHours() === a.getHours();
|
|
446
524
|
}
|
|
447
|
-
function
|
|
525
|
+
function ot(t, r) {
|
|
448
526
|
let i = e(t), a = e(r);
|
|
449
527
|
return !n(i) || !n(a) ? !1 : i.getFullYear() === a.getFullYear() && i.getMonth() === a.getMonth() && i.getDate() === a.getDate() && i.getHours() === a.getHours() && i.getMinutes() === a.getMinutes();
|
|
450
528
|
}
|
|
451
|
-
function
|
|
529
|
+
function st(t, r) {
|
|
452
530
|
let i = e(t), a = e(r);
|
|
453
531
|
return !n(i) || !n(a) ? !1 : i.getFullYear() === a.getFullYear() && i.getMonth() === a.getMonth() && i.getDate() === a.getDate() && i.getHours() === a.getHours() && i.getMinutes() === a.getMinutes() && i.getSeconds() === a.getSeconds();
|
|
454
532
|
}
|
|
455
|
-
function
|
|
533
|
+
function ct(t, r) {
|
|
456
534
|
let i = e(t), a = e(r);
|
|
457
535
|
return !n(i) || !n(a) ? !1 : i.getHours() === a.getHours() && i.getMinutes() === a.getMinutes() && i.getSeconds() === a.getSeconds();
|
|
458
536
|
}
|
|
459
|
-
function
|
|
537
|
+
function lt(t, r) {
|
|
460
538
|
let i = e(t), a = e(r);
|
|
461
539
|
if (!n(i) || !n(a)) return NaN;
|
|
462
540
|
let o = i.getTime() - a.getTime();
|
|
463
541
|
return o < 0 ? -1 : +(o > 0);
|
|
464
542
|
}
|
|
465
|
-
function
|
|
543
|
+
function ut(t, r) {
|
|
466
544
|
let i = e(t), a = e(r);
|
|
467
545
|
if (!n(i) || !n(a)) return NaN;
|
|
468
546
|
let o = i.getTime() - a.getTime();
|
|
469
547
|
return o > 0 ? -1 : +(o < 0);
|
|
470
548
|
}
|
|
471
|
-
function
|
|
549
|
+
function dt(t, r) {
|
|
550
|
+
let i = e(t), a = e(r);
|
|
551
|
+
return !n(i) || !n(a) ? !1 : q(i) === q(a);
|
|
552
|
+
}
|
|
553
|
+
function ft(t, r) {
|
|
472
554
|
let i = e(t), a = e(r);
|
|
473
555
|
return !n(i) || !n(a) ? !1 : i.getTime() < a.getTime();
|
|
474
556
|
}
|
|
475
|
-
function
|
|
557
|
+
function pt(t, r) {
|
|
476
558
|
let i = e(t), a = e(r);
|
|
477
559
|
return !n(i) || !n(a) ? !1 : i.getTime() > a.getTime();
|
|
478
560
|
}
|
|
479
|
-
function
|
|
561
|
+
function mt(t, r) {
|
|
562
|
+
let i = e(t), a = e(r);
|
|
563
|
+
return !n(i) || !n(a) ? !1 : i.getTime() <= a.getTime();
|
|
564
|
+
}
|
|
565
|
+
function ht(t, r) {
|
|
566
|
+
let i = e(t), a = e(r);
|
|
567
|
+
return !n(i) || !n(a) ? !1 : i.getTime() >= a.getTime();
|
|
568
|
+
}
|
|
569
|
+
function gt(t, r) {
|
|
480
570
|
let i = e(t), a = e(r);
|
|
481
571
|
return !n(i) || !n(a) ? !1 : i.getTime() === a.getTime();
|
|
482
572
|
}
|
|
483
|
-
function
|
|
573
|
+
function _t(t, r, i) {
|
|
484
574
|
let a = e(t), o = e(r), s = e(i);
|
|
485
575
|
return !n(a) || !n(o) || !n(s) ? !1 : (o.getTime() > s.getTime() && ([o, s] = [s, o]), a.getTime() >= o.getTime() && a.getTime() <= s.getTime());
|
|
486
576
|
}
|
|
487
|
-
function
|
|
577
|
+
function vt(e, t) {
|
|
488
578
|
return !n(e.start) || !n(e.end) || !n(t.start) || !n(t.end) ? !1 : e.start.getTime() < t.end.getTime() && e.end.getTime() > t.start.getTime();
|
|
489
579
|
}
|
|
490
|
-
function
|
|
491
|
-
return
|
|
580
|
+
function yt(e) {
|
|
581
|
+
return $(e, /* @__PURE__ */ new Date());
|
|
492
582
|
}
|
|
493
|
-
function
|
|
583
|
+
function bt(e) {
|
|
494
584
|
let t = /* @__PURE__ */ new Date();
|
|
495
|
-
return t.setDate(t.getDate() - 1),
|
|
585
|
+
return t.setDate(t.getDate() - 1), $(e, t);
|
|
496
586
|
}
|
|
497
|
-
function
|
|
587
|
+
function xt(e) {
|
|
498
588
|
let t = /* @__PURE__ */ new Date();
|
|
499
|
-
return t.setDate(t.getDate() + 1),
|
|
589
|
+
return t.setDate(t.getDate() + 1), $(e, t);
|
|
500
590
|
}
|
|
501
|
-
function
|
|
591
|
+
function St(t) {
|
|
502
592
|
let r = e(t);
|
|
503
593
|
return n(r) ? r.getTime() < Date.now() : !1;
|
|
504
594
|
}
|
|
505
|
-
function
|
|
595
|
+
function Ct(t) {
|
|
506
596
|
let r = e(t);
|
|
507
597
|
return n(r) ? r.getTime() > Date.now() : !1;
|
|
508
598
|
}
|
|
509
|
-
function
|
|
510
|
-
return
|
|
599
|
+
function wt(e, t = 0) {
|
|
600
|
+
return it(e, /* @__PURE__ */ new Date(), t);
|
|
511
601
|
}
|
|
512
|
-
function
|
|
513
|
-
return
|
|
602
|
+
function Tt(e) {
|
|
603
|
+
return tt(e, /* @__PURE__ */ new Date());
|
|
514
604
|
}
|
|
515
|
-
function
|
|
516
|
-
return
|
|
605
|
+
function Et(e) {
|
|
606
|
+
return nt(e, /* @__PURE__ */ new Date());
|
|
517
607
|
}
|
|
518
|
-
function
|
|
608
|
+
function Dt(t) {
|
|
519
609
|
let r = e(t);
|
|
520
610
|
return n(r) ? r.getDate() === 1 : !1;
|
|
521
611
|
}
|
|
522
|
-
function
|
|
612
|
+
function Ot(t) {
|
|
523
613
|
let r = e(t);
|
|
524
614
|
if (!n(r)) return !1;
|
|
525
615
|
let i = new Date(r);
|
|
526
616
|
return i.setDate(i.getDate() + 1), i.getMonth() !== r.getMonth();
|
|
527
617
|
}
|
|
528
|
-
function
|
|
618
|
+
function kt(t) {
|
|
529
619
|
let r = e(t);
|
|
530
620
|
if (!n(r)) return !1;
|
|
531
621
|
let i = r.getDay();
|
|
532
622
|
return i === 0 || i === 6;
|
|
533
623
|
}
|
|
534
|
-
function
|
|
624
|
+
function At(t) {
|
|
535
625
|
let r = e(t);
|
|
536
626
|
if (!n(r)) return !1;
|
|
537
627
|
let i = r.getDay();
|
|
538
628
|
return i >= 1 && i <= 5;
|
|
539
629
|
}
|
|
540
|
-
function
|
|
630
|
+
function jt(t) {
|
|
541
631
|
let r = e(t);
|
|
542
632
|
return n(r) ? r.getHours() < 12 : !1;
|
|
543
633
|
}
|
|
544
|
-
function
|
|
634
|
+
function Mt(t) {
|
|
545
635
|
let r = e(t);
|
|
546
636
|
return n(r) ? r.getHours() >= 12 : !1;
|
|
547
637
|
}
|
|
548
|
-
function
|
|
638
|
+
function Nt(e) {
|
|
549
639
|
let t;
|
|
550
640
|
if (e instanceof Date) {
|
|
551
641
|
if (!n(e)) return !1;
|
|
@@ -553,78 +643,78 @@ function $(e) {
|
|
|
553
643
|
} else t = e;
|
|
554
644
|
return t % 4 == 0 && t % 100 != 0 || t % 400 == 0;
|
|
555
645
|
}
|
|
556
|
-
function
|
|
646
|
+
function Pt(t) {
|
|
557
647
|
let r = e(t);
|
|
558
|
-
return n(r) ?
|
|
648
|
+
return n(r) ? Nt(r.getFullYear()) : !1;
|
|
559
649
|
}
|
|
560
650
|
//#endregion
|
|
561
651
|
//#region src/format.ts
|
|
562
|
-
function
|
|
652
|
+
function Ft(t, r, i) {
|
|
563
653
|
let a = e(t);
|
|
564
654
|
if (!n(a)) return "Invalid Date";
|
|
565
655
|
let o = i?.locale ?? "default";
|
|
566
|
-
return r.replace(
|
|
656
|
+
return r.replace(Je, (e) => {
|
|
567
657
|
if (e.startsWith("'")) {
|
|
568
658
|
let t = e.slice(1, -1);
|
|
569
659
|
return t === "" ? "'" : t;
|
|
570
660
|
}
|
|
571
|
-
let t =
|
|
661
|
+
let t = qe[e];
|
|
572
662
|
return t(a, o);
|
|
573
663
|
});
|
|
574
664
|
}
|
|
575
|
-
function
|
|
665
|
+
function It(t, r = "default", i = {}) {
|
|
576
666
|
let a = e(t);
|
|
577
667
|
return n(a) ? new Intl.DateTimeFormat(r, i).format(a) : "Invalid Date";
|
|
578
668
|
}
|
|
579
|
-
function
|
|
669
|
+
function Lt(t, r = /* @__PURE__ */ new Date(), i = "default") {
|
|
580
670
|
let a = e(t), o = e(r);
|
|
581
671
|
if (!n(a) || !n(o)) return "Invalid Date";
|
|
582
|
-
let s = new Intl.RelativeTimeFormat(i, { numeric: "auto" }), c = Math.abs.bind(Math), l =
|
|
672
|
+
let s = new Intl.RelativeTimeFormat(i, { numeric: "auto" }), c = Math.abs.bind(Math), l = B(a, o), u = V(a, o), d = H(a, o), f = U(a, o), p = Math.trunc(f / 7), m = Math.round(f / 30.4375), h = Math.round(f / 365.25);
|
|
583
673
|
return c(l) < 60 ? s.format(l, "second") : c(u) < 60 ? s.format(u, "minute") : c(d) < 24 ? s.format(d, "hour") : c(f) < 7 ? s.format(f, "day") : c(p) < 4 ? s.format(p, "week") : c(m) < 12 ? s.format(m, "month") : s.format(h, "year");
|
|
584
674
|
}
|
|
585
|
-
function
|
|
675
|
+
function Rt(t, r) {
|
|
586
676
|
let i = e(t);
|
|
587
677
|
if (!n(i)) return "Invalid Date";
|
|
588
|
-
let a = r?.format ?? "extended", o = r?.representation ?? "complete", s = a === "extended" ? "-" : "", c = a === "extended" ? ":" : "", l = String(i.getFullYear()).padStart(4, "0"), u = String(i.getMonth() + 1).padStart(2, "0"), d = String(i.getDate()).padStart(2, "0"), f = String(i.getHours()).padStart(2, "0"), p = String(i.getMinutes()).padStart(2, "0"), m = String(i.getSeconds()).padStart(2, "0"), h =
|
|
678
|
+
let a = r?.format ?? "extended", o = r?.representation ?? "complete", s = a === "extended" ? "-" : "", c = a === "extended" ? ":" : "", l = String(i.getFullYear()).padStart(4, "0"), u = String(i.getMonth() + 1).padStart(2, "0"), d = String(i.getDate()).padStart(2, "0"), f = String(i.getHours()).padStart(2, "0"), p = String(i.getMinutes()).padStart(2, "0"), m = String(i.getSeconds()).padStart(2, "0"), h = Q(i), g = `${h.sign}${h.hours}${c}${h.minutes}`, _ = `${l}${s}${u}${s}${d}`, v = `${f}${c}${p}${c}${m}`;
|
|
589
679
|
return o === "date" ? _ : o === "time" ? `${v}${g}` : `${_}T${v}${g}`;
|
|
590
680
|
}
|
|
591
|
-
function
|
|
681
|
+
function zt(t, r) {
|
|
592
682
|
let i = e(t);
|
|
593
683
|
if (!n(i)) return "Invalid Date";
|
|
594
684
|
let a = r?.fractionDigits ?? 0;
|
|
595
685
|
return `${String(i.getFullYear()).padStart(4, "0")}-${String(i.getMonth() + 1).padStart(2, "0")}-${String(i.getDate()).padStart(2, "0")}T${String(i.getHours()).padStart(2, "0")}:${String(i.getMinutes()).padStart(2, "0")}:${String(i.getSeconds()).padStart(2, "0")}${a > 0 ? "." + String(i.getMilliseconds()).padStart(3, "0").slice(0, a) : ""}${i.getTimezoneOffset() === 0 ? "Z" : (() => {
|
|
596
|
-
let e =
|
|
686
|
+
let e = Q(i);
|
|
597
687
|
return `${e.sign}${e.hours}:${e.minutes}`;
|
|
598
688
|
})()}`;
|
|
599
689
|
}
|
|
600
|
-
function
|
|
690
|
+
function Bt(t, r) {
|
|
601
691
|
let i = e(t);
|
|
602
692
|
if (!n(i)) return "Invalid Date";
|
|
603
693
|
let a = r?.representation ?? "complete", o = String(i.getFullYear()).padStart(4, "0"), s = String(i.getMonth() + 1).padStart(2, "0"), c = String(i.getDate()).padStart(2, "0"), l = String(i.getHours()).padStart(2, "0"), u = String(i.getMinutes()).padStart(2, "0"), d = String(i.getSeconds()).padStart(2, "0");
|
|
604
694
|
return a === "date" ? `${o}-${s}-${c}` : a === "time" ? `${l}:${u}:${d}` : `${o}-${s}-${c} ${l}:${u}:${d}`;
|
|
605
695
|
}
|
|
606
|
-
function
|
|
696
|
+
function Vt(t) {
|
|
607
697
|
let r = e(t);
|
|
608
698
|
if (!n(r)) return "Invalid Date";
|
|
609
|
-
let i =
|
|
699
|
+
let i = Ye[r.getDay()], a = String(r.getDate()).padStart(2, "0"), o = Xe[r.getMonth()], s = r.getFullYear(), c = String(r.getHours()).padStart(2, "0"), l = String(r.getMinutes()).padStart(2, "0"), u = String(r.getSeconds()).padStart(2, "0"), d = Q(r);
|
|
610
700
|
return `${i}, ${a} ${o} ${s} ${c}:${l}:${u} ${d.sign}${d.hours}${d.minutes}`;
|
|
611
701
|
}
|
|
612
|
-
function
|
|
613
|
-
let n = t?.zero ?? !1, r = t?.delimiter ?? ", ", i = t?.locale ?? "default", a = t?.format ??
|
|
702
|
+
function Ht(e, t) {
|
|
703
|
+
let n = t?.zero ?? !1, r = t?.delimiter ?? ", ", i = t?.locale ?? "default", a = t?.format ?? Ze, o = new Intl.PluralRules(i), s = new Intl.NumberFormat(i), c = [];
|
|
614
704
|
for (let t of a) {
|
|
615
705
|
let r = e[t] ?? 0;
|
|
616
706
|
if (r === 0 && !n) continue;
|
|
617
|
-
let [i, a] =
|
|
707
|
+
let [i, a] = Qe[t], l = o.select(r) === "one" ? i : a;
|
|
618
708
|
c.push(`${s.format(r)} ${l}`);
|
|
619
709
|
}
|
|
620
710
|
return c.join(r);
|
|
621
711
|
}
|
|
622
|
-
function
|
|
712
|
+
function Ut(t) {
|
|
623
713
|
let r = e(t);
|
|
624
714
|
return n(r) ? r.toISOString() : "Invalid Date";
|
|
625
715
|
}
|
|
626
|
-
function
|
|
627
|
-
return
|
|
716
|
+
function Wt(e) {
|
|
717
|
+
return $e.test(e.trim()) ? new Date(e) : /* @__PURE__ */ new Date(NaN);
|
|
628
718
|
}
|
|
629
719
|
//#endregion
|
|
630
|
-
export {
|
|
720
|
+
export { _ as add, we as addBusinessDays, S as addDays, x as addHours, v as addMilliseconds, b as addMinutes, w as addMonths, y as addSeconds, C as addWeeks, T as addYears, Ee as clampDate, ke as closestTo, lt as compareAsc, ut as compareDesc, r as createDate, Te as differenceInBusinessDays, U as differenceInDays, H as differenceInHours, z as differenceInMilliseconds, V as differenceInMinutes, W as differenceInMonths, B as differenceInSeconds, xe as differenceInWeeks, G as differenceInYears, Ge as durationToMilliseconds, Me as eachDayOfInterval, je as eachHourOfInterval, Ae as eachMinuteOfInterval, Pe as eachMonthOfInterval, Ne as eachWeekOfInterval, Fe as eachYearOfInterval, fe as endOfDay, pe as endOfHour, Ue as endOfISOWeekYear, me as endOfMinute, L as endOfMonth, ye as endOfQuarter, he as endOfWeek, be as endOfYear, Ft as format, It as formatDate, Ht as formatDuration, Rt as formatISO, Bt as formatISO9075, Vt as formatRFC2822, zt as formatRFC3339, Lt as formatRelativeTime, Ie as fromUnixTime, o as getDate, f as getDayOfWeek, h as getDayOfYear, p as getDaysInMonth, g as getDaysInYear, s as getHours, K as getISOWeek, q as getISOWeekYear, Ve as getISOWeeksInYear, u as getMilliseconds, c as getMinutes, a as getMonth, Ke as getOverlappingDaysInInterval, m as getQuarter, l as getSeconds, d as getTimestamp, ge as getWeekOfMonth, _e as getWeeksInMonth, i as getYear, We as intervalToDuration, jt as isAM, pt as isAfter, ft as isBefore, t as isDate, gt as isEqual, Dt as isFirstDayOfMonth, Ct as isFuture, Pt as isInLeapYear, Ot as isLastDayOfMonth, Nt as isLeapYear, vt as isOverlapping, Mt as isPM, St as isPast, $ as isSameDay, at as isSameHour, dt as isSameISOWeekYear, ot as isSameMinute, tt as isSameMonth, ht as isSameOrAfter, mt as isSameOrBefore, rt as isSameQuarter, st as isSameSecond, ct as isSameTime, it as isSameWeek, nt as isSameYear, Tt as isThisMonth, wt as isThisWeek, Et as isThisYear, yt as isToday, xt as isTomorrow, n as isValid, At as isWeekday, kt as isWeekend, _t as isWithinRange, bt as isYesterday, Oe as max, De as min, Se as nextDay, Wt as parseISO, Ce as previousDay, ze as roundToNearestHours, Re as roundToNearestMinutes, ae as set, le as setDate, oe as setDay, ue as setHours, Be as setISOWeek, j as setMilliseconds, A as setMinutes, ce as setMonth, de as setSeconds, se as setYear, M as startOfDay, N as startOfHour, He as startOfISOWeekYear, P as startOfMinute, I as startOfMonth, ve as startOfQuarter, F as startOfWeek, R as startOfYear, ee as sub, E as subDays, ie as subHours, te as subMilliseconds, re as subMinutes, O as subMonths, ne as subSeconds, D as subWeeks, k as subYears, e as toDate, Ut as toISOString, Le as toUnixTime };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@himanshu-sorathiya/datetime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A strictly client-side, fully type-safe, zero-dependency toolkit for parsing, querying, manipulating, and formatting dates in TypeScript. Every function is a pure, immutable transformation — no wrapper classes, no prototype patching, no hidden global state.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|