@naturalcycles/js-lib 14.260.0 → 14.261.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.
@@ -1,9 +1,9 @@
1
1
  import { Iterable2 } from '../iter/iterable2';
2
- import type { Inclusiveness, IsoDateString, IsoDateTimeString, MonthId, SortDirection, UnixTimestamp, UnixTimestampMillis } from '../types';
2
+ import type { Inclusiveness, IsoDate, IsoDateTime, MonthId, SortDirection, UnixTimestamp, UnixTimestampMillis } from '../types';
3
3
  import { DateObject, ISODayOfWeek, LocalTime } from './localTime';
4
4
  export type LocalDateUnit = LocalDateUnitStrict | 'week';
5
5
  export type LocalDateUnitStrict = 'year' | 'month' | 'day';
6
- export type LocalDateInput = LocalDate | Date | IsoDateString;
6
+ export type LocalDateInput = LocalDate | Date | IsoDate;
7
7
  export type LocalDateInputNullable = LocalDateInput | null | undefined;
8
8
  export type LocalDateFormatter = (ld: LocalDate) => string;
9
9
  /**
@@ -119,18 +119,18 @@ export declare class LocalDate {
119
119
  /**
120
120
  * Returns e.g: `1984-06-21`
121
121
  */
122
- toISODate(): IsoDateString;
122
+ toISODate(): IsoDate;
123
123
  /**
124
124
  * Returns e.g: `1984-06-21T00:00:00`
125
125
  * Hours, minutes and seconds are 0.
126
126
  */
127
- toISODateTime(): IsoDateTimeString;
127
+ toISODateTime(): IsoDateTime;
128
128
  /**
129
129
  * Returns e.g: `1984-06-21T00:00:00Z` (notice the Z at the end, which indicates UTC).
130
130
  * Hours, minutes and seconds are 0.
131
131
  */
132
- toISODateTimeInUTC(): IsoDateTimeString;
133
- toString(): IsoDateString;
132
+ toISODateTimeInUTC(): IsoDateTime;
133
+ toString(): IsoDate;
134
134
  /**
135
135
  * Returns e.g: `19840621`
136
136
  */
@@ -147,7 +147,7 @@ export declare class LocalDate {
147
147
  * Same as .unix(), but in milliseconds.
148
148
  */
149
149
  get unixMillis(): UnixTimestampMillis;
150
- toJSON(): IsoDateString;
150
+ toJSON(): IsoDate;
151
151
  format(fmt: Intl.DateTimeFormat | LocalDateFormatter): string;
152
152
  }
153
153
  declare class LocalDateFactory {
@@ -170,9 +170,9 @@ declare class LocalDateFactory {
170
170
  */
171
171
  todayInUTC(): LocalDate;
172
172
  /**
173
- Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
173
+ Convenience function to return current today's IsoDate representation, e.g `2024-06-21`
174
174
  */
175
- todayString(): IsoDateString;
175
+ todayString(): IsoDate;
176
176
  /**
177
177
  * Create LocalDate from LocalDateInput.
178
178
  * Input can already be a LocalDate - it is returned as-is in that case.
@@ -199,9 +199,9 @@ declare class LocalDateFactory {
199
199
  try(input: LocalDateInputNullable): LocalDate | undefined;
200
200
  /**
201
201
  * Performs STRICT parsing.
202
- * Only allows IsoDateString input, nothing else.
202
+ * Only allows IsoDate input, nothing else.
203
203
  */
204
- fromString(s: IsoDateString): LocalDate;
204
+ fromString(s: IsoDate): LocalDate;
205
205
  /**
206
206
  * Parses "compact iso8601 format", e.g `19840621` into LocalDate.
207
207
  * Throws if it fails to do so.
@@ -385,14 +385,14 @@ class LocalDate {
385
385
  * Hours, minutes and seconds are 0.
386
386
  */
387
387
  toISODateTime() {
388
- return this.toISODate() + 'T00:00:00';
388
+ return (this.toISODate() + 'T00:00:00');
389
389
  }
390
390
  /**
391
391
  * Returns e.g: `1984-06-21T00:00:00Z` (notice the Z at the end, which indicates UTC).
392
392
  * Hours, minutes and seconds are 0.
393
393
  */
394
394
  toISODateTimeInUTC() {
395
- return this.toISODateTime() + 'Z';
395
+ return (this.toISODateTime() + 'Z');
396
396
  }
397
397
  toString() {
398
398
  return this.toISODate();
@@ -464,7 +464,7 @@ class LocalDateFactory {
464
464
  return this.fromDateInUTC(new Date());
465
465
  }
466
466
  /**
467
- Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
467
+ Convenience function to return current today's IsoDate representation, e.g `2024-06-21`
468
468
  */
469
469
  todayString() {
470
470
  return this.fromDate(new Date()).toISODate();
@@ -524,7 +524,7 @@ class LocalDateFactory {
524
524
  }
525
525
  /**
526
526
  * Performs STRICT parsing.
527
- * Only allows IsoDateString input, nothing else.
527
+ * Only allows IsoDate input, nothing else.
528
528
  */
529
529
  fromString(s) {
530
530
  return this.parseToLocalDate(DATE_REGEX, s);
@@ -1,4 +1,4 @@
1
- import type { Inclusiveness, IsoDateString, IsoDateTimeString, MonthId, NumberOfHours, NumberOfMinutes, SortDirection, UnixTimestamp, UnixTimestampMillis } from '../types';
1
+ import type { Inclusiveness, IsoDate, IsoDateTime, MonthId, NumberOfHours, NumberOfMinutes, SortDirection, UnixTimestamp, UnixTimestampMillis } from '../types';
2
2
  import { LocalDate } from './localDate';
3
3
  import { WallTime } from './wallTime';
4
4
  export type LocalTimeUnit = 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second';
@@ -11,7 +11,7 @@ export declare enum ISODayOfWeek {
11
11
  SATURDAY = 6,
12
12
  SUNDAY = 7
13
13
  }
14
- export type LocalTimeInput = LocalTime | Date | IsoDateTimeString | UnixTimestamp;
14
+ export type LocalTimeInput = LocalTime | Date | IsoDate | IsoDateTime | UnixTimestamp;
15
15
  export type LocalTimeInputNullable = LocalTimeInput | null | undefined;
16
16
  export type LocalTimeFormatter = (ld: LocalTime) => string;
17
17
  export type DateTimeObject = DateObject & TimeObject;
@@ -195,15 +195,15 @@ export declare class LocalTime {
195
195
  * or (if seconds=false):
196
196
  * `1984-06-21 17:56`
197
197
  */
198
- toPretty(seconds?: boolean): IsoDateTimeString;
198
+ toPretty(seconds?: boolean): IsoDateTime;
199
199
  /**
200
200
  * Returns e.g: `1984-06-21T17:56:21`
201
201
  */
202
- toISODateTime(): IsoDateTimeString;
202
+ toISODateTime(): IsoDateTime;
203
203
  /**
204
204
  * Returns e.g: `1984-06-21`, only the date part of DateTime
205
205
  */
206
- toISODate(): IsoDateString;
206
+ toISODate(): IsoDate;
207
207
  /**
208
208
  * Returns e.g: `17:03:15` (or `17:03` with seconds=false)
209
209
  */
@@ -212,7 +212,7 @@ export declare class LocalTime {
212
212
  * Returns e.g: `19840621_1705`
213
213
  */
214
214
  toStringCompact(seconds?: boolean): string;
215
- toString(): string;
215
+ toString(): IsoDateTime;
216
216
  toJSON(): UnixTimestamp;
217
217
  toMonthId(): MonthId;
218
218
  format(fmt: Intl.DateTimeFormat | LocalTimeFormatter): string;
@@ -253,7 +253,7 @@ declare class LocalTimeFactory {
253
253
  /**
254
254
  * Returns true if isoString is a valid iso8601 string like `yyyy-mm-ddThh:mm:dd`.
255
255
  */
256
- isValidString(isoString: string | undefined | null): boolean;
256
+ isValidString(isoString: IsoDateTime | IsoDate | undefined | null): boolean;
257
257
  /**
258
258
  * Tries to convert/parse the input into LocalTime.
259
259
  * Uses LOOSE parsing.
@@ -262,14 +262,14 @@ declare class LocalTimeFactory {
262
262
  try(input: LocalTimeInputNullable): LocalTime | undefined;
263
263
  /**
264
264
  * Performs STRICT parsing.
265
- * Only allows IsoDateTimeString or IsoDateString input, nothing else.
265
+ * Only allows IsoDateTime or IsoDate input, nothing else.
266
266
  */
267
- fromIsoDateTimeString(s: IsoDateTimeString | IsoDateString): LocalTime;
267
+ fromIsoDateTimeString(s: IsoDateTime | IsoDate): LocalTime;
268
268
  /**
269
269
  * Performs LOOSE parsing.
270
270
  * Tries to coerce imprefect/incorrect string input into IsoDateTimeString.
271
271
  * Use with caution.
272
- * Allows to input IsoDateString, will set h:m:s to zeros.
272
+ * Allows to input IsoDate, will set h:m:s to zeros.
273
273
  */
274
274
  parse(s: string): LocalTime;
275
275
  private parseStrictlyOrUndefined;
@@ -549,7 +549,7 @@ class LocalTime {
549
549
  * `1984-06-21 17:56`
550
550
  */
551
551
  toPretty(seconds = true) {
552
- return this.toISODate() + ' ' + this.toISOTime(seconds);
552
+ return (this.toISODate() + ' ' + this.toISOTime(seconds));
553
553
  // !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
554
554
  // const s = this.$date.toISOString()
555
555
  // return s.slice(0, 10) + ' ' + s.slice(11, seconds ? 19 : 16)
@@ -558,7 +558,7 @@ class LocalTime {
558
558
  * Returns e.g: `1984-06-21T17:56:21`
559
559
  */
560
560
  toISODateTime() {
561
- return this.toISODate() + 'T' + this.toISOTime();
561
+ return (this.toISODate() + 'T' + this.toISOTime());
562
562
  // !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
563
563
  // return this.$date.toISOString().slice(0, 19)
564
564
  }
@@ -717,9 +717,8 @@ class LocalTimeFactory {
717
717
  }
718
718
  /**
719
719
  * Performs STRICT parsing.
720
- * Only allows IsoDateTimeString or IsoDateString input, nothing else.
720
+ * Only allows IsoDateTime or IsoDate input, nothing else.
721
721
  */
722
- // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
723
722
  fromIsoDateTimeString(s) {
724
723
  const d = this.parseStrictlyOrUndefined(s);
725
724
  (0, assert_1._assert)(d, `Cannot parse "${s}" into LocalTime`);
@@ -729,7 +728,7 @@ class LocalTimeFactory {
729
728
  * Performs LOOSE parsing.
730
729
  * Tries to coerce imprefect/incorrect string input into IsoDateTimeString.
731
730
  * Use with caution.
732
- * Allows to input IsoDateString, will set h:m:s to zeros.
731
+ * Allows to input IsoDate, will set h:m:s to zeros.
733
732
  */
734
733
  parse(s) {
735
734
  const d = this.parseLooselyOrUndefined(String(s));
package/dist/types.d.ts CHANGED
@@ -30,8 +30,8 @@ export type AnyEnum = NumberEnum;
30
30
  export type NumberEnum = Record<string, number | string>;
31
31
  export type StringEnum = Record<string, string>;
32
32
  export type CreatedUpdated = {
33
- created: number;
34
- updated: number;
33
+ created: UnixTimestamp;
34
+ updated: UnixTimestamp;
35
35
  };
36
36
  export interface CreatedUpdatedId extends CreatedUpdated {
37
37
  id: string;
@@ -172,20 +172,22 @@ export interface InstanceId {
172
172
  instanceId: string;
173
173
  }
174
174
  /**
175
- * Interface explicitly states that the value is an ISO Date string (without time).
175
+ * ISO 8601 date (without time).
176
+ * Branded type.
176
177
  *
177
178
  * @example '2019-06-21'
178
179
  */
179
- export type IsoDateString = string;
180
+ export type IsoDate = Branded<string, 'IsoDate'>;
180
181
  /**
181
- * Interface explicitly states that the value is an ISO DateTime string (with time).
182
+ * ISO 8601 date (date+time).
183
+ * Branded type.
182
184
  *
183
185
  * @example '2019-06-21T05:21:73Z'
184
186
  */
185
- export type IsoDateTimeString = string;
187
+ export type IsoDateTime = Branded<string, 'IsoDateTime'>;
186
188
  /**
187
189
  * Identifies the Month.
188
- * Like IsoDateString, but without the Day token.
190
+ * Like IsoDate, but without the Day token.
189
191
  *
190
192
  * @example '2023-09'
191
193
  */
@@ -382,14 +382,14 @@ export class LocalDate {
382
382
  * Hours, minutes and seconds are 0.
383
383
  */
384
384
  toISODateTime() {
385
- return this.toISODate() + 'T00:00:00';
385
+ return (this.toISODate() + 'T00:00:00');
386
386
  }
387
387
  /**
388
388
  * Returns e.g: `1984-06-21T00:00:00Z` (notice the Z at the end, which indicates UTC).
389
389
  * Hours, minutes and seconds are 0.
390
390
  */
391
391
  toISODateTimeInUTC() {
392
- return this.toISODateTime() + 'Z';
392
+ return (this.toISODateTime() + 'Z');
393
393
  }
394
394
  toString() {
395
395
  return this.toISODate();
@@ -460,7 +460,7 @@ class LocalDateFactory {
460
460
  return this.fromDateInUTC(new Date());
461
461
  }
462
462
  /**
463
- Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
463
+ Convenience function to return current today's IsoDate representation, e.g `2024-06-21`
464
464
  */
465
465
  todayString() {
466
466
  return this.fromDate(new Date()).toISODate();
@@ -520,7 +520,7 @@ class LocalDateFactory {
520
520
  }
521
521
  /**
522
522
  * Performs STRICT parsing.
523
- * Only allows IsoDateString input, nothing else.
523
+ * Only allows IsoDate input, nothing else.
524
524
  */
525
525
  fromString(s) {
526
526
  return this.parseToLocalDate(DATE_REGEX, s);
@@ -546,7 +546,7 @@ export class LocalTime {
546
546
  * `1984-06-21 17:56`
547
547
  */
548
548
  toPretty(seconds = true) {
549
- return this.toISODate() + ' ' + this.toISOTime(seconds);
549
+ return (this.toISODate() + ' ' + this.toISOTime(seconds));
550
550
  // !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
551
551
  // const s = this.$date.toISOString()
552
552
  // return s.slice(0, 10) + ' ' + s.slice(11, seconds ? 19 : 16)
@@ -555,7 +555,7 @@ export class LocalTime {
555
555
  * Returns e.g: `1984-06-21T17:56:21`
556
556
  */
557
557
  toISODateTime() {
558
- return this.toISODate() + 'T' + this.toISOTime();
558
+ return (this.toISODate() + 'T' + this.toISOTime());
559
559
  // !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
560
560
  // return this.$date.toISOString().slice(0, 19)
561
561
  }
@@ -713,9 +713,8 @@ class LocalTimeFactory {
713
713
  }
714
714
  /**
715
715
  * Performs STRICT parsing.
716
- * Only allows IsoDateTimeString or IsoDateString input, nothing else.
716
+ * Only allows IsoDateTime or IsoDate input, nothing else.
717
717
  */
718
- // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
719
718
  fromIsoDateTimeString(s) {
720
719
  const d = this.parseStrictlyOrUndefined(s);
721
720
  _assert(d, `Cannot parse "${s}" into LocalTime`);
@@ -725,7 +724,7 @@ class LocalTimeFactory {
725
724
  * Performs LOOSE parsing.
726
725
  * Tries to coerce imprefect/incorrect string input into IsoDateTimeString.
727
726
  * Use with caution.
728
- * Allows to input IsoDateString, will set h:m:s to zeros.
727
+ * Allows to input IsoDate, will set h:m:s to zeros.
729
728
  */
730
729
  parse(s) {
731
730
  const d = this.parseLooselyOrUndefined(String(s));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.260.0",
3
+ "version": "14.261.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build-esm-cjs",
@@ -1,4 +1,4 @@
1
- import { Inclusiveness } from '../types'
1
+ import { Inclusiveness, IsoDate } from '../types'
2
2
  import { LocalDate, localDate, LocalDateInput, LocalDateUnit } from './localDate'
3
3
 
4
4
  export type DateIntervalConfig = DateInterval | DateIntervalString
@@ -25,7 +25,7 @@ export class DateInterval {
25
25
  static parse(d: DateIntervalConfig): DateInterval {
26
26
  if (d instanceof DateInterval) return d
27
27
 
28
- const [start, end] = d.split('/')
28
+ const [start, end] = d.split('/') as IsoDate[]
29
29
 
30
30
  if (!end || !start) {
31
31
  throw new Error(`Cannot parse "${d}" into DateInterval`)
@@ -2,8 +2,8 @@ import { _assert } from '../error/assert'
2
2
  import { Iterable2 } from '../iter/iterable2'
3
3
  import type {
4
4
  Inclusiveness,
5
- IsoDateString,
6
- IsoDateTimeString,
5
+ IsoDate,
6
+ IsoDateTime,
7
7
  MonthId,
8
8
  SortDirection,
9
9
  UnixTimestamp,
@@ -21,7 +21,7 @@ const MDAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
21
21
  const DATE_REGEX = /^(\d\d\d\d)-(\d\d)-(\d\d)/
22
22
  const COMPACT_DATE_REGEX = /^(\d\d\d\d)(\d\d)(\d\d)$/
23
23
 
24
- export type LocalDateInput = LocalDate | Date | IsoDateString
24
+ export type LocalDateInput = LocalDate | Date | IsoDate
25
25
  export type LocalDateInputNullable = LocalDateInput | null | undefined
26
26
  export type LocalDateFormatter = (ld: LocalDate) => string
27
27
 
@@ -442,31 +442,31 @@ export class LocalDate {
442
442
  /**
443
443
  * Returns e.g: `1984-06-21`
444
444
  */
445
- toISODate(): IsoDateString {
445
+ toISODate(): IsoDate {
446
446
  return [
447
447
  String(this.year).padStart(4, '0'),
448
448
  String(this.month).padStart(2, '0'),
449
449
  String(this.day).padStart(2, '0'),
450
- ].join('-')
450
+ ].join('-') as IsoDate
451
451
  }
452
452
 
453
453
  /**
454
454
  * Returns e.g: `1984-06-21T00:00:00`
455
455
  * Hours, minutes and seconds are 0.
456
456
  */
457
- toISODateTime(): IsoDateTimeString {
458
- return this.toISODate() + 'T00:00:00'
457
+ toISODateTime(): IsoDateTime {
458
+ return (this.toISODate() + 'T00:00:00') as IsoDateTime
459
459
  }
460
460
 
461
461
  /**
462
462
  * Returns e.g: `1984-06-21T00:00:00Z` (notice the Z at the end, which indicates UTC).
463
463
  * Hours, minutes and seconds are 0.
464
464
  */
465
- toISODateTimeInUTC(): IsoDateTimeString {
466
- return this.toISODateTime() + 'Z'
465
+ toISODateTimeInUTC(): IsoDateTime {
466
+ return (this.toISODateTime() + 'Z') as IsoDateTime
467
467
  }
468
468
 
469
- toString(): IsoDateString {
469
+ toString(): IsoDate {
470
470
  return this.toISODate()
471
471
  }
472
472
 
@@ -502,7 +502,7 @@ export class LocalDate {
502
502
  return this.toDate().valueOf() as UnixTimestampMillis
503
503
  }
504
504
 
505
- toJSON(): IsoDateString {
505
+ toJSON(): IsoDate {
506
506
  return this.toISODate()
507
507
  }
508
508
 
@@ -547,9 +547,9 @@ class LocalDateFactory {
547
547
  }
548
548
 
549
549
  /**
550
- Convenience function to return current today's IsoDateString representation, e.g `2024-06-21`
550
+ Convenience function to return current today's IsoDate representation, e.g `2024-06-21`
551
551
  */
552
- todayString(): IsoDateString {
552
+ todayString(): IsoDate {
553
553
  return this.fromDate(new Date()).toISODate()
554
554
  }
555
555
 
@@ -605,9 +605,9 @@ class LocalDateFactory {
605
605
 
606
606
  /**
607
607
  * Performs STRICT parsing.
608
- * Only allows IsoDateString input, nothing else.
608
+ * Only allows IsoDate input, nothing else.
609
609
  */
610
- fromString(s: IsoDateString): LocalDate {
610
+ fromString(s: IsoDate): LocalDate {
611
611
  return this.parseToLocalDate(DATE_REGEX, s)
612
612
  }
613
613
 
@@ -2,8 +2,8 @@ import { _assert } from '../error/assert'
2
2
  import { _ms } from '../time/time.util'
3
3
  import type {
4
4
  Inclusiveness,
5
- IsoDateString,
6
- IsoDateTimeString,
5
+ IsoDate,
6
+ IsoDateTime,
7
7
  MonthId,
8
8
  NumberOfHours,
9
9
  NumberOfMinutes,
@@ -26,7 +26,7 @@ export enum ISODayOfWeek {
26
26
  SUNDAY = 7,
27
27
  }
28
28
 
29
- export type LocalTimeInput = LocalTime | Date | IsoDateTimeString | UnixTimestamp
29
+ export type LocalTimeInput = LocalTime | Date | IsoDate | IsoDateTime | UnixTimestamp
30
30
  export type LocalTimeInputNullable = LocalTimeInput | null | undefined
31
31
  export type LocalTimeFormatter = (ld: LocalTime) => string
32
32
 
@@ -659,8 +659,8 @@ export class LocalTime {
659
659
  * or (if seconds=false):
660
660
  * `1984-06-21 17:56`
661
661
  */
662
- toPretty(seconds = true): IsoDateTimeString {
663
- return this.toISODate() + ' ' + this.toISOTime(seconds)
662
+ toPretty(seconds = true): IsoDateTime {
663
+ return (this.toISODate() + ' ' + this.toISOTime(seconds)) as IsoDateTime
664
664
  // !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
665
665
  // const s = this.$date.toISOString()
666
666
  // return s.slice(0, 10) + ' ' + s.slice(11, seconds ? 19 : 16)
@@ -669,8 +669,8 @@ export class LocalTime {
669
669
  /**
670
670
  * Returns e.g: `1984-06-21T17:56:21`
671
671
  */
672
- toISODateTime(): IsoDateTimeString {
673
- return this.toISODate() + 'T' + this.toISOTime()
672
+ toISODateTime(): IsoDateTime {
673
+ return (this.toISODate() + 'T' + this.toISOTime()) as IsoDateTime
674
674
  // !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
675
675
  // return this.$date.toISOString().slice(0, 19)
676
676
  }
@@ -678,14 +678,14 @@ export class LocalTime {
678
678
  /**
679
679
  * Returns e.g: `1984-06-21`, only the date part of DateTime
680
680
  */
681
- toISODate(): IsoDateString {
681
+ toISODate(): IsoDate {
682
682
  const { year, month, day } = this.toDateObject()
683
683
 
684
684
  return [
685
685
  String(year).padStart(4, '0'),
686
686
  String(month).padStart(2, '0'),
687
687
  String(day).padStart(2, '0'),
688
- ].join('-')
688
+ ].join('-') as IsoDate
689
689
 
690
690
  // !! Not using toISOString(), as it returns time in UTC, not in local timezone (unexpected!)
691
691
  // return this.$date.toISOString().slice(0, 10)
@@ -726,7 +726,7 @@ export class LocalTime {
726
726
  ].join('')
727
727
  }
728
728
 
729
- toString(): string {
729
+ toString(): IsoDateTime {
730
730
  return this.toISODateTime()
731
731
  }
732
732
 
@@ -818,7 +818,7 @@ class LocalTimeFactory {
818
818
  /**
819
819
  * Returns true if isoString is a valid iso8601 string like `yyyy-mm-ddThh:mm:dd`.
820
820
  */
821
- isValidString(isoString: string | undefined | null): boolean {
821
+ isValidString(isoString: IsoDateTime | IsoDate | undefined | null): boolean {
822
822
  return !!this.parseStrictlyOrUndefined(isoString)
823
823
  }
824
824
 
@@ -843,10 +843,10 @@ class LocalTimeFactory {
843
843
 
844
844
  /**
845
845
  * Performs STRICT parsing.
846
- * Only allows IsoDateTimeString or IsoDateString input, nothing else.
846
+ * Only allows IsoDateTime or IsoDate input, nothing else.
847
847
  */
848
- // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents
849
- fromIsoDateTimeString(s: IsoDateTimeString | IsoDateString): LocalTime {
848
+
849
+ fromIsoDateTimeString(s: IsoDateTime | IsoDate): LocalTime {
850
850
  const d = this.parseStrictlyOrUndefined(s)
851
851
  _assert(d, `Cannot parse "${s}" into LocalTime`)
852
852
  return new LocalTime(d)
@@ -856,7 +856,7 @@ class LocalTimeFactory {
856
856
  * Performs LOOSE parsing.
857
857
  * Tries to coerce imprefect/incorrect string input into IsoDateTimeString.
858
858
  * Use with caution.
859
- * Allows to input IsoDateString, will set h:m:s to zeros.
859
+ * Allows to input IsoDate, will set h:m:s to zeros.
860
860
  */
861
861
  parse(s: string): LocalTime {
862
862
  const d = this.parseLooselyOrUndefined(String(s))
package/src/types.ts CHANGED
@@ -38,8 +38,8 @@ export type StringEnum = Record<string, string>
38
38
 
39
39
  // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
40
40
  export type CreatedUpdated = {
41
- created: number
42
- updated: number
41
+ created: UnixTimestamp
42
+ updated: UnixTimestamp
43
43
  }
44
44
 
45
45
  export interface CreatedUpdatedId extends CreatedUpdated {
@@ -227,22 +227,24 @@ export interface InstanceId {
227
227
  }
228
228
 
229
229
  /**
230
- * Interface explicitly states that the value is an ISO Date string (without time).
230
+ * ISO 8601 date (without time).
231
+ * Branded type.
231
232
  *
232
233
  * @example '2019-06-21'
233
234
  */
234
- export type IsoDateString = string
235
+ export type IsoDate = Branded<string, 'IsoDate'>
235
236
 
236
237
  /**
237
- * Interface explicitly states that the value is an ISO DateTime string (with time).
238
+ * ISO 8601 date (date+time).
239
+ * Branded type.
238
240
  *
239
241
  * @example '2019-06-21T05:21:73Z'
240
242
  */
241
- export type IsoDateTimeString = string
243
+ export type IsoDateTime = Branded<string, 'IsoDateTime'>
242
244
 
243
245
  /**
244
246
  * Identifies the Month.
245
- * Like IsoDateString, but without the Day token.
247
+ * Like IsoDate, but without the Day token.
246
248
  *
247
249
  * @example '2023-09'
248
250
  */