date-vir 8.6.4 → 9.0.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.
Files changed (37) hide show
  1. package/README.md +13 -13
  2. package/dist/date-operations/calculate-relative-date.d.ts +2 -1
  3. package/dist/date-operations/combine-dates.d.ts +9 -8
  4. package/dist/date-operations/date-position.d.ts +3 -2
  5. package/dist/date-operations/diff-dates.d.ts +4 -4
  6. package/dist/date-operations/diff-dates.js +4 -4
  7. package/dist/extra-utils/has-date-props.d.ts +3 -2
  8. package/dist/extra-utils/js-date-conversion.d.ts +2 -2
  9. package/dist/extra-utils/js-date-conversion.js +2 -2
  10. package/dist/extra-utils/now.d.ts +4 -4
  11. package/dist/extra-utils/now.js +2 -2
  12. package/dist/extra-utils/override-date.d.ts +5 -4
  13. package/dist/extra-utils/override-date.js +3 -3
  14. package/dist/extra-utils/zero.d.ts +9 -8
  15. package/dist/extra-utils/zero.js +6 -6
  16. package/dist/formatting/simple-strings.d.ts +7 -6
  17. package/dist/formatting/simple-strings.js +1 -1
  18. package/dist/formatting/timestamp.d.ts +6 -6
  19. package/dist/formatting/timestamp.js +6 -6
  20. package/dist/full-date/create-full-date.d.ts +10 -10
  21. package/dist/full-date/create-full-date.js +7 -7
  22. package/dist/full-date/date-like.d.ts +2 -1
  23. package/dist/full-date/full-date-shape.d.ts +10 -9
  24. package/dist/full-date/is-valid-full-date.d.ts +2 -1
  25. package/dist/full-date/luxon-date-time-conversion.d.ts +2 -1
  26. package/dist/full-date/luxon-date-time-conversion.js +7 -2
  27. package/dist/full-date/maybe-create-date.d.ts +2 -1
  28. package/dist/full-date/parsing.d.ts +3 -2
  29. package/dist/full-date/string-parsing.d.ts +2 -1
  30. package/dist/full-date/string-parsing.js +0 -1
  31. package/dist/timezone/timezone-checks.d.ts +15 -2
  32. package/dist/timezone/timezone-checks.js +25 -8
  33. package/dist/timezone/timezone-shape.d.ts +4 -3
  34. package/dist/timezone/timezone-shape.js +2 -2
  35. package/dist/timezone/timezones.d.ts +21 -8
  36. package/dist/timezone/timezones.js +6 -5
  37. package/package.json +2 -2
package/README.md CHANGED
@@ -37,24 +37,24 @@ import {
37
37
  getNowFullDate,
38
38
  parseDateStringWithPattern,
39
39
  parseInputElementValue,
40
- Timezone,
40
+ TimezoneName,
41
41
  } from 'date-vir';
42
42
 
43
43
  /**
44
44
  * Creates a FullDate from a wide range of possible inputs. See TypeScript types for full details on
45
45
  * available inputs.
46
46
  */
47
- createFullDate('2023-06-05', Timezone['Europe/Rome']);
47
+ createFullDate('2023-06-05', TimezoneName['Europe/Rome']);
48
48
 
49
49
  /** Get the current date and time right now in the given timezone. */
50
- getNowFullDate(Timezone['America/Argentina/Buenos_Aires']);
50
+ getNowFullDate(TimezoneName['America/Argentina/Buenos_Aires']);
51
51
 
52
52
  /**
53
53
  * Parsed the value of an <input> element directly from the element itself. This is intended to be
54
54
  * used for type="date" or type="time" <input> elements, but any input element with a valid date or
55
55
  * time string will work.
56
56
  */
57
- parseInputElementValue(document.querySelector('input'), Timezone['Asia/Tokyo']);
57
+ parseInputElementValue(document.querySelector('input'), TimezoneName['Asia/Tokyo']);
58
58
 
59
59
  /**
60
60
  * If you have a really oddly formatted date/time string and createFullDate does not suffice, you
@@ -65,7 +65,7 @@ parseInputElementValue(document.querySelector('input'), Timezone['Asia/Tokyo']);
65
65
  parseDateStringWithPattern({
66
66
  dateString: '870-0-14-19 5 2023 6',
67
67
  formatString: 'S-s-h-m d yyyy M',
68
- timezone: Timezone['America/Cancun'],
68
+ timezone: TimezoneName['America/Cancun'],
69
69
  });
70
70
  ```
71
71
 
@@ -80,14 +80,14 @@ import {
80
80
  createFullDate,
81
81
  formatPresets,
82
82
  FullDatePart,
83
- Timezone,
83
+ TimezoneName,
84
84
  toHtmlInputString,
85
85
  toLocaleString,
86
86
  toTimestamp,
87
87
  toUtcIsoString,
88
88
  } from 'date-vir';
89
89
 
90
- const myFullDate = createFullDate('2023-06-05T14:19:00.870Z', Timezone['America/Chicago']);
90
+ const myFullDate = createFullDate('2023-06-05T14:19:00.870Z', TimezoneName['America/Chicago']);
91
91
 
92
92
  /**
93
93
  * Converts the given FullDate into a UTC unix timestamp with milliseconds. Since the output is a
@@ -123,11 +123,11 @@ toHtmlInputString(myFullDate, FullDatePart.Date); // returns '2023-06-05'
123
123
  <!-- example-link: src/readme-examples/timezones.example.ts -->
124
124
 
125
125
  ```TypeScript
126
- import {Timezone, userTimezone, utcTimezone} from 'date-vir';
126
+ import {TimezoneName, userTimezone, utcTimezone} from 'date-vir';
127
127
 
128
- Timezone['Africa/Abidjan'];
129
- Timezone['America/Los_Angeles'];
130
- Timezone['Etc/GMT+1'];
128
+ TimezoneName['Africa/Abidjan'];
129
+ TimezoneName['America/Los_Angeles'];
130
+ TimezoneName['Etc/GMT+1'];
131
131
 
132
132
  utcTimezone;
133
133
  userTimezone;
@@ -142,9 +142,9 @@ The parsing and timezone conversions in `date-vir` utilize the [`luxon`](https:/
142
142
  <!-- example-link: src/readme-examples/luxon-conversion.example.ts -->
143
143
 
144
144
  ```TypeScript
145
- import {createFullDate, Timezone, toLuxonDateTime} from 'date-vir';
145
+ import {createFullDate, TimezoneName, toLuxonDateTime} from 'date-vir';
146
146
 
147
- const myFullDate = createFullDate('2023-06-05T14:19:00.870Z', Timezone['America/Chicago']);
147
+ const myFullDate = createFullDate('2023-06-05T14:19:00.870Z', TimezoneName['America/Chicago']);
148
148
 
149
149
  toLuxonDateTime(myFullDate);
150
150
  ```
@@ -1,5 +1,6 @@
1
1
  import { type AnyDuration } from '@date-vir/duration';
2
2
  import { type FullDate } from '../full-date/full-date-shape.js';
3
+ import { type Timezone } from '../timezone/timezones.js';
3
4
  /**
4
5
  * Calculates a new date starting at the given fullDate and adding the given offsets. Offsets can be
5
6
  * negative to go backwards in time.
@@ -13,4 +14,4 @@ import { type FullDate } from '../full-date/full-date-shape.js';
13
14
  * calculateRelativeDate(getNowInUserTimezone(), {days: 2});
14
15
  * ```
15
16
  */
16
- export declare function calculateRelativeDate<const SpecificTimezone extends string>(fullDate: Readonly<FullDate<SpecificTimezone>>, offset: Readonly<AnyDuration>): FullDate<SpecificTimezone>;
17
+ export declare function calculateRelativeDate<const SpecificTimezone extends Timezone>(fullDate: Readonly<FullDate<SpecificTimezone>>, offset: Readonly<AnyDuration>): FullDate<SpecificTimezone>;
@@ -1,11 +1,12 @@
1
1
  import { type FullDatePart } from '../full-date/full-date-parts.js';
2
2
  import { type DatePart, type FullDate, type TimePart } from '../full-date/full-date-shape.js';
3
+ import { type Timezone } from '../timezone/timezones.js';
3
4
  /**
4
5
  * An object containing date and/or time parts or neither. Used for {@link combineDateParts}
5
6
  *
6
7
  * @category Internal
7
8
  */
8
- export type MaybeDateParts<SpecificTimezone extends string> = Partial<{
9
+ export type MaybeDateParts<SpecificTimezone extends Timezone> = Partial<{
9
10
  [FullDatePart.Date]: DatePart<SpecificTimezone> | undefined | Partial<FullDate<SpecificTimezone>>;
10
11
  [FullDatePart.Time]: TimePart<SpecificTimezone> | undefined | Partial<FullDate<SpecificTimezone>>;
11
12
  }>;
@@ -14,8 +15,8 @@ export type MaybeDateParts<SpecificTimezone extends string> = Partial<{
14
15
  *
15
16
  * @category Internal
16
17
  */
17
- export type MaybeDatePart<SpecificTimezone extends string> = FullDate<SpecificTimezone> | Partial<FullDate<SpecificTimezone>> | DatePart<SpecificTimezone> | TimePart<SpecificTimezone> | undefined;
18
- export declare function combineDateParts<const SpecificTimezone extends string>(maybeDateParts: {
18
+ export type MaybeDatePart<SpecificTimezone extends Timezone> = FullDate<SpecificTimezone> | Partial<FullDate<SpecificTimezone>> | DatePart<SpecificTimezone> | TimePart<SpecificTimezone> | undefined;
19
+ export declare function combineDateParts<const SpecificTimezone extends Timezone>(maybeDateParts: {
19
20
  [FullDatePart.Date]: DatePart<SpecificTimezone>;
20
21
  [FullDatePart.Time]: TimePart<SpecificTimezone>;
21
22
  }): FullDate<SpecificTimezone>;
@@ -23,20 +24,20 @@ export declare function combineDateParts(maybeDateParts: {
23
24
  [FullDatePart.Date]?: undefined;
24
25
  [FullDatePart.Time]?: undefined;
25
26
  }): undefined;
26
- export declare function combineDateParts<const SpecificTimezone extends string>(maybeDateParts: {
27
+ export declare function combineDateParts<const SpecificTimezone extends Timezone>(maybeDateParts: {
27
28
  [FullDatePart.Date]: DatePart<SpecificTimezone>;
28
29
  [FullDatePart.Time]?: undefined;
29
30
  }): DatePart<SpecificTimezone>;
30
- export declare function combineDateParts<const SpecificTimezone extends string>(maybeDateParts: {
31
+ export declare function combineDateParts<const SpecificTimezone extends Timezone>(maybeDateParts: {
31
32
  [FullDatePart.Date]: DatePart<SpecificTimezone>;
32
33
  [FullDatePart.Time]?: TimePart<SpecificTimezone> | undefined | Partial<FullDate<SpecificTimezone>>;
33
34
  }): FullDate<SpecificTimezone> | DatePart<SpecificTimezone>;
34
- export declare function combineDateParts<const SpecificTimezone extends string>(maybeDateParts: {
35
+ export declare function combineDateParts<const SpecificTimezone extends Timezone>(maybeDateParts: {
35
36
  [FullDatePart.Date]?: undefined;
36
37
  [FullDatePart.Time]: TimePart<SpecificTimezone>;
37
38
  }): TimePart<SpecificTimezone>;
38
- export declare function combineDateParts<const SpecificTimezone extends string>(maybeDateParts: {
39
+ export declare function combineDateParts<const SpecificTimezone extends Timezone>(maybeDateParts: {
39
40
  [FullDatePart.Date]?: DatePart<SpecificTimezone> | undefined | Partial<FullDate<SpecificTimezone>>;
40
41
  [FullDatePart.Time]: TimePart<SpecificTimezone>;
41
42
  }): FullDate<SpecificTimezone> | TimePart<SpecificTimezone>;
42
- export declare function combineDateParts<const SpecificTimezone extends string>(maybeDateParts: MaybeDateParts<SpecificTimezone>): MaybeDatePart<SpecificTimezone>;
43
+ export declare function combineDateParts<const SpecificTimezone extends Timezone>(maybeDateParts: MaybeDateParts<SpecificTimezone>): MaybeDatePart<SpecificTimezone>;
@@ -1,5 +1,6 @@
1
1
  import { DateUnit } from '@date-vir/duration';
2
2
  import { type FullDate } from '../full-date/full-date-shape.js';
3
+ import { type Timezone } from '../timezone/timezones.js';
3
4
  /**
4
5
  * Get the {@link DateUnit} value of a {@link FullDate}.
5
6
  *
@@ -53,7 +54,7 @@ export declare function getDateUnit(date: Readonly<FullDate>, unit: DateUnit): n
53
54
  * ); // outputs {year: 2024, month: 11, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0, timezone: utcTimezone}
54
55
  * ```
55
56
  */
56
- export declare function getStartDate<const SpecificTimezone extends string>(date: Readonly<FullDate<SpecificTimezone>>, unit: DateUnit): FullDate<SpecificTimezone>;
57
+ export declare function getStartDate<const SpecificTimezone extends Timezone>(date: Readonly<FullDate<SpecificTimezone>>, unit: DateUnit): FullDate<SpecificTimezone>;
57
58
  /**
58
59
  * Get the end date of a specific {@link DateUnit} based on a given {@link FullDate}.
59
60
  *
@@ -80,7 +81,7 @@ export declare function getStartDate<const SpecificTimezone extends string>(date
80
81
  * ); // outputs {year: 2024, month: 11, day: 30, hour: 23, minute: 59, second: 59, millisecond: 999, timezone: utcTimezone}
81
82
  * ```
82
83
  */
83
- export declare function getEndDate<const SpecificTimezone extends string>(date: Readonly<FullDate<SpecificTimezone>>, unit: DateUnit): FullDate<SpecificTimezone>;
84
+ export declare function getEndDate<const SpecificTimezone extends Timezone>(date: Readonly<FullDate<SpecificTimezone>>, unit: DateUnit): FullDate<SpecificTimezone>;
84
85
  /**
85
86
  * Shape definition for all valid date position calculations. Used for {@link calculateDatePosition}.
86
87
  *
@@ -13,7 +13,7 @@ import { type FullDate } from '../full-date/full-date-shape.js';
13
13
  * @example
14
14
  *
15
15
  * ```ts
16
- * import {diffDates, DurationUnit} from 'date-vir';
16
+ * import {diffDates, DurationUnit, utcTimezone} from 'date-vir';
17
17
  *
18
18
  * const exampleDate: FullDate = {
19
19
  * year: 2024,
@@ -23,7 +23,7 @@ import { type FullDate } from '../full-date/full-date-shape.js';
23
23
  * minute: 1,
24
24
  * second: 1,
25
25
  * millisecond: 1,
26
- * timezone: 'UTC',
26
+ * timezone: utcTimezone,
27
27
  * };
28
28
  *
29
29
  * // get the diff in days
@@ -59,7 +59,7 @@ units: SelectedUnits, options?: Readonly<RoundOptions>): DurationBySelection<Sel
59
59
  * @example
60
60
  *
61
61
  * ```ts
62
- * import {isDateAfter, type FullDate} from 'date-vir';
62
+ * import {isDateAfter, type FullDate, utcTimezone} from 'date-vir';
63
63
  *
64
64
  * const exampleDate: FullDate = {
65
65
  * year: 2024,
@@ -69,7 +69,7 @@ units: SelectedUnits, options?: Readonly<RoundOptions>): DurationBySelection<Sel
69
69
  * minute: 1,
70
70
  * second: 1,
71
71
  * millisecond: 1,
72
- * timezone: 'UTC',
72
+ * timezone: utcTimezone,
73
73
  * };
74
74
  *
75
75
  * isDateAfter({
@@ -31,7 +31,7 @@ function getHighestPriorityConversionAccuracy(units) {
31
31
  * @example
32
32
  *
33
33
  * ```ts
34
- * import {diffDates, DurationUnit} from 'date-vir';
34
+ * import {diffDates, DurationUnit, utcTimezone} from 'date-vir';
35
35
  *
36
36
  * const exampleDate: FullDate = {
37
37
  * year: 2024,
@@ -41,7 +41,7 @@ function getHighestPriorityConversionAccuracy(units) {
41
41
  * minute: 1,
42
42
  * second: 1,
43
43
  * millisecond: 1,
44
- * timezone: 'UTC',
44
+ * timezone: utcTimezone,
45
45
  * };
46
46
  *
47
47
  * // get the diff in days
@@ -85,7 +85,7 @@ units, options = {}) {
85
85
  * @example
86
86
  *
87
87
  * ```ts
88
- * import {isDateAfter, type FullDate} from 'date-vir';
88
+ * import {isDateAfter, type FullDate, utcTimezone} from 'date-vir';
89
89
  *
90
90
  * const exampleDate: FullDate = {
91
91
  * year: 2024,
@@ -95,7 +95,7 @@ units, options = {}) {
95
95
  * minute: 1,
96
96
  * second: 1,
97
97
  * millisecond: 1,
98
- * timezone: 'UTC',
98
+ * timezone: utcTimezone,
99
99
  * };
100
100
  *
101
101
  * isDateAfter({
@@ -1,5 +1,6 @@
1
1
  import { type PartialWithUndefined, type SetRequiredAndNotNull } from '@augment-vir/common';
2
2
  import { type FullDate } from '../full-date/full-date-shape.js';
3
+ import { type Timezone } from '../timezone/timezones.js';
3
4
  /**
4
5
  * Checks that the input has all the requested {@link FullDate} keys.
5
6
  *
@@ -13,7 +14,7 @@ import { type FullDate } from '../full-date/full-date-shape.js';
13
14
  * hasFullDateKeys({year: 2024}, ['day']); // `false`
14
15
  * ```
15
16
  */
16
- export declare function hasFullDateKeys<SpecificTimezone extends string, PartialFullDate extends PartialWithUndefined<FullDate<SpecificTimezone>>,
17
+ export declare function hasFullDateKeys<SpecificTimezone extends Timezone, PartialFullDate extends PartialWithUndefined<FullDate<SpecificTimezone>>,
17
18
  /** A union of strings. */
18
19
  RequiredKeys extends keyof FullDate<SpecificTimezone>>(partialFullDate: PartialWithUndefined<FullDate<SpecificTimezone>>, keys: ReadonlyArray<RequiredKeys>): partialFullDate is SetRequiredAndNotNull<PartialFullDate, RequiredKeys>;
19
20
  /**
@@ -29,6 +30,6 @@ RequiredKeys extends keyof FullDate<SpecificTimezone>>(partialFullDate: PartialW
29
30
  * assertHasFullDateKeys({year: 2024}, ['day']); // fails
30
31
  * ```
31
32
  */
32
- export declare function assertHasFullDateKeys<SpecificTimezone extends string, PartialFullDate extends PartialWithUndefined<FullDate<SpecificTimezone>>,
33
+ export declare function assertHasFullDateKeys<SpecificTimezone extends Timezone, PartialFullDate extends PartialWithUndefined<FullDate<SpecificTimezone>>,
33
34
  /** A union of strings. */
34
35
  RequiredKeys extends keyof FullDate<SpecificTimezone>>(partialFullDate: PartialWithUndefined<FullDate<SpecificTimezone>>, keys: ReadonlyArray<RequiredKeys>): asserts partialFullDate is SetRequiredAndNotNull<PartialFullDate, RequiredKeys>;
@@ -7,7 +7,7 @@ import { type FullDate } from '../full-date/full-date-shape.js';
7
7
  * @example
8
8
  *
9
9
  * ```ts
10
- * import {toJsDate, type FullDate} from 'date-vir';
10
+ * import {toJsDate, type FullDate, utcTimezone} from 'date-vir';
11
11
  *
12
12
  * const exampleDate: Readonly<FullDate> = {
13
13
  * year: 2024,
@@ -17,7 +17,7 @@ import { type FullDate } from '../full-date/full-date-shape.js';
17
17
  * minute: 1,
18
18
  * second: 1,
19
19
  * millisecond: 1,
20
- * timezone: 'UTC',
20
+ * timezone: utcTimezone,
21
21
  * };
22
22
  *
23
23
  * toJsDate(exampleDate);
@@ -8,7 +8,7 @@ import { userTimezone } from '../timezone/timezones.js';
8
8
  * @example
9
9
  *
10
10
  * ```ts
11
- * import {toJsDate, type FullDate} from 'date-vir';
11
+ * import {toJsDate, type FullDate, utcTimezone} from 'date-vir';
12
12
  *
13
13
  * const exampleDate: Readonly<FullDate> = {
14
14
  * year: 2024,
@@ -18,7 +18,7 @@ import { userTimezone } from '../timezone/timezones.js';
18
18
  * minute: 1,
19
19
  * second: 1,
20
20
  * millisecond: 1,
21
- * timezone: 'UTC',
21
+ * timezone: utcTimezone,
22
22
  * };
23
23
  *
24
24
  * toJsDate(exampleDate);
@@ -1,6 +1,6 @@
1
1
  import { type UtcIsoString } from '../formatting/string-format-types.js';
2
2
  import { type FullDate } from '../full-date/full-date-shape.js';
3
- import { type UtcTimezone } from '../timezone/timezones.js';
3
+ import { type Timezone, type UtcTimezone } from '../timezone/timezones.js';
4
4
  /**
5
5
  * Get the time right now as a UTC ISO.
6
6
  *
@@ -47,10 +47,10 @@ export declare function getNowInUtcTimezone(): FullDate<UtcTimezone>;
47
47
  * @example
48
48
  *
49
49
  * ```ts
50
- * import {getNowFullDate, utcTimezone, timezones} from 'date-vir';
50
+ * import {getNowFullDate, TimezoneName, utcTimezone} from 'date-vir';
51
51
  *
52
52
  * getNowFullDate(utcTimezone);
53
- * getNowFullDate(timezones['Australia/Brisbane']);
53
+ * getNowFullDate(TimezoneName['Australia/Brisbane']);
54
54
  * ```
55
55
  */
56
- export declare function getNowFullDate<const SpecificTimezone extends string>(timezone: SpecificTimezone): FullDate<SpecificTimezone>;
56
+ export declare function getNowFullDate<const SpecificTimezone extends Timezone>(timezone: SpecificTimezone): FullDate<SpecificTimezone>;
@@ -57,10 +57,10 @@ export function getNowInUtcTimezone() {
57
57
  * @example
58
58
  *
59
59
  * ```ts
60
- * import {getNowFullDate, utcTimezone, timezones} from 'date-vir';
60
+ * import {getNowFullDate, TimezoneName, utcTimezone} from 'date-vir';
61
61
  *
62
62
  * getNowFullDate(utcTimezone);
63
- * getNowFullDate(timezones['Australia/Brisbane']);
63
+ * getNowFullDate(TimezoneName['Australia/Brisbane']);
64
64
  * ```
65
65
  */
66
66
  export function getNowFullDate(timezone) {
@@ -1,4 +1,5 @@
1
1
  import { type FullDate } from '../full-date/full-date-shape.js';
2
+ import { type Timezone } from '../timezone/timezones.js';
2
3
  /**
3
4
  * Override the initial provided FullDate with all subsequent FullDate parts.
4
5
  *
@@ -6,7 +7,7 @@ import { type FullDate } from '../full-date/full-date-shape.js';
6
7
  * @example
7
8
  *
8
9
  * ```ts
9
- * import {overrideDateParts, type FullDate} from 'date-vir';
10
+ * import {overrideDateParts, type FullDate, utcTimezone} from 'date-vir';
10
11
  *
11
12
  * const exampleDate: Readonly<FullDate> = {
12
13
  * year: 2024,
@@ -16,11 +17,11 @@ import { type FullDate } from '../full-date/full-date-shape.js';
16
17
  * minute: 1,
17
18
  * second: 1,
18
19
  * millisecond: 1,
19
- * timezone: 'UTC',
20
+ * timezone: utcTimezone,
20
21
  * };
21
22
  *
22
23
  * overrideDateParts(exampleDate, {day: 20}, {second: 10});
23
- * // `{year: 2024, month: 1, day: 20, hour: 1, minute: 1, second: 10, millisecond: 1, timezone: 'UTC'}`
24
+ * // `{year: 2024, month: 1, day: 20, hour: 1, minute: 1, second: 10, millisecond: 1, timezone: utcTimezone}`
24
25
  * ```
25
26
  */
26
- export declare function overrideDateParts<const SpecificTimezone extends string>(date: FullDate<SpecificTimezone>, ...overrides: Partial<FullDate<SpecificTimezone>>[]): FullDate<SpecificTimezone>;
27
+ export declare function overrideDateParts<const SpecificTimezone extends Timezone>(date: FullDate<SpecificTimezone>, ...overrides: Partial<FullDate<SpecificTimezone>>[]): FullDate<SpecificTimezone>;
@@ -5,7 +5,7 @@
5
5
  * @example
6
6
  *
7
7
  * ```ts
8
- * import {overrideDateParts, type FullDate} from 'date-vir';
8
+ * import {overrideDateParts, type FullDate, utcTimezone} from 'date-vir';
9
9
  *
10
10
  * const exampleDate: Readonly<FullDate> = {
11
11
  * year: 2024,
@@ -15,11 +15,11 @@
15
15
  * minute: 1,
16
16
  * second: 1,
17
17
  * millisecond: 1,
18
- * timezone: 'UTC',
18
+ * timezone: utcTimezone,
19
19
  * };
20
20
  *
21
21
  * overrideDateParts(exampleDate, {day: 20}, {second: 10});
22
- * // `{year: 2024, month: 1, day: 20, hour: 1, minute: 1, second: 10, millisecond: 1, timezone: 'UTC'}`
22
+ * // `{year: 2024, month: 1, day: 20, hour: 1, minute: 1, second: 10, millisecond: 1, timezone: utcTimezone}`
23
23
  * ```
24
24
  */
25
25
  export function overrideDateParts(date, ...overrides) {
@@ -1,5 +1,6 @@
1
1
  import { TimeKey } from '../full-date/full-date-parts.js';
2
2
  import { type FullDate } from '../full-date/full-date-shape.js';
3
+ import { type Timezone } from '../timezone/timezones.js';
3
4
  /**
4
5
  * A {@link FullDate} instance that has the lowest, valid, non-negative, value for each property.
5
6
  *
@@ -50,7 +51,7 @@ export declare const zeroTime: Pick<{
50
51
  * @example
51
52
  *
52
53
  * ```ts
53
- * import {clearTime, type FullDate} from 'date-vir';
54
+ * import {clearTime, type FullDate, utcTimezone} from 'date-vir';
54
55
  *
55
56
  * const exampleDate: Readonly<FullDate> = {
56
57
  * year: 2024,
@@ -60,14 +61,14 @@ export declare const zeroTime: Pick<{
60
61
  * minute: 1,
61
62
  * second: 1,
62
63
  * millisecond: 1,
63
- * timezone: 'UTC',
64
+ * timezone: utcTimezone,
64
65
  * };
65
66
  *
66
67
  * clearTime(exampleDate);
67
- * // `{year: 2024, month: 1, day: 5, hour: 0, minute: 0, second: 0, millisecond: 0, timezone: 'UTC'}`
68
+ * // `{year: 2024, month: 1, day: 5, hour: 0, minute: 0, second: 0, millisecond: 0, timezone: utcTimezone}`
68
69
  * ```
69
70
  */
70
- export declare function clearTime<const SpecificTimezone extends string>(inputFullDate: Readonly<FullDate<SpecificTimezone>>): FullDate<SpecificTimezone>;
71
+ export declare function clearTime<const SpecificTimezone extends Timezone>(inputFullDate: Readonly<FullDate<SpecificTimezone>>): FullDate<SpecificTimezone>;
71
72
  /**
72
73
  * Clear all the selected parts of {@link FullDate} by setting them each to their lowest, valid
73
74
  * value. See {@link zeroDate} for the lowest valid values for each property.
@@ -76,7 +77,7 @@ export declare function clearTime<const SpecificTimezone extends string>(inputFu
76
77
  * @example
77
78
  *
78
79
  * ```ts
79
- * import {clearTime, type FullDate} from 'date-vir';
80
+ * import {clearTime, type FullDate, utcTimezone} from 'date-vir';
80
81
  *
81
82
  * const exampleDate: Readonly<FullDate> = {
82
83
  * year: 2024,
@@ -86,17 +87,17 @@ export declare function clearTime<const SpecificTimezone extends string>(inputFu
86
87
  * minute: 1,
87
88
  * second: 1,
88
89
  * millisecond: 1,
89
- * timezone: 'UTC',
90
+ * timezone: utcTimezone,
90
91
  * };
91
92
  *
92
93
  * clearParts(exampleDate, [
93
94
  * 'year',
94
95
  * 'day',
95
96
  * ]);
96
- * // `{year: 0, month: 1, day: 1, hour: 1, minute: 1, second: 1, millisecond: 1, timezone: 'UTC'}`
97
+ * // `{year: 0, month: 1, day: 1, hour: 1, minute: 1, second: 1, millisecond: 1, timezone: utcTimezone}`
97
98
  * ```
98
99
  */
99
- export declare function clearParts<const SpecificTimezone extends string>(inputFullDate: Readonly<FullDate<SpecificTimezone>>, parts: ReadonlyArray<Exclude<keyof FullDate, 'timezone'>>): {
100
+ export declare function clearParts<const SpecificTimezone extends Timezone>(inputFullDate: Readonly<FullDate<SpecificTimezone>>, parts: ReadonlyArray<Exclude<keyof FullDate, 'timezone'>>): {
100
101
  year: number;
101
102
  month: import("@date-vir/duration").MonthNumber;
102
103
  day: import("@date-vir/duration").DayOfMonth;
@@ -35,7 +35,7 @@ export const zeroTime = pickObjectKeys(zeroDate, getEnumValues(TimeKey));
35
35
  * @example
36
36
  *
37
37
  * ```ts
38
- * import {clearTime, type FullDate} from 'date-vir';
38
+ * import {clearTime, type FullDate, utcTimezone} from 'date-vir';
39
39
  *
40
40
  * const exampleDate: Readonly<FullDate> = {
41
41
  * year: 2024,
@@ -45,11 +45,11 @@ export const zeroTime = pickObjectKeys(zeroDate, getEnumValues(TimeKey));
45
45
  * minute: 1,
46
46
  * second: 1,
47
47
  * millisecond: 1,
48
- * timezone: 'UTC',
48
+ * timezone: utcTimezone,
49
49
  * };
50
50
  *
51
51
  * clearTime(exampleDate);
52
- * // `{year: 2024, month: 1, day: 5, hour: 0, minute: 0, second: 0, millisecond: 0, timezone: 'UTC'}`
52
+ * // `{year: 2024, month: 1, day: 5, hour: 0, minute: 0, second: 0, millisecond: 0, timezone: utcTimezone}`
53
53
  * ```
54
54
  */
55
55
  export function clearTime(inputFullDate) {
@@ -63,7 +63,7 @@ export function clearTime(inputFullDate) {
63
63
  * @example
64
64
  *
65
65
  * ```ts
66
- * import {clearTime, type FullDate} from 'date-vir';
66
+ * import {clearTime, type FullDate, utcTimezone} from 'date-vir';
67
67
  *
68
68
  * const exampleDate: Readonly<FullDate> = {
69
69
  * year: 2024,
@@ -73,14 +73,14 @@ export function clearTime(inputFullDate) {
73
73
  * minute: 1,
74
74
  * second: 1,
75
75
  * millisecond: 1,
76
- * timezone: 'UTC',
76
+ * timezone: utcTimezone,
77
77
  * };
78
78
  *
79
79
  * clearParts(exampleDate, [
80
80
  * 'year',
81
81
  * 'day',
82
82
  * ]);
83
- * // `{year: 0, month: 1, day: 1, hour: 1, minute: 1, second: 1, millisecond: 1, timezone: 'UTC'}`
83
+ * // `{year: 0, month: 1, day: 1, hour: 1, minute: 1, second: 1, millisecond: 1, timezone: utcTimezone}`
84
84
  * ```
85
85
  */
86
86
  export function clearParts(inputFullDate, parts) {
@@ -1,5 +1,6 @@
1
1
  import { type SetOptionalAndNullable } from '@augment-vir/common';
2
2
  import { type FullDate } from '../full-date/full-date-shape.js';
3
+ import { type Timezone } from '../timezone/timezones.js';
3
4
  import { type JustDateString, type JustTimeString, type JustTimeWithSecondsString } from './string-format-types.js';
4
5
  /**
5
6
  * Create a string based on just the date parts of a FullDate.
@@ -57,7 +58,7 @@ export type FullDateForParts = SetOptionalAndNullable<FullDate, 'millisecond'>;
57
58
  * result = {
58
59
  * date: '2024-04-24',
59
60
  * time: '06:04:09',
60
- * timezone: 'UTC',
61
+ * timezone: utcTimezone,
61
62
  * };
62
63
  * ```
63
64
  */
@@ -66,7 +67,7 @@ export declare function toDatePartStrings(fullDate: FullDateForParts, options: {
66
67
  }): {
67
68
  date: JustDateString;
68
69
  time: JustTimeWithSecondsString;
69
- timezone: string;
70
+ timezone: Timezone;
70
71
  };
71
72
  /**
72
73
  * Splits a FullDate up into multiple formatted string representations.
@@ -98,7 +99,7 @@ export declare function toDatePartStrings(fullDate: FullDateForParts, options: {
98
99
  * result = {
99
100
  * date: '2024-04-24',
100
101
  * time: '06:04:09',
101
- * timezone: 'UTC',
102
+ * timezone: utcTimezone,
102
103
  * };
103
104
  * ```
104
105
  */
@@ -107,7 +108,7 @@ export declare function toDatePartStrings(fullDate: SetOptionalAndNullable<FullD
107
108
  }): {
108
109
  date: JustDateString;
109
110
  time: JustTimeString;
110
- timezone: string;
111
+ timezone: Timezone;
111
112
  };
112
113
  /**
113
114
  * Splits a FullDate up into multiple formatted string representations.
@@ -139,7 +140,7 @@ export declare function toDatePartStrings(fullDate: SetOptionalAndNullable<FullD
139
140
  * result = {
140
141
  * date: '2024-04-24',
141
142
  * time: '06:04:09',
142
- * timezone: 'UTC',
143
+ * timezone: utcTimezone,
143
144
  * };
144
145
  * ```
145
146
  */
@@ -148,7 +149,7 @@ export declare function toDatePartStrings(fullDate: FullDateForParts, options: {
148
149
  }): {
149
150
  date: JustDateString;
150
151
  time: JustTimeWithSecondsString | JustTimeString;
151
- timezone: string;
152
+ timezone: Timezone;
152
153
  };
153
154
  /**
154
155
  * Converts a date into a simple, unambiguous date string.
@@ -67,7 +67,7 @@ export function toSimpleTimePartString(fullDate, includeSeconds) {
67
67
  * result = {
68
68
  * date: '2024-04-24',
69
69
  * time: '06:04:09',
70
- * timezone: 'UTC',
70
+ * timezone: utcTimezone,
71
71
  * };
72
72
  * ```
73
73
  */
@@ -8,7 +8,7 @@ import { type HttpDateString, type UtcIsoString } from './string-format-types.js
8
8
  * @example
9
9
  *
10
10
  * ```ts
11
- * import {toTimestamp} from 'date-vir';
11
+ * import {toTimestamp, utcTimezone} from 'date-vir';
12
12
  *
13
13
  * const exampleDate: FullDate = {
14
14
  * year: 2024,
@@ -18,7 +18,7 @@ import { type HttpDateString, type UtcIsoString } from './string-format-types.js
18
18
  * minute: 1,
19
19
  * second: 1,
20
20
  * millisecond: 1,
21
- * timezone: 'UTC',
21
+ * timezone: utcTimezone,
22
22
  * };
23
23
  *
24
24
  * toTimestamp(exampleDate); // `1704416461001`
@@ -37,7 +37,7 @@ export declare function toTimestamp(fullDate: FullDate): number;
37
37
  * @example
38
38
  *
39
39
  * ```ts
40
- * import {toUtcIsoString} from 'date-vir';
40
+ * import {toUtcIsoString, utcTimezone} from 'date-vir';
41
41
  *
42
42
  * const exampleDate: FullDate = {
43
43
  * year: 2024,
@@ -47,7 +47,7 @@ export declare function toTimestamp(fullDate: FullDate): number;
47
47
  * minute: 1,
48
48
  * second: 1,
49
49
  * millisecond: 1,
50
- * timezone: 'UTC',
50
+ * timezone: utcTimezone,
51
51
  * };
52
52
  *
53
53
  * toUtcIsoString(exampleDate); // `'2024-01-05T01:01:01.001Z'`
@@ -93,7 +93,7 @@ dateLike: Readonly<DateLike>): UtcIsoString;
93
93
  * @example
94
94
  *
95
95
  * ```ts
96
- * import {toHttpDateString} from 'date-vir';
96
+ * import {toHttpDateString, utcTimezone} from 'date-vir';
97
97
  *
98
98
  * const exampleDate: FullDate = {
99
99
  * year: 2024,
@@ -103,7 +103,7 @@ dateLike: Readonly<DateLike>): UtcIsoString;
103
103
  * minute: 1,
104
104
  * second: 1,
105
105
  * millisecond: 1,
106
- * timezone: 'UTC',
106
+ * timezone: utcTimezone,
107
107
  * };
108
108
  *
109
109
  * toHttpDateString(exampleDate); // `'Fri, 05 Jan 2024 01:01:01 GMT'`
@@ -8,7 +8,7 @@ import { utcTimezone } from '../timezone/timezones.js';
8
8
  * @example
9
9
  *
10
10
  * ```ts
11
- * import {toTimestamp} from 'date-vir';
11
+ * import {toTimestamp, utcTimezone} from 'date-vir';
12
12
  *
13
13
  * const exampleDate: FullDate = {
14
14
  * year: 2024,
@@ -18,7 +18,7 @@ import { utcTimezone } from '../timezone/timezones.js';
18
18
  * minute: 1,
19
19
  * second: 1,
20
20
  * millisecond: 1,
21
- * timezone: 'UTC',
21
+ * timezone: utcTimezone,
22
22
  * };
23
23
  *
24
24
  * toTimestamp(exampleDate); // `1704416461001`
@@ -39,7 +39,7 @@ export function toTimestamp(fullDate) {
39
39
  * @example
40
40
  *
41
41
  * ```ts
42
- * import {toUtcIsoString} from 'date-vir';
42
+ * import {toUtcIsoString, utcTimezone} from 'date-vir';
43
43
  *
44
44
  * const exampleDate: FullDate = {
45
45
  * year: 2024,
@@ -49,7 +49,7 @@ export function toTimestamp(fullDate) {
49
49
  * minute: 1,
50
50
  * second: 1,
51
51
  * millisecond: 1,
52
- * timezone: 'UTC',
52
+ * timezone: utcTimezone,
53
53
  * };
54
54
  *
55
55
  * toUtcIsoString(exampleDate); // `'2024-01-05T01:01:01.001Z'`
@@ -105,7 +105,7 @@ dateLike) {
105
105
  * @example
106
106
  *
107
107
  * ```ts
108
- * import {toHttpDateString} from 'date-vir';
108
+ * import {toHttpDateString, utcTimezone} from 'date-vir';
109
109
  *
110
110
  * const exampleDate: FullDate = {
111
111
  * year: 2024,
@@ -115,7 +115,7 @@ dateLike) {
115
115
  * minute: 1,
116
116
  * second: 1,
117
117
  * millisecond: 1,
118
- * timezone: 'UTC',
118
+ * timezone: utcTimezone,
119
119
  * };
120
120
  *
121
121
  * toHttpDateString(exampleDate); // `'Fri, 05 Jan 2024 01:01:01 GMT'`
@@ -1,4 +1,4 @@
1
- import { type UtcTimezone } from '../timezone/timezones.js';
1
+ import { type Timezone, type UtcTimezone } from '../timezone/timezones.js';
2
2
  import { type DateLike } from './date-like.js';
3
3
  import { type FullDate } from './full-date-shape.js';
4
4
  /**
@@ -45,16 +45,16 @@ export declare function createUtcFullDate(dateLike: Readonly<DateLike>): FullDat
45
45
  * @example
46
46
  *
47
47
  * ```ts
48
- * import {createFullDate, timezones, utcTimezone} from 'date-vir';
48
+ * import {createFullDate, TimezoneName, utcTimezone} from 'date-vir';
49
49
  *
50
50
  * createFullDate('June 1, 2024', utcTimezone);
51
- * createFullDate(new Date(), timezones['Australia/Brisbane']);
52
- * createFullDate(112300120, timezones['Etc/GMT-11']);
51
+ * createFullDate(new Date(), TimezoneName['Australia/Brisbane']);
52
+ * createFullDate(112300120, TimezoneName['Etc/GMT-11']);
53
53
  * ```
54
54
  *
55
55
  * @throws Error: if a valid date cannot be created.
56
56
  */
57
- export declare function createFullDate<const SpecificTimezone extends string>(
57
+ export declare function createFullDate<const SpecificTimezone extends Timezone>(
58
58
  /** The original date representation to be converted into a FullDate. */
59
59
  dateLike: Readonly<DateLike>,
60
60
  /** The timezone that this date/time is meant for / originated from. */
@@ -67,7 +67,7 @@ timezone: SpecificTimezone): FullDate<SpecificTimezone>;
67
67
  * @example
68
68
  *
69
69
  * ```ts
70
- * import {toNewTimezone} from 'date-vir';
70
+ * import {toNewTimezone, TimezoneName, utcTimezone} from 'date-vir';
71
71
  *
72
72
  * const exampleDate: FullDate = {
73
73
  * year: 2024,
@@ -77,10 +77,10 @@ timezone: SpecificTimezone): FullDate<SpecificTimezone>;
77
77
  * minute: 1,
78
78
  * second: 1,
79
79
  * millisecond: 1,
80
- * timezone: 'UTC',
80
+ * timezone: utcTimezone,
81
81
  * };
82
82
  *
83
- * let result = toNewTimezone(exampleDate, timezones['Australia/Brisbane']);
83
+ * let result = toNewTimezone(exampleDate, TimezoneName['Australia/Brisbane']);
84
84
  * // output:
85
85
  * result = {
86
86
  * year: 2024,
@@ -90,8 +90,8 @@ timezone: SpecificTimezone): FullDate<SpecificTimezone>;
90
90
  * minute: 1,
91
91
  * second: 1,
92
92
  * millisecond: 1,
93
- * timezone: timezones['Australia/Brisbane'],
93
+ * timezone: TimezoneName['Australia/Brisbane'],
94
94
  * };
95
95
  * ```
96
96
  */
97
- export declare function toNewTimezone<const SpecificTimezone extends string>(fullDate: Readonly<FullDate>, timezone: SpecificTimezone): FullDate<SpecificTimezone>;
97
+ export declare function toNewTimezone<const SpecificTimezone extends Timezone>(fullDate: Readonly<FullDate>, timezone: SpecificTimezone): FullDate<SpecificTimezone>;
@@ -53,11 +53,11 @@ export function createUtcFullDate(dateLike) {
53
53
  * @example
54
54
  *
55
55
  * ```ts
56
- * import {createFullDate, timezones, utcTimezone} from 'date-vir';
56
+ * import {createFullDate, TimezoneName, utcTimezone} from 'date-vir';
57
57
  *
58
58
  * createFullDate('June 1, 2024', utcTimezone);
59
- * createFullDate(new Date(), timezones['Australia/Brisbane']);
60
- * createFullDate(112300120, timezones['Etc/GMT-11']);
59
+ * createFullDate(new Date(), TimezoneName['Australia/Brisbane']);
60
+ * createFullDate(112300120, TimezoneName['Etc/GMT-11']);
61
61
  * ```
62
62
  *
63
63
  * @throws Error: if a valid date cannot be created.
@@ -81,7 +81,7 @@ timezone) {
81
81
  * @example
82
82
  *
83
83
  * ```ts
84
- * import {toNewTimezone} from 'date-vir';
84
+ * import {toNewTimezone, TimezoneName, utcTimezone} from 'date-vir';
85
85
  *
86
86
  * const exampleDate: FullDate = {
87
87
  * year: 2024,
@@ -91,10 +91,10 @@ timezone) {
91
91
  * minute: 1,
92
92
  * second: 1,
93
93
  * millisecond: 1,
94
- * timezone: 'UTC',
94
+ * timezone: utcTimezone,
95
95
  * };
96
96
  *
97
- * let result = toNewTimezone(exampleDate, timezones['Australia/Brisbane']);
97
+ * let result = toNewTimezone(exampleDate, TimezoneName['Australia/Brisbane']);
98
98
  * // output:
99
99
  * result = {
100
100
  * year: 2024,
@@ -104,7 +104,7 @@ timezone) {
104
104
  * minute: 1,
105
105
  * second: 1,
106
106
  * millisecond: 1,
107
- * timezone: timezones['Australia/Brisbane'],
107
+ * timezone: TimezoneName['Australia/Brisbane'],
108
108
  * };
109
109
  * ```
110
110
  */
@@ -1,8 +1,9 @@
1
1
  import { type DateTime } from 'luxon';
2
+ import { type Timezone } from '../timezone/timezones.js';
2
3
  import { type FullDate } from './full-date-shape.js';
3
4
  /**
4
5
  * Types that can be converted into {@link FullDate} instances.
5
6
  *
6
7
  * @category Internal
7
8
  */
8
- export type DateLike<SpecificTimezone extends string = string> = string | Date | number | DateTime | FullDate<SpecificTimezone>;
9
+ export type DateLike<SpecificTimezone extends Timezone = Timezone> = string | Date | number | DateTime | FullDate<SpecificTimezone>;
@@ -1,6 +1,7 @@
1
1
  import { type Overwrite, type SetRequired } from '@augment-vir/common';
2
2
  import { type DayOfMonth, type Hour, type Minute, type MonthNumber, type Second } from '@date-vir/duration';
3
3
  import { type Simplify } from 'type-fest';
4
+ import { type Timezone } from '../timezone/timezones.js';
4
5
  /**
5
6
  * Time part of {@link FullDate} represented in a shape definition.
6
7
  *
@@ -16,14 +17,14 @@ export declare const timePartShape: import("object-shape-tester").Shape<{
16
17
  /** Millisecond of the second: 0-999 */
17
18
  millisecond: import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<number>>;
18
19
  /** The timezone that this date/time is meant for / originated from. */
19
- timezone: import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<string>>;
20
+ timezone: import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<Timezone>>;
20
21
  }>;
21
22
  /**
22
23
  * Time part of a {@link FullDate}.
23
24
  *
24
25
  * @category Internal
25
26
  */
26
- export type TimePart<SpecificTimezone extends string = string> = SetRequired<Partial<FullDate<SpecificTimezone>>, keyof (typeof timePartShape)['runtimeType']>;
27
+ export type TimePart<SpecificTimezone extends Timezone = Timezone> = SetRequired<Partial<FullDate<SpecificTimezone>>, keyof (typeof timePartShape)['runtimeType']>;
27
28
  /**
28
29
  * Date part of {@link FullDate} represented in a shape definition.
29
30
  *
@@ -41,14 +42,14 @@ export declare const datePartShape: import("object-shape-tester").Shape<{
41
42
  /** A day of the month: 1-31 depending on the month */
42
43
  day: import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<DayOfMonth>>;
43
44
  /** The timezone that this date/time is meant for / originated from. */
44
- timezone: import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<string>>;
45
+ timezone: import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<Timezone>>;
45
46
  }>;
46
47
  /**
47
48
  * Date part of {@link FullDate}.
48
49
  *
49
50
  * @category Internal
50
51
  */
51
- export type DatePart<SpecificTimezone extends string = string> = SetRequired<Partial<FullDate<SpecificTimezone>>, keyof (typeof datePartShape)['runtimeType']>;
52
+ export type DatePart<SpecificTimezone extends Timezone = Timezone> = SetRequired<Partial<FullDate<SpecificTimezone>>, keyof (typeof datePartShape)['runtimeType']>;
52
53
  /**
53
54
  * The complete {@link FullDate} represented in a shape definition.
54
55
  *
@@ -59,12 +60,12 @@ export declare const fullDateShape: import("object-shape-tester").Shape<import("
59
60
  minute: Minute;
60
61
  second: Minute;
61
62
  millisecond: number;
62
- timezone: string;
63
+ timezone: Timezone;
63
64
  } & {
64
65
  year: number;
65
66
  month: MonthNumber;
66
67
  day: DayOfMonth;
67
- timezone: string;
68
+ timezone: Timezone;
68
69
  }>>>;
69
70
  /**
70
71
  * A serializable object that completely specifies how any given date should be represented,
@@ -75,7 +76,7 @@ export declare const fullDateShape: import("object-shape-tester").Shape<import("
75
76
  * @example
76
77
  *
77
78
  * ```ts
78
- * import {FullDate, timezones} from 'date-vir';
79
+ * import {FullDate, TimezoneName} from 'date-vir';
79
80
  *
80
81
  * const myDate: FullDate = {
81
82
  * year: 2024,
@@ -87,11 +88,11 @@ export declare const fullDateShape: import("object-shape-tester").Shape<import("
87
88
  * second: 12,
88
89
  *
89
90
  * milliseconds: 94,
90
- * timezone: timezones['Australia/Brisbane'],
91
+ * timezone: TimezoneName['Australia/Brisbane'],
91
92
  * };
92
93
  * ```
93
94
  */
94
- export type FullDate<SpecificTimezone extends string = string> = Simplify<Overwrite<(typeof fullDateShape)['runtimeType'], {
95
+ export type FullDate<SpecificTimezone extends Timezone = Timezone> = Simplify<Overwrite<(typeof fullDateShape)['runtimeType'], {
95
96
  second: Second;
96
97
  timezone: SpecificTimezone;
97
98
  }>>;
@@ -1,3 +1,4 @@
1
+ import { type Timezone } from '../timezone/timezones.js';
1
2
  import { type FullDate } from './full-date-shape.js';
2
3
  /**
3
4
  * Asserts that the input is a valid {@link FullDate}.
@@ -17,4 +18,4 @@ export declare function isValidFullDate(input: unknown): input is FullDate;
17
18
  *
18
19
  * @category Assertion
19
20
  */
20
- export declare function hasTimezone<const SpecificTimezone extends string>(input: FullDate, timezone: SpecificTimezone): input is FullDate<SpecificTimezone>;
21
+ export declare function hasTimezone<const SpecificTimezone extends Timezone>(input: FullDate, timezone: SpecificTimezone): input is FullDate<SpecificTimezone>;
@@ -1,4 +1,5 @@
1
1
  import { DateTime } from 'luxon';
2
+ import { type Timezone } from '../timezone/timezones.js';
2
3
  import { type FullDate } from './full-date-shape.js';
3
4
  /**
4
5
  * Converts a {@link FullDate} object into a Luxon DateTime library. This is only needed if you need
@@ -15,4 +16,4 @@ export declare function toLuxonDateTime(fullDateInput: Readonly<FullDate>): Date
15
16
  *
16
17
  * @category Internal
17
18
  */
18
- export declare function parseLuxonDateTime<const SpecificTimezone extends string>(dateTimeInput: Readonly<DateTime>, forcedTimezone?: SpecificTimezone): FullDate<SpecificTimezone>;
19
+ export declare function parseLuxonDateTime<const SpecificTimezone extends Timezone>(dateTimeInput: Readonly<DateTime>, forcedTimezone?: SpecificTimezone): FullDate<SpecificTimezone>;
@@ -1,4 +1,4 @@
1
- import { omitObjectKeys } from '@augment-vir/common';
1
+ import { applyBrand, omitObjectKeys } from '@augment-vir/common';
2
2
  import { assertWrapDayOfMonth, assertWrapHour, assertWrapMillisecond, assertWrapMinute, assertWrapMonthNumber, assertWrapSecond, } from '@date-vir/duration';
3
3
  import { DateTime } from 'luxon';
4
4
  /**
@@ -30,6 +30,11 @@ export function parseLuxonDateTime(dateTimeInput, forcedTimezone) {
30
30
  if (!dateTimeInput.isValid) {
31
31
  throw new Error(`Invalid input: '${dateTimeInput.toISO()}'`);
32
32
  }
33
+ const zoneName = dateTimeInput.zoneName;
34
+ if (zoneName == undefined) {
35
+ throw new Error('Valid Luxon dates must have a timezone.');
36
+ }
37
+ const brandedZoneName = applyBrand(zoneName);
33
38
  return {
34
39
  day: assertWrapDayOfMonth(dateTimeInput.day),
35
40
  month: assertWrapMonthNumber(dateTimeInput.month),
@@ -38,6 +43,6 @@ export function parseLuxonDateTime(dateTimeInput, forcedTimezone) {
38
43
  minute: assertWrapMinute(dateTimeInput.minute),
39
44
  second: assertWrapSecond(dateTimeInput.second),
40
45
  millisecond: assertWrapMillisecond(dateTimeInput.millisecond),
41
- timezone: forcedTimezone ?? dateTimeInput.zoneName,
46
+ timezone: forcedTimezone ?? brandedZoneName,
42
47
  };
43
48
  }
@@ -1,3 +1,4 @@
1
+ import { type Timezone } from '../timezone/timezones.js';
1
2
  import { type DateLike } from './date-like.js';
2
3
  import { type FullDate } from './full-date-shape.js';
3
4
  /**
@@ -5,7 +6,7 @@ import { type FullDate } from './full-date-shape.js';
5
6
  * timezone. If the conversion fails or the input {@link DateLike} is empty, `undefined` is
6
7
  * returned.
7
8
  */
8
- export declare function maybeCreateFullDate<const SpecificTimezone extends string>(
9
+ export declare function maybeCreateFullDate<const SpecificTimezone extends Timezone>(
9
10
  /** The original date representation to be converted into a FullDate. */
10
11
  dateLike: Readonly<DateLike> | undefined | null,
11
12
  /** The timezone that this date/time is meant for / originated from. */
@@ -1,3 +1,4 @@
1
+ import { type Timezone } from '../timezone/timezones.js';
1
2
  import { type FullDate } from './full-date-shape.js';
2
3
  /**
3
4
  * Parses any date string into a {@link FullDate} using the specified pattern and timezone. Prefer
@@ -11,7 +12,7 @@ import { type FullDate } from './full-date-shape.js';
11
12
  *
12
13
  * @category FullDate
13
14
  */
14
- export declare function parseDateStringWithPattern<const SpecificTimezone extends string>({ dateString, formatString, timezone, }: {
15
+ export declare function parseDateStringWithPattern<const SpecificTimezone extends Timezone>({ dateString, formatString, timezone, }: {
15
16
  /** The date string to be parsed. */
16
17
  dateString: string;
17
18
  /**
@@ -29,4 +30,4 @@ export declare function parseDateStringWithPattern<const SpecificTimezone extend
29
30
  * @category FullDate
30
31
  * @category HTML
31
32
  */
32
- export declare function parseInputElementValue<const SpecificTimezone extends string>(elementOrValue: Readonly<Pick<HTMLInputElement, 'value'>> | string | null | undefined, timezone: SpecificTimezone): FullDate<SpecificTimezone> | undefined;
33
+ export declare function parseInputElementValue<const SpecificTimezone extends Timezone>(elementOrValue: Readonly<Pick<HTMLInputElement, 'value'>> | string | null | undefined, timezone: SpecificTimezone): FullDate<SpecificTimezone> | undefined;
@@ -1,8 +1,9 @@
1
1
  import { DateTime } from 'luxon';
2
+ import { type Timezone } from '../timezone/timezones.js';
2
3
  /**
3
4
  * Tries extra known formats for parsing date strings, even those that browsers do not natively
4
5
  * support.
5
6
  *
6
7
  * @category Internal
7
8
  */
8
- export declare function parseDateString(dateString: string, timezone: string): DateTime | undefined;
9
+ export declare function parseDateString(dateString: string, timezone: Timezone): DateTime | undefined;
@@ -1,4 +1,3 @@
1
- /* eslint-disable @virmator/prefer-params-object */
2
1
  import { DateTime } from 'luxon';
3
2
  /**
4
3
  * These formats are for luxon, documented here:
@@ -1,3 +1,4 @@
1
+ import { type Timezone } from './timezones.js';
1
2
  /**
2
3
  * Checks that the given timezone is valid.
3
4
  *
@@ -7,7 +8,7 @@
7
8
  *
8
9
  * @category Assertion
9
10
  */
10
- export declare function isValidTimezone(potentialTimezone: string): boolean;
11
+ export declare function isValidTimezone(raw: string): raw is Timezone;
11
12
  /**
12
13
  * Asserts that the given input is a valid timezone name.
13
14
  *
@@ -17,4 +18,16 @@ export declare function isValidTimezone(potentialTimezone: string): boolean;
17
18
  *
18
19
  * @category Assertion
19
20
  */
20
- export declare function assertValidTimezone(potentialTimezone: string, userMessage?: string | undefined): void;
21
+ export declare function assertValidTimezone(raw: string, userMessage?: string | undefined): asserts raw is Timezone;
22
+ /**
23
+ * Asserts that the given input is a valid timezone name and returns it.
24
+ *
25
+ * @category Assertion
26
+ */
27
+ export declare function assertWrapValidTimezone(raw: string, userMessage?: string | undefined): Timezone;
28
+ /**
29
+ * Checks that the given input is a valid timezone name and returns it when valid.
30
+ *
31
+ * @category Assertion
32
+ */
33
+ export declare function checkWrapValidTimezone(raw: string): Timezone | undefined;
@@ -19,16 +19,16 @@ const ianaValidityCache = new Map();
19
19
  *
20
20
  * @category Assertion
21
21
  */
22
- export function isValidTimezone(potentialTimezone) {
23
- if (knownTimezones.has(potentialTimezone)) {
22
+ export function isValidTimezone(raw) {
23
+ if (knownTimezones.has(raw)) {
24
24
  return true;
25
25
  }
26
- const cached = ianaValidityCache.get(potentialTimezone);
26
+ const cached = ianaValidityCache.get(raw);
27
27
  if (cached != undefined) {
28
28
  return cached;
29
29
  }
30
- const isValid = Info.isValidIANAZone(potentialTimezone);
31
- ianaValidityCache.set(potentialTimezone, isValid);
30
+ const isValid = Info.isValidIANAZone(raw);
31
+ ianaValidityCache.set(raw, isValid);
32
32
  return isValid;
33
33
  }
34
34
  /**
@@ -40,8 +40,25 @@ export function isValidTimezone(potentialTimezone) {
40
40
  *
41
41
  * @category Assertion
42
42
  */
43
- export function assertValidTimezone(potentialTimezone, userMessage) {
44
- if (!isValidTimezone(potentialTimezone)) {
45
- throw new AssertionError(`'${potentialTimezone}' is not a valid time zone`, userMessage);
43
+ export function assertValidTimezone(raw, userMessage) {
44
+ if (!isValidTimezone(raw)) {
45
+ throw new AssertionError(`'${raw}' is not a valid time zone`, userMessage);
46
46
  }
47
47
  }
48
+ /**
49
+ * Asserts that the given input is a valid timezone name and returns it.
50
+ *
51
+ * @category Assertion
52
+ */
53
+ export function assertWrapValidTimezone(raw, userMessage) {
54
+ assertValidTimezone(raw, userMessage);
55
+ return raw;
56
+ }
57
+ /**
58
+ * Checks that the given input is a valid timezone name and returns it when valid.
59
+ *
60
+ * @category Assertion
61
+ */
62
+ export function checkWrapValidTimezone(raw) {
63
+ return isValidTimezone(raw) ? raw : undefined;
64
+ }
@@ -1,12 +1,13 @@
1
+ import { type Timezone } from './timezones.js';
1
2
  /**
2
3
  * A shape for a timezone value.
3
4
  *
4
5
  * Unlike a strict enum check against the typed {@link Timezone} list, this validates at runtime via
5
6
  * {@link isValidTimezone} (i.e. any valid IANA zone name). It therefore accepts valid IANA names
6
7
  * that aren't in the typed list, such as legacy aliases like `'America/Indianapolis'` that some
7
- * environments (notably Safari) still report from `Intl`. The static type is `string` so that
8
- * timezone inputs are not restricted to the {@link Timezone} enum.
8
+ * environments (notably Safari) still report from `Intl`. The branded {@link Timezone} type allows
9
+ * timezone inputs that are not restricted to the {@link Timezone} list.
9
10
  *
10
11
  * @category Shape
11
12
  */
12
- export declare const timezoneShape: (defaultValue?: string | undefined) => import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<string>>;
13
+ export declare const timezoneShape: (defaultValue?: Timezone | undefined) => import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<Timezone>>;
@@ -8,8 +8,8 @@ import { utcTimezone } from './timezones.js';
8
8
  * Unlike a strict enum check against the typed {@link Timezone} list, this validates at runtime via
9
9
  * {@link isValidTimezone} (i.e. any valid IANA zone name). It therefore accepts valid IANA names
10
10
  * that aren't in the typed list, such as legacy aliases like `'America/Indianapolis'` that some
11
- * environments (notably Safari) still report from `Intl`. The static type is `string` so that
12
- * timezone inputs are not restricted to the {@link Timezone} enum.
11
+ * environments (notably Safari) still report from `Intl`. The branded {@link Timezone} type allows
12
+ * timezone inputs that are not restricted to the {@link Timezone} list.
13
13
  *
14
14
  * @category Shape
15
15
  */
@@ -1,12 +1,25 @@
1
- import { type ArrayElement } from '@augment-vir/common';
1
+ import { type ArrayElement, type Branded } from '@augment-vir/common';
2
2
  import { allTimezoneNames } from './timezone-names.js';
3
3
  /**
4
- * All possible timezone names.
4
+ * All known timezone names.
5
5
  *
6
6
  * @category Timezone
7
7
  * @see {@link allTimezoneNames}
8
8
  */
9
- export type Timezone = ArrayElement<typeof allTimezoneNames>;
9
+ export type TimezoneName = ArrayElement<typeof allTimezoneNames>;
10
+ /**
11
+ * A branded string for any timezone
12
+ *
13
+ * @category Timezone
14
+ * @see {@link allTimezoneNames}
15
+ */
16
+ export type TimezoneString = Branded<string, 'timezone-string'>;
17
+ /**
18
+ * Any known or unknown timezone.
19
+ *
20
+ * @category Timezone
21
+ */
22
+ export type Timezone = TimezoneString | TimezoneName;
10
23
  /**
11
24
  * An enum of all possible timezone names.
12
25
  *
@@ -14,20 +27,20 @@ export type Timezone = ArrayElement<typeof allTimezoneNames>;
14
27
  * @example
15
28
  *
16
29
  * ```ts
17
- * import {Timezone} from 'date-vir';
30
+ * import {TimezoneName} from 'date-vir';
18
31
  *
19
- * Timezone['Africa/Bamako'];
32
+ * TimezoneName['Africa/Bamako'];
20
33
  * ```
21
34
  */
22
- export declare const Timezone: Readonly<{
23
- [SpecificTimezoneName in Timezone]: SpecificTimezoneName;
35
+ export declare const TimezoneName: Readonly<{
36
+ [SpecificTimezoneName in TimezoneName]: SpecificTimezoneName;
24
37
  }>;
25
38
  /**
26
39
  * The timezone of the current user's environment.
27
40
  *
28
41
  * @category Timezone
29
42
  */
30
- export declare const userTimezone: string;
43
+ export declare const userTimezone: NoInfer<TimezoneString>;
31
44
  /**
32
45
  * The UTC timezone.
33
46
  *
@@ -1,3 +1,4 @@
1
+ import { applyBrand } from '@augment-vir/common';
1
2
  import { Settings } from 'luxon';
2
3
  import { allTimezoneNames } from './timezone-names.js';
3
4
  /**
@@ -7,12 +8,12 @@ import { allTimezoneNames } from './timezone-names.js';
7
8
  * @example
8
9
  *
9
10
  * ```ts
10
- * import {Timezone} from 'date-vir';
11
+ * import {TimezoneName} from 'date-vir';
11
12
  *
12
- * Timezone['Africa/Bamako'];
13
+ * TimezoneName['Africa/Bamako'];
13
14
  * ```
14
15
  */
15
- export const Timezone = allTimezoneNames.reduce((accum, timezoneName) => {
16
+ export const TimezoneName = allTimezoneNames.reduce((accum, timezoneName) => {
16
17
  accum[timezoneName] = timezoneName;
17
18
  return accum;
18
19
  }, {});
@@ -21,10 +22,10 @@ export const Timezone = allTimezoneNames.reduce((accum, timezoneName) => {
21
22
  *
22
23
  * @category Timezone
23
24
  */
24
- export const userTimezone = Settings.defaultZone.name;
25
+ export const userTimezone = applyBrand(Settings.defaultZone.name);
25
26
  /**
26
27
  * The UTC timezone.
27
28
  *
28
29
  * @category Timezone
29
30
  */
30
- export const utcTimezone = Timezone.UTC;
31
+ export const utcTimezone = TimezoneName.UTC;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-vir",
3
- "version": "8.6.4",
3
+ "version": "9.0.0",
4
4
  "description": "Easy and explicit dates and times.",
5
5
  "keywords": [
6
6
  "date",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@augment-vir/assert": "^32.2.1",
39
39
  "@augment-vir/common": "^32.2.1",
40
- "@date-vir/duration": "^8.6.4",
40
+ "@date-vir/duration": "^9.0.0",
41
41
  "@types/luxon": "^3.7.3",
42
42
  "luxon": "^3.7.2",
43
43
  "object-shape-tester": "^6.14.1",