date-vir 8.6.4 → 9.1.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 (39) 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/duration-shape.d.ts +294 -0
  8. package/dist/duration-shape.js +18 -1
  9. package/dist/extra-utils/has-date-props.d.ts +3 -2
  10. package/dist/extra-utils/js-date-conversion.d.ts +2 -2
  11. package/dist/extra-utils/js-date-conversion.js +2 -2
  12. package/dist/extra-utils/now.d.ts +4 -4
  13. package/dist/extra-utils/now.js +2 -2
  14. package/dist/extra-utils/override-date.d.ts +5 -4
  15. package/dist/extra-utils/override-date.js +3 -3
  16. package/dist/extra-utils/zero.d.ts +9 -8
  17. package/dist/extra-utils/zero.js +6 -6
  18. package/dist/formatting/simple-strings.d.ts +7 -6
  19. package/dist/formatting/simple-strings.js +1 -1
  20. package/dist/formatting/timestamp.d.ts +6 -6
  21. package/dist/formatting/timestamp.js +6 -6
  22. package/dist/full-date/create-full-date.d.ts +10 -10
  23. package/dist/full-date/create-full-date.js +7 -7
  24. package/dist/full-date/date-like.d.ts +2 -1
  25. package/dist/full-date/full-date-shape.d.ts +10 -9
  26. package/dist/full-date/is-valid-full-date.d.ts +2 -1
  27. package/dist/full-date/luxon-date-time-conversion.d.ts +2 -1
  28. package/dist/full-date/luxon-date-time-conversion.js +7 -2
  29. package/dist/full-date/maybe-create-date.d.ts +2 -1
  30. package/dist/full-date/parsing.d.ts +3 -2
  31. package/dist/full-date/string-parsing.d.ts +2 -1
  32. package/dist/full-date/string-parsing.js +0 -1
  33. package/dist/timezone/timezone-checks.d.ts +15 -2
  34. package/dist/timezone/timezone-checks.js +25 -8
  35. package/dist/timezone/timezone-shape.d.ts +4 -3
  36. package/dist/timezone/timezone-shape.js +2 -2
  37. package/dist/timezone/timezones.d.ts +21 -8
  38. package/dist/timezone/timezones.js +6 -5
  39. package/package.json +2 -2
@@ -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.1.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.1.0",
41
41
  "@types/luxon": "^3.7.3",
42
42
  "luxon": "^3.7.2",
43
43
  "object-shape-tester": "^6.14.1",