@naturalcycles/js-lib 14.232.0 → 14.233.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/dist/datetime/dateInterval.d.ts +1 -2
- package/dist/datetime/dateInterval.js +5 -5
- package/dist/datetime/localDate.d.ts +125 -52
- package/dist/datetime/localDate.js +259 -201
- package/dist/datetime/localTime.d.ts +46 -51
- package/dist/datetime/localTime.js +181 -197
- package/dist/datetime/timeInterval.d.ts +1 -2
- package/dist/datetime/timeInterval.js +4 -4
- package/dist/env/buildInfo.js +1 -1
- package/dist-esm/datetime/dateInterval.js +6 -6
- package/dist-esm/datetime/localDate.js +259 -195
- package/dist-esm/datetime/localTime.js +177 -192
- package/dist-esm/datetime/timeInterval.js +5 -5
- package/dist-esm/env/buildInfo.js +2 -2
- package/package.json +2 -2
- package/src/datetime/dateInterval.ts +6 -7
- package/src/datetime/localDate.ts +307 -237
- package/src/datetime/localTime.ts +203 -212
- package/src/datetime/timeInterval.ts +6 -7
- package/src/env/buildInfo.ts +2 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Inclusiveness } from '../types';
|
|
2
|
-
import
|
|
3
|
-
import { LocalDate } from './localDate';
|
|
2
|
+
import { LocalDateInput, LocalDateUnit, LocalDate } from './localDate';
|
|
4
3
|
export type DateIntervalConfig = DateInterval | DateIntervalString;
|
|
5
4
|
export type DateIntervalString = string;
|
|
6
5
|
/**
|
|
@@ -13,7 +13,7 @@ class DateInterval {
|
|
|
13
13
|
this.end = end;
|
|
14
14
|
}
|
|
15
15
|
static of(start, end) {
|
|
16
|
-
return new DateInterval(localDate_1.
|
|
16
|
+
return new DateInterval((0, localDate_1.localDate)(start), (0, localDate_1.localDate)(end));
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Parses string like `2022-02-24/2023-03-30` into a DateInterval.
|
|
@@ -25,7 +25,7 @@ class DateInterval {
|
|
|
25
25
|
if (!end || !start) {
|
|
26
26
|
throw new Error(`Cannot parse "${d}" into DateInterval`);
|
|
27
27
|
}
|
|
28
|
-
return new DateInterval(localDate_1.
|
|
28
|
+
return new DateInterval((0, localDate_1.localDate)(start), (0, localDate_1.localDate)(end));
|
|
29
29
|
}
|
|
30
30
|
isSame(d) {
|
|
31
31
|
return this.cmp(d) === 0;
|
|
@@ -48,7 +48,7 @@ class DateInterval {
|
|
|
48
48
|
* Ranges of DateInterval (start, end) are INCLUSIVE.
|
|
49
49
|
*/
|
|
50
50
|
includes(d, incl = '[]') {
|
|
51
|
-
d = localDate_1.
|
|
51
|
+
d = (0, localDate_1.localDate)(d);
|
|
52
52
|
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
53
53
|
return d.isAfter(this.start, incl[0] === '[') && d.isBefore(this.end, incl[1] === ']');
|
|
54
54
|
}
|
|
@@ -66,13 +66,13 @@ class DateInterval {
|
|
|
66
66
|
return this.start.cmp(d.start) || this.end.cmp(d.end);
|
|
67
67
|
}
|
|
68
68
|
getDays(incl = '[]') {
|
|
69
|
-
return
|
|
69
|
+
return localDate_1.localDate.range(this.start, this.end, incl, 1, 'day');
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Returns an array of LocalDates that are included in the interval.
|
|
73
73
|
*/
|
|
74
74
|
range(incl = '[]', step = 1, stepUnit = 'day') {
|
|
75
|
-
return
|
|
75
|
+
return localDate_1.localDate.range(this.start, this.end, incl, step, stepUnit);
|
|
76
76
|
}
|
|
77
77
|
toString() {
|
|
78
78
|
return [this.start, this.end].join('/');
|
|
@@ -6,34 +6,14 @@ export type LocalDateUnitStrict = 'year' | 'month' | 'day';
|
|
|
6
6
|
export type LocalDateInput = LocalDate | Date | IsoDateString;
|
|
7
7
|
export type LocalDateFormatter = (ld: LocalDate) => string;
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* LocalDate represents a date without time.
|
|
10
|
+
* It is timezone-independent.
|
|
10
11
|
*/
|
|
11
12
|
export declare class LocalDate {
|
|
12
13
|
private $year;
|
|
13
14
|
private $month;
|
|
14
15
|
private $day;
|
|
15
|
-
|
|
16
|
-
static create(year: number, month: number, day: number): LocalDate;
|
|
17
|
-
/**
|
|
18
|
-
* Parses input into LocalDate.
|
|
19
|
-
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
20
|
-
*/
|
|
21
|
-
static of(d: LocalDateInput): LocalDate;
|
|
22
|
-
static parseCompact(d: string): LocalDate;
|
|
23
|
-
static fromDate(d: Date): LocalDate;
|
|
24
|
-
static fromDateUTC(d: Date): LocalDate;
|
|
25
|
-
/**
|
|
26
|
-
* Returns null if invalid.
|
|
27
|
-
*/
|
|
28
|
-
static parseOrNull(d: LocalDateInput | undefined | null): LocalDate | null;
|
|
29
|
-
static isValid(iso: string | undefined | null): boolean;
|
|
30
|
-
static today(): LocalDate;
|
|
31
|
-
static todayUTC(): LocalDate;
|
|
32
|
-
static sort(items: LocalDate[], mutate?: boolean, dir?: SortDirection): LocalDate[];
|
|
33
|
-
static earliestOrUndefined(items: LocalDateInput[]): LocalDate | undefined;
|
|
34
|
-
static earliest(items: LocalDateInput[]): LocalDate;
|
|
35
|
-
static latestOrUndefined(items: LocalDateInput[]): LocalDate | undefined;
|
|
36
|
-
static latest(items: LocalDateInput[]): LocalDate;
|
|
16
|
+
constructor($year: number, $month: number, $day: number);
|
|
37
17
|
get(unit: LocalDateUnitStrict): number;
|
|
38
18
|
set(unit: LocalDateUnitStrict, v: number, mutate?: boolean): LocalDate;
|
|
39
19
|
year(): number;
|
|
@@ -102,9 +82,6 @@ export declare class LocalDate {
|
|
|
102
82
|
* E.g 31 for January.
|
|
103
83
|
*/
|
|
104
84
|
daysInMonth(): number;
|
|
105
|
-
static getYearLength(year: number): number;
|
|
106
|
-
static getMonthLength(year: number, month: number): number;
|
|
107
|
-
static isLeapYear(year: number): boolean;
|
|
108
85
|
clone(): LocalDate;
|
|
109
86
|
/**
|
|
110
87
|
* Converts LocalDate into instance of Date.
|
|
@@ -118,48 +95,144 @@ export declare class LocalDate {
|
|
|
118
95
|
* Unlike normal `.toDate` that uses browser's timezone by default.
|
|
119
96
|
*/
|
|
120
97
|
toDateInUTC(): Date;
|
|
98
|
+
/**
|
|
99
|
+
* Converts LocalDate to LocalTime with 0 hours, 0 minutes, 0 seconds.
|
|
100
|
+
* LocalTime's Date will be in local timezone.
|
|
101
|
+
*/
|
|
121
102
|
toLocalTime(): LocalTime;
|
|
103
|
+
/**
|
|
104
|
+
* Returns e.g: `1984-06-21`
|
|
105
|
+
*/
|
|
122
106
|
toISODate(): IsoDateString;
|
|
123
107
|
/**
|
|
124
|
-
* Returns e.g: `1984-06-
|
|
108
|
+
* Returns e.g: `1984-06-21T00:00:00`
|
|
109
|
+
* Hours, minutes and seconds are 0.
|
|
125
110
|
*/
|
|
126
111
|
toISODateTime(): IsoDateTimeString;
|
|
127
112
|
/**
|
|
128
|
-
* Returns e.g: `1984-06-
|
|
113
|
+
* Returns e.g: `1984-06-21T00:00:00Z` (notice the Z at the end, which indicates UTC).
|
|
114
|
+
* Hours, minutes and seconds are 0.
|
|
129
115
|
*/
|
|
130
|
-
|
|
116
|
+
toISODateTimeInUTC(): IsoDateTimeString;
|
|
131
117
|
toString(): IsoDateString;
|
|
118
|
+
/**
|
|
119
|
+
* Returns e.g: `19840621`
|
|
120
|
+
*/
|
|
132
121
|
toStringCompact(): string;
|
|
122
|
+
/**
|
|
123
|
+
* Returns e.g: `1984-06`
|
|
124
|
+
*/
|
|
133
125
|
toMonthId(): MonthId;
|
|
126
|
+
/**
|
|
127
|
+
* Returns unix timestamp of 00:00:00 of that date (in UTC, because unix timestamp always reflects UTC).
|
|
128
|
+
*/
|
|
134
129
|
unix(): UnixTimestampNumber;
|
|
130
|
+
/**
|
|
131
|
+
* Same as .unix(), but in milliseconds.
|
|
132
|
+
*/
|
|
135
133
|
unixMillis(): UnixTimestampMillisNumber;
|
|
136
134
|
toJSON(): IsoDateString;
|
|
137
135
|
format(fmt: Intl.DateTimeFormat | LocalDateFormatter): string;
|
|
138
136
|
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
137
|
+
declare class LocalDateFactory {
|
|
138
|
+
/**
|
|
139
|
+
* Create LocalDate from year, month and day components.
|
|
140
|
+
*/
|
|
141
|
+
create(year: number, month: number, day: number): LocalDate;
|
|
142
|
+
/**
|
|
143
|
+
* Create LocalDate from LocalDateInput.
|
|
144
|
+
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
145
|
+
* String - will be parsed as yyyy-mm-dd.
|
|
146
|
+
* Date - will be converted to LocalDate (as-is, in whatever timezone it is - local or UTC).
|
|
147
|
+
* No other formats are supported.
|
|
148
|
+
*
|
|
149
|
+
* Will throw if it fails to parse/construct LocalDate.
|
|
150
|
+
*/
|
|
151
|
+
of(d: LocalDateInput): LocalDate;
|
|
152
|
+
/**
|
|
153
|
+
* Tries to construct LocalDate from LocalDateInput, returns null otherwise.
|
|
154
|
+
* Does not throw (returns null instead).
|
|
155
|
+
*/
|
|
156
|
+
parseOrNull(d: LocalDateInput | undefined | null): LocalDate | null;
|
|
157
|
+
/**
|
|
158
|
+
* Parses "compact iso8601 format", e.g `19840621` into LocalDate.
|
|
159
|
+
* Throws if it fails to do so.
|
|
160
|
+
*/
|
|
161
|
+
parseCompact(d: string): LocalDate;
|
|
162
|
+
getYearLength(year: number): number;
|
|
163
|
+
getMonthLength(year: number, month: number): number;
|
|
164
|
+
isLeapYear(year: number): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Constructs LocalDate from Date.
|
|
167
|
+
* Takes Date as-is, in its timezone - local or UTC.
|
|
168
|
+
*/
|
|
169
|
+
fromDate(d: Date): LocalDate;
|
|
170
|
+
/**
|
|
171
|
+
* Constructs LocalDate from Date.
|
|
172
|
+
* Takes Date's year/month/day components in UTC, using getUTCFullYear, getUTCMonth, getUTCDate.
|
|
173
|
+
*/
|
|
174
|
+
fromDateInUTC(d: Date): LocalDate;
|
|
175
|
+
/**
|
|
176
|
+
* Returns true if isoString is a valid iso8601 string like `yyyy-mm-dd`.
|
|
177
|
+
*/
|
|
178
|
+
isValid(isoString: string | undefined | null): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Creates LocalDate that represents `today` (in local timezone).
|
|
181
|
+
*/
|
|
182
|
+
today(): LocalDate;
|
|
183
|
+
/**
|
|
184
|
+
* Creates LocalDate that represents `today` in UTC.
|
|
185
|
+
*/
|
|
186
|
+
todayInUTC(): LocalDate;
|
|
187
|
+
/**
|
|
188
|
+
* Sorts an array of LocalDates in `dir` order (ascending by default).
|
|
189
|
+
*/
|
|
190
|
+
sort(items: LocalDate[], dir?: SortDirection, mutate?: boolean): LocalDate[];
|
|
191
|
+
/**
|
|
192
|
+
* Returns the earliest (min) LocalDate from the array, or undefined if the array is empty.
|
|
193
|
+
*/
|
|
194
|
+
minOrUndefined(items: LocalDateInput[]): LocalDate | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Returns the earliest LocalDate from the array.
|
|
197
|
+
* Throws if the array is empty.
|
|
198
|
+
*/
|
|
199
|
+
min(items: LocalDateInput[]): LocalDate;
|
|
200
|
+
/**
|
|
201
|
+
* Returns the latest (max) LocalDate from the array, or undefined if the array is empty.
|
|
202
|
+
*/
|
|
203
|
+
maxOrUndefined(items: LocalDateInput[]): LocalDate | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Returns the latest LocalDate from the array.
|
|
206
|
+
* Throws if the array is empty.
|
|
207
|
+
*/
|
|
208
|
+
max(items: LocalDateInput[]): LocalDate;
|
|
209
|
+
/**
|
|
210
|
+
* Returns the range (array) of LocalDates between min and max.
|
|
211
|
+
* By default, min is included, max is excluded.
|
|
212
|
+
*/
|
|
213
|
+
range(min: LocalDateInput, max: LocalDateInput, incl?: Inclusiveness, step?: number, stepUnit?: LocalDateUnit): LocalDate[];
|
|
214
|
+
/**
|
|
215
|
+
* Returns the Iterable2 of LocalDates between min and max.
|
|
216
|
+
* By default, min is included, max is excluded.
|
|
217
|
+
*/
|
|
218
|
+
rangeIterable(min: LocalDateInput, max: LocalDateInput, incl?: Inclusiveness, step?: number, stepUnit?: LocalDateUnit): Iterable2<LocalDate>;
|
|
219
|
+
/**
|
|
220
|
+
* Creates a LocalDate from the input, unless it's falsy - then returns undefined.
|
|
221
|
+
*
|
|
222
|
+
* Similar to `localDate.orToday`, but that will instead return Today on falsy input.
|
|
223
|
+
*/
|
|
224
|
+
orUndefined(d: LocalDateInput | null | undefined): LocalDate | undefined;
|
|
225
|
+
/**
|
|
226
|
+
* Creates a LocalDate from the input, unless it's falsy - then returns localDate.today.
|
|
227
|
+
*/
|
|
228
|
+
orToday(d: LocalDateInput | null | undefined): LocalDate;
|
|
229
|
+
}
|
|
230
|
+
interface LocalDateFn extends LocalDateFactory {
|
|
231
|
+
(d: LocalDateInput): LocalDate;
|
|
232
|
+
}
|
|
233
|
+
export declare const localDate: LocalDateFn;
|
|
162
234
|
/**
|
|
163
235
|
Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
|
|
164
236
|
*/
|
|
165
237
|
export declare function todayString(): IsoDateString;
|
|
238
|
+
export {};
|