@naturalcycles/js-lib 14.243.1 → 14.245.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/dist/datetime/dateInterval.d.ts +1 -1
- package/dist/datetime/dateInterval.js +1 -1
- package/dist/datetime/localDate.d.ts +75 -51
- package/dist/datetime/localDate.js +256 -200
- package/dist/datetime/localTime.d.ts +88 -56
- package/dist/datetime/localTime.js +277 -176
- package/dist/datetime/timeInterval.d.ts +2 -2
- package/dist/datetime/timeInterval.js +2 -2
- package/dist/env/buildInfo.js +2 -2
- package/dist/error/error.util.d.ts +1 -1
- package/dist/index.d.ts +37 -37
- package/dist/index.js +37 -37
- package/dist/json-schema/from-data/generateJsonSchemaFromData.d.ts +1 -1
- package/dist/json-schema/jsonSchemaBuilder.d.ts +1 -1
- package/dist/object/object.util.d.ts +1 -1
- package/dist/time/time.util.js +4 -2
- package/dist/zod/zod.util.d.ts +1 -1
- package/dist-esm/datetime/dateInterval.js +1 -1
- package/dist-esm/datetime/localDate.js +256 -199
- package/dist-esm/datetime/localTime.js +277 -175
- package/dist-esm/datetime/timeInterval.js +2 -2
- package/dist-esm/decorators/logMethod.decorator.js +1 -1
- package/dist-esm/env/buildInfo.js +2 -2
- package/dist-esm/index.js +37 -37
- package/dist-esm/json-schema/jsonSchemaBuilder.js +1 -1
- package/dist-esm/time/time.util.js +4 -2
- package/package.json +1 -1
- package/src/datetime/dateInterval.ts +2 -2
- package/src/datetime/localDate.ts +259 -215
- package/src/datetime/localTime.ts +277 -209
- package/src/datetime/timeInterval.ts +4 -4
- package/src/decorators/logMethod.decorator.ts +1 -1
- package/src/define.ts +1 -1
- package/src/env/buildInfo.ts +2 -2
- package/src/error/error.util.ts +3 -3
- package/src/http/fetcher.ts +1 -1
- package/src/index.ts +37 -37
- package/src/json-schema/from-data/generateJsonSchemaFromData.ts +1 -1
- package/src/json-schema/jsonSchemaBuilder.ts +2 -2
- package/src/object/object.util.ts +1 -1
- package/src/time/time.util.ts +4 -1
- package/src/zod/zod.util.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Inclusiveness } from '../types';
|
|
2
|
-
import { LocalDateInput, LocalDateUnit
|
|
2
|
+
import { LocalDate, LocalDateInput, LocalDateUnit } from './localDate';
|
|
3
3
|
export type DateIntervalConfig = DateInterval | DateIntervalString;
|
|
4
4
|
export type DateIntervalString = string;
|
|
5
5
|
/**
|
|
@@ -63,7 +63,7 @@ class DateInterval {
|
|
|
63
63
|
*/
|
|
64
64
|
cmp(d) {
|
|
65
65
|
d = DateInterval.parse(d);
|
|
66
|
-
return this.start.
|
|
66
|
+
return this.start.compare(d.start) || this.end.compare(d.end);
|
|
67
67
|
}
|
|
68
68
|
getDays(incl = '[]') {
|
|
69
69
|
return localDate_1.localDate.range(this.start, this.end, incl, 1, 'day');
|
|
@@ -11,19 +11,16 @@ export type LocalDateFormatter = (ld: LocalDate) => string;
|
|
|
11
11
|
* It is timezone-independent.
|
|
12
12
|
*/
|
|
13
13
|
export declare class LocalDate {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
14
|
+
year: number;
|
|
15
|
+
month: number;
|
|
16
|
+
day: number;
|
|
17
|
+
constructor(year: number, month: number, day: number);
|
|
18
18
|
get(unit: LocalDateUnitStrict): number;
|
|
19
19
|
set(unit: LocalDateUnitStrict, v: number, mutate?: boolean): LocalDate;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
day(): number;
|
|
25
|
-
day(v: number): LocalDate;
|
|
26
|
-
dayOfWeek(): ISODayOfWeek;
|
|
20
|
+
setYear(v: number): LocalDate;
|
|
21
|
+
setMonth(v: number): LocalDate;
|
|
22
|
+
setDay(v: number): LocalDate;
|
|
23
|
+
get dayOfWeek(): ISODayOfWeek;
|
|
27
24
|
isSame(d: LocalDateInput): boolean;
|
|
28
25
|
isBefore(d: LocalDateInput, inclusive?: boolean): boolean;
|
|
29
26
|
isSameOrBefore(d: LocalDateInput): boolean;
|
|
@@ -67,7 +64,7 @@ export declare class LocalDate {
|
|
|
67
64
|
* returns 0 if they are equal
|
|
68
65
|
* returns -1 if this < d
|
|
69
66
|
*/
|
|
70
|
-
|
|
67
|
+
compare(d: LocalDateInput): -1 | 0 | 1;
|
|
71
68
|
/**
|
|
72
69
|
* Same as Math.abs( diff )
|
|
73
70
|
*/
|
|
@@ -94,7 +91,7 @@ export declare class LocalDate {
|
|
|
94
91
|
* Returns how many days are in the current month.
|
|
95
92
|
* E.g 31 for January.
|
|
96
93
|
*/
|
|
97
|
-
daysInMonth(): number;
|
|
94
|
+
get daysInMonth(): number;
|
|
98
95
|
clone(): LocalDate;
|
|
99
96
|
/**
|
|
100
97
|
* Converts LocalDate into instance of Date.
|
|
@@ -140,19 +137,37 @@ export declare class LocalDate {
|
|
|
140
137
|
/**
|
|
141
138
|
* Returns unix timestamp of 00:00:00 of that date (in UTC, because unix timestamp always reflects UTC).
|
|
142
139
|
*/
|
|
143
|
-
unix(): UnixTimestampNumber;
|
|
140
|
+
get unix(): UnixTimestampNumber;
|
|
144
141
|
/**
|
|
145
142
|
* Same as .unix(), but in milliseconds.
|
|
146
143
|
*/
|
|
147
|
-
unixMillis(): UnixTimestampMillisNumber;
|
|
144
|
+
get unixMillis(): UnixTimestampMillisNumber;
|
|
148
145
|
toJSON(): IsoDateString;
|
|
149
146
|
format(fmt: Intl.DateTimeFormat | LocalDateFormatter): string;
|
|
150
147
|
}
|
|
151
148
|
declare class LocalDateFactory {
|
|
152
149
|
/**
|
|
153
|
-
*
|
|
150
|
+
* Creates a LocalDate from the input, unless it's falsy - then returns undefined.
|
|
151
|
+
*
|
|
152
|
+
* Similar to `localDate.orToday`, but that will instead return Today on falsy input.
|
|
153
|
+
*/
|
|
154
|
+
orUndefined(d: LocalDateInputNullable): LocalDate | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Creates a LocalDate from the input, unless it's falsy - then returns localDate.today.
|
|
157
|
+
*/
|
|
158
|
+
orToday(d: LocalDateInputNullable): LocalDate;
|
|
159
|
+
/**
|
|
160
|
+
* Creates LocalDate that represents `today` (in local timezone).
|
|
161
|
+
*/
|
|
162
|
+
today(): LocalDate;
|
|
163
|
+
/**
|
|
164
|
+
* Creates LocalDate that represents `today` in UTC.
|
|
154
165
|
*/
|
|
155
|
-
|
|
166
|
+
todayInUTC(): LocalDate;
|
|
167
|
+
/**
|
|
168
|
+
Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
|
|
169
|
+
*/
|
|
170
|
+
todayString(): IsoDateString;
|
|
156
171
|
/**
|
|
157
172
|
* Create LocalDate from LocalDateInput.
|
|
158
173
|
* Input can already be a LocalDate - it is returned as-is in that case.
|
|
@@ -162,42 +177,62 @@ declare class LocalDateFactory {
|
|
|
162
177
|
*
|
|
163
178
|
* Will throw if it fails to parse/construct LocalDate.
|
|
164
179
|
*/
|
|
165
|
-
|
|
180
|
+
fromInput(input: LocalDateInput): LocalDate;
|
|
181
|
+
/**
|
|
182
|
+
* Returns true if input is valid to create LocalDate.
|
|
183
|
+
*/
|
|
184
|
+
isValid(input: LocalDateInputNullable): boolean;
|
|
166
185
|
/**
|
|
167
|
-
*
|
|
168
|
-
|
|
186
|
+
* Returns true if isoString is a valid iso8601 string like `yyyy-mm-dd`.
|
|
187
|
+
*/
|
|
188
|
+
isValidString(isoString: string | undefined | null): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Tries to convert/parse the input into LocalDate.
|
|
191
|
+
* Uses LOOSE parsing.
|
|
192
|
+
* If invalid - doesn't throw, but returns undefined instead.
|
|
169
193
|
*/
|
|
170
|
-
|
|
194
|
+
try(input: LocalDateInputNullable): LocalDate | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Performs STRICT parsing.
|
|
197
|
+
* Only allows IsoDateString input, nothing else.
|
|
198
|
+
*/
|
|
199
|
+
fromIsoDateString(s: IsoDateString): LocalDate;
|
|
171
200
|
/**
|
|
172
201
|
* Parses "compact iso8601 format", e.g `19840621` into LocalDate.
|
|
173
202
|
* Throws if it fails to do so.
|
|
174
203
|
*/
|
|
175
|
-
|
|
176
|
-
getYearLength(year: number): number;
|
|
177
|
-
getMonthLength(year: number, month: number): number;
|
|
178
|
-
isLeapYear(year: number): boolean;
|
|
204
|
+
fromCompactString(s: string): LocalDate;
|
|
179
205
|
/**
|
|
180
|
-
*
|
|
181
|
-
*
|
|
206
|
+
* Performs LOOSE parsing.
|
|
207
|
+
* Tries to coerce imprefect/incorrect string input into IsoDateString.
|
|
208
|
+
* Use with caution.
|
|
209
|
+
* Allows to input IsoDateTimeString, will drop the Time part of it.
|
|
182
210
|
*/
|
|
183
|
-
|
|
211
|
+
parse(s: string): LocalDate;
|
|
184
212
|
/**
|
|
185
|
-
*
|
|
186
|
-
* Takes Date's year/month/day components in UTC, using getUTCFullYear, getUTCMonth, getUTCDate.
|
|
213
|
+
* Throws if it fails to parse the input string via Regex and YMD validation.
|
|
187
214
|
*/
|
|
188
|
-
|
|
215
|
+
private parseToLocalDate;
|
|
189
216
|
/**
|
|
190
|
-
*
|
|
217
|
+
* Tries to parse the input string, returns undefined if input is invalid.
|
|
191
218
|
*/
|
|
192
|
-
|
|
219
|
+
private parseToLocalDateOrUndefined;
|
|
193
220
|
/**
|
|
194
|
-
*
|
|
221
|
+
* Throws on invalid value.
|
|
195
222
|
*/
|
|
196
|
-
|
|
223
|
+
private validateDateObject;
|
|
224
|
+
isDateObjectValid({ year, month, day }: DateObject): boolean;
|
|
197
225
|
/**
|
|
198
|
-
*
|
|
226
|
+
* Constructs LocalDate from Date.
|
|
227
|
+
* Takes Date as-is, in its timezone - local or UTC.
|
|
199
228
|
*/
|
|
200
|
-
|
|
229
|
+
fromDate(d: Date): LocalDate;
|
|
230
|
+
/**
|
|
231
|
+
* Constructs LocalDate from Date.
|
|
232
|
+
* Takes Date's year/month/day components in UTC, using getUTCFullYear, getUTCMonth, getUTCDate.
|
|
233
|
+
*/
|
|
234
|
+
fromDateInUTC(d: Date): LocalDate;
|
|
235
|
+
fromDateObject(o: DateObject): LocalDate;
|
|
201
236
|
/**
|
|
202
237
|
* Sorts an array of LocalDates in `dir` order (ascending by default).
|
|
203
238
|
*/
|
|
@@ -230,23 +265,12 @@ declare class LocalDateFactory {
|
|
|
230
265
|
* By default, min is included, max is excluded.
|
|
231
266
|
*/
|
|
232
267
|
rangeIterable(min: LocalDateInput, max: LocalDateInput, incl?: Inclusiveness, step?: number, stepUnit?: LocalDateUnit): Iterable2<LocalDate>;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
* Similar to `localDate.orToday`, but that will instead return Today on falsy input.
|
|
237
|
-
*/
|
|
238
|
-
orUndefined(d: LocalDateInputNullable): LocalDate | undefined;
|
|
239
|
-
/**
|
|
240
|
-
* Creates a LocalDate from the input, unless it's falsy - then returns localDate.today.
|
|
241
|
-
*/
|
|
242
|
-
orToday(d: LocalDateInputNullable): LocalDate;
|
|
268
|
+
getYearLength(year: number): number;
|
|
269
|
+
getMonthLength(year: number, month: number): number;
|
|
270
|
+
isLeapYear(year: number): boolean;
|
|
243
271
|
}
|
|
244
272
|
interface LocalDateFn extends LocalDateFactory {
|
|
245
273
|
(d: LocalDateInput): LocalDate;
|
|
246
274
|
}
|
|
247
275
|
export declare const localDate: LocalDateFn;
|
|
248
|
-
/**
|
|
249
|
-
Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
|
|
250
|
-
*/
|
|
251
|
-
export declare function todayString(): IsoDateString;
|
|
252
276
|
export {};
|