date-vir 5.3.2 → 7.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 (147) hide show
  1. package/LICENSE-MIT +1 -1
  2. package/README.md +28 -28
  3. package/dist/date-operations/calculate-relative-date.d.ts +17 -0
  4. package/dist/{esm/date-operations → date-operations}/calculate-relative-date.js +10 -1
  5. package/dist/date-operations/combine-dates.d.ts +43 -0
  6. package/dist/{esm/date-operations → date-operations}/combine-dates.js +6 -4
  7. package/dist/date-operations/date-position.d.ts +149 -0
  8. package/dist/date-operations/date-position.js +175 -0
  9. package/dist/date-operations/diff-dates.d.ts +95 -0
  10. package/dist/date-operations/diff-dates.js +124 -0
  11. package/dist/extra-utils/end.d.ts +11 -0
  12. package/dist/extra-utils/end.js +11 -0
  13. package/dist/extra-utils/has-date-props.d.ts +35 -0
  14. package/dist/extra-utils/has-date-props.js +46 -0
  15. package/dist/extra-utils/js-date-conversion.d.ts +26 -0
  16. package/dist/extra-utils/js-date-conversion.js +28 -0
  17. package/dist/extra-utils/now.d.ts +56 -0
  18. package/dist/extra-utils/now.js +68 -0
  19. package/dist/extra-utils/override-date.d.ts +27 -0
  20. package/dist/extra-utils/override-date.js +27 -0
  21. package/dist/extra-utils/zero.d.ts +109 -0
  22. package/dist/extra-utils/zero.js +94 -0
  23. package/dist/formatting/formatted-string.d.ts +58 -0
  24. package/dist/formatting/formatted-string.js +73 -0
  25. package/dist/formatting/html-input.d.ts +30 -0
  26. package/dist/formatting/html-input.js +47 -0
  27. package/dist/formatting/relative-string.d.ts +53 -0
  28. package/dist/formatting/relative-string.js +93 -0
  29. package/dist/formatting/simple-strings.d.ts +187 -0
  30. package/dist/formatting/simple-strings.js +120 -0
  31. package/dist/formatting/string-format-types.d.ts +59 -0
  32. package/dist/formatting/string-format-types.js +19 -0
  33. package/dist/formatting/timestamp.d.ts +51 -0
  34. package/dist/formatting/timestamp.js +61 -0
  35. package/dist/full-date/create-full-date.d.ts +91 -0
  36. package/dist/full-date/create-full-date.js +142 -0
  37. package/dist/full-date/date-like.d.ts +9 -0
  38. package/dist/{esm/full-date → full-date}/format-presets.d.ts +4 -2
  39. package/dist/{esm/full-date → full-date}/format-presets.js +4 -2
  40. package/dist/full-date/full-date-parts.d.ts +44 -0
  41. package/dist/full-date/full-date-parts.js +47 -0
  42. package/dist/full-date/full-date-shape.d.ts +108 -0
  43. package/dist/full-date/full-date-shape.js +45 -0
  44. package/dist/full-date/is-valid-full-date.d.ts +21 -0
  45. package/dist/full-date/is-valid-full-date.js +38 -0
  46. package/dist/full-date/luxon-date-time-conversion.d.ts +19 -0
  47. package/dist/full-date/luxon-date-time-conversion.js +43 -0
  48. package/dist/full-date/parsing.d.ts +33 -0
  49. package/dist/full-date/parsing.js +47 -0
  50. package/dist/full-date/string-parsing.d.ts +9 -0
  51. package/dist/{esm/full-date → full-date}/string-parsing.js +6 -0
  52. package/dist/index.d.ts +29 -0
  53. package/dist/index.js +29 -0
  54. package/dist/locales.d.ts +6 -0
  55. package/dist/locales.js +7 -0
  56. package/dist/timezone/timezone-checks.d.ts +21 -0
  57. package/dist/timezone/timezone-checks.js +34 -0
  58. package/dist/{esm/timezone → timezone}/timezone-names.d.ts +11 -5
  59. package/dist/{esm/timezone → timezone}/timezone-names.js +11 -3
  60. package/dist/timezone/timezones.d.ts +42 -0
  61. package/dist/timezone/timezones.js +31 -0
  62. package/package.json +33 -51
  63. package/cspell.config.cjs +0 -13
  64. package/dist/cjs/date-operations/calculate-relative-date.js +0 -12
  65. package/dist/cjs/date-operations/combine-dates.js +0 -50
  66. package/dist/cjs/date-operations/diff-dates.js +0 -105
  67. package/dist/cjs/duration/duration-unit.js +0 -41
  68. package/dist/cjs/duration/duration-utils.js +0 -42
  69. package/dist/cjs/duration/duration.js +0 -2
  70. package/dist/cjs/extra-utils/date-transforms.js +0 -8
  71. package/dist/cjs/extra-utils/has-date-props.js +0 -25
  72. package/dist/cjs/extra-utils/js-date-conversion.js +0 -8
  73. package/dist/cjs/extra-utils/now.js +0 -22
  74. package/dist/cjs/extra-utils/zero.js +0 -31
  75. package/dist/cjs/formatting/formatted-string.js +0 -34
  76. package/dist/cjs/formatting/html-input.js +0 -37
  77. package/dist/cjs/formatting/relative-string.js +0 -77
  78. package/dist/cjs/formatting/simple-strings.js +0 -58
  79. package/dist/cjs/formatting/string-format-types.js +0 -9
  80. package/dist/cjs/formatting/timestamp.js +0 -21
  81. package/dist/cjs/full-date/create-full-date.js +0 -81
  82. package/dist/cjs/full-date/date-like.js +0 -2
  83. package/dist/cjs/full-date/format-presets.js +0 -32
  84. package/dist/cjs/full-date/full-date-shape.js +0 -54
  85. package/dist/cjs/full-date/is-valid-full-date.js +0 -28
  86. package/dist/cjs/full-date/luxon-date-time-conversion.js +0 -43
  87. package/dist/cjs/full-date/parsing.js +0 -48
  88. package/dist/cjs/full-date/string-parsing.js +0 -33
  89. package/dist/cjs/index.js +0 -44
  90. package/dist/cjs/locales.js +0 -5
  91. package/dist/cjs/timezone/timezone-checks.js +0 -34
  92. package/dist/cjs/timezone/timezone-names.js +0 -479
  93. package/dist/cjs/timezone/timezones.js +0 -14
  94. package/dist/esm/date-operations/calculate-relative-date.d.ts +0 -8
  95. package/dist/esm/date-operations/combine-dates.d.ts +0 -35
  96. package/dist/esm/date-operations/diff-dates.d.ts +0 -66
  97. package/dist/esm/date-operations/diff-dates.js +0 -100
  98. package/dist/esm/duration/duration-unit.d.ts +0 -27
  99. package/dist/esm/duration/duration-unit.js +0 -38
  100. package/dist/esm/duration/duration-utils.d.ts +0 -11
  101. package/dist/esm/duration/duration-utils.js +0 -37
  102. package/dist/esm/duration/duration.d.ts +0 -32
  103. package/dist/esm/duration/duration.js +0 -1
  104. package/dist/esm/extra-utils/date-transforms.d.ts +0 -4
  105. package/dist/esm/extra-utils/date-transforms.js +0 -4
  106. package/dist/esm/extra-utils/has-date-props.d.ts +0 -9
  107. package/dist/esm/extra-utils/has-date-props.js +0 -20
  108. package/dist/esm/extra-utils/js-date-conversion.d.ts +0 -2
  109. package/dist/esm/extra-utils/js-date-conversion.js +0 -4
  110. package/dist/esm/extra-utils/now.d.ts +0 -6
  111. package/dist/esm/extra-utils/now.js +0 -16
  112. package/dist/esm/extra-utils/zero.d.ts +0 -31
  113. package/dist/esm/extra-utils/zero.js +0 -26
  114. package/dist/esm/formatting/formatted-string.d.ts +0 -14
  115. package/dist/esm/formatting/formatted-string.js +0 -29
  116. package/dist/esm/formatting/html-input.d.ts +0 -19
  117. package/dist/esm/formatting/html-input.js +0 -33
  118. package/dist/esm/formatting/relative-string.d.ts +0 -31
  119. package/dist/esm/formatting/relative-string.js +0 -73
  120. package/dist/esm/formatting/simple-strings.d.ts +0 -71
  121. package/dist/esm/formatting/simple-strings.js +0 -51
  122. package/dist/esm/formatting/string-format-types.d.ts +0 -7
  123. package/dist/esm/formatting/string-format-types.js +0 -5
  124. package/dist/esm/formatting/timestamp.d.ts +0 -6
  125. package/dist/esm/formatting/timestamp.js +0 -16
  126. package/dist/esm/full-date/create-full-date.d.ts +0 -21
  127. package/dist/esm/full-date/create-full-date.js +0 -73
  128. package/dist/esm/full-date/date-like.d.ts +0 -5
  129. package/dist/esm/full-date/full-date-shape.d.ts +0 -80
  130. package/dist/esm/full-date/full-date-shape.js +0 -51
  131. package/dist/esm/full-date/is-valid-full-date.d.ts +0 -5
  132. package/dist/esm/full-date/is-valid-full-date.js +0 -22
  133. package/dist/esm/full-date/luxon-date-time-conversion.d.ts +0 -15
  134. package/dist/esm/full-date/luxon-date-time-conversion.js +0 -38
  135. package/dist/esm/full-date/parsing.d.ts +0 -27
  136. package/dist/esm/full-date/parsing.js +0 -43
  137. package/dist/esm/full-date/string-parsing.d.ts +0 -3
  138. package/dist/esm/index.d.ts +0 -28
  139. package/dist/esm/index.js +0 -28
  140. package/dist/esm/locales.d.ts +0 -1
  141. package/dist/esm/locales.js +0 -2
  142. package/dist/esm/timezone/timezone-checks.d.ts +0 -17
  143. package/dist/esm/timezone/timezone-checks.js +0 -29
  144. package/dist/esm/timezone/timezones.d.ts +0 -480
  145. package/dist/esm/timezone/timezones.js +0 -11
  146. package/public/index.css +0 -7
  147. /package/dist/{esm/full-date → full-date}/date-like.js +0 -0
@@ -0,0 +1,108 @@
1
+ import { Overwrite, type SetRequired } from '@augment-vir/common';
2
+ import { type DayOfMonth, type Hour, type Minute, type MonthNumber } from '@date-vir/duration';
3
+ import type { Simplify } from 'type-fest';
4
+ import { type Timezone } from '../timezone/timezones.js';
5
+ /**
6
+ * Time part of {@link FullDate} represented in a shape definition.
7
+ *
8
+ * @category Shape
9
+ */
10
+ export declare const timePartShape: import("object-shape-tester").ShapeDefinition<{
11
+ /** Hour of the day in 24 time: 0-23 */
12
+ hour: import("object-shape-tester").ShapeNumericRange<Hour>;
13
+ /** Minute of the hour: 0-59 */
14
+ minute: import("object-shape-tester").ShapeNumericRange<Minute>;
15
+ /** Second of the minute: 0-59 */
16
+ second: import("object-shape-tester").ShapeNumericRange<Minute>;
17
+ /** Millisecond of the second: 0-999 */
18
+ millisecond: import("object-shape-tester").ShapeNumericRange<number>;
19
+ /** The timezone that this date/time is meant for / originated from. */
20
+ timezone: Timezone;
21
+ }, false>;
22
+ /**
23
+ * Time part of a {@link FullDate}.
24
+ *
25
+ * @category Internal
26
+ */
27
+ export type TimePart<SpecificTimezone extends Timezone = Timezone> = SetRequired<Partial<FullDate<SpecificTimezone>>, keyof (typeof timePartShape)['runtimeType']>;
28
+ /**
29
+ * Date part of {@link FullDate} represented in a shape definition.
30
+ *
31
+ * @category Shape
32
+ */
33
+ export declare const datePartShape: import("object-shape-tester").ShapeDefinition<{
34
+ /**
35
+ * The full, four digit year.
36
+ *
37
+ * @example 2023;
38
+ */
39
+ year: number;
40
+ /** A month of the year: 1-12 */
41
+ month: import("object-shape-tester").ShapeNumericRange<MonthNumber>;
42
+ /** A day of the month: 1-31 depending on the month */
43
+ day: import("object-shape-tester").ShapeNumericRange<DayOfMonth>;
44
+ /** The timezone that this date/time is meant for / originated from. */
45
+ timezone: Timezone;
46
+ }, false>;
47
+ /**
48
+ * Date part of {@link FullDate}.
49
+ *
50
+ * @category Internal
51
+ */
52
+ export type DatePart<SpecificTimezone extends Timezone = Timezone> = SetRequired<Partial<FullDate<SpecificTimezone>>, keyof (typeof datePartShape)['runtimeType']>;
53
+ /**
54
+ * The complete {@link FullDate} represented in a shape definition.
55
+ *
56
+ * @category Shape
57
+ */
58
+ export declare const fullDateShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeAnd<[import("object-shape-tester").ShapeDefinition<{
59
+ /**
60
+ * The full, four digit year.
61
+ *
62
+ * @example 2023;
63
+ */
64
+ year: number;
65
+ /** A month of the year: 1-12 */
66
+ month: import("object-shape-tester").ShapeNumericRange<MonthNumber>;
67
+ /** A day of the month: 1-31 depending on the month */
68
+ day: import("object-shape-tester").ShapeNumericRange<DayOfMonth>;
69
+ /** The timezone that this date/time is meant for / originated from. */
70
+ timezone: Timezone;
71
+ }, false>, import("object-shape-tester").ShapeDefinition<{
72
+ /** Hour of the day in 24 time: 0-23 */
73
+ hour: import("object-shape-tester").ShapeNumericRange<Hour>;
74
+ /** Minute of the hour: 0-59 */
75
+ minute: import("object-shape-tester").ShapeNumericRange<Minute>;
76
+ /** Second of the minute: 0-59 */
77
+ second: import("object-shape-tester").ShapeNumericRange<Minute>;
78
+ /** Millisecond of the second: 0-999 */
79
+ millisecond: import("object-shape-tester").ShapeNumericRange<number>;
80
+ /** The timezone that this date/time is meant for / originated from. */
81
+ timezone: Timezone;
82
+ }, false>]>, false>;
83
+ /**
84
+ * A serializable object that completely specifies how any given date should be represented,
85
+ * including its timezone, to millisecond accuracy. This is the core type of the `date-vir` package,
86
+ * with most operations either requiring or returning this type.
87
+ *
88
+ * @category FullDate
89
+ * @example
90
+ *
91
+ * ```ts
92
+ * import {FullDate, timezones} from 'date-vir';
93
+ *
94
+ * const myDate: FullDate = {
95
+ * year: 2024,
96
+ * month: 6,
97
+ * day: 2,
98
+ * hour: 13,
99
+ * minute: 32,
100
+ * second: 12,
101
+ * milliseconds: 94,
102
+ * timezone: timezones['Australia/Brisbane'],
103
+ * };
104
+ * ```
105
+ */
106
+ export type FullDate<SpecificTimezone extends Timezone = Timezone> = Simplify<Overwrite<(typeof fullDateShape)['runtimeType'], {
107
+ timezone: SpecificTimezone;
108
+ }>>;
@@ -0,0 +1,45 @@
1
+ import { dayOfMonthBounds, hourBounds, millisecondsBounds, minuteBounds, monthNumberBounds, secondBounds, } from '@date-vir/duration';
2
+ import { and, defineShape, numericRange } from 'object-shape-tester';
3
+ import { utcTimezone } from '../timezone/timezones.js';
4
+ /**
5
+ * Time part of {@link FullDate} represented in a shape definition.
6
+ *
7
+ * @category Shape
8
+ */
9
+ export const timePartShape = defineShape({
10
+ /** Hour of the day in 24 time: 0-23 */
11
+ hour: numericRange(hourBounds.min, hourBounds.max),
12
+ /** Minute of the hour: 0-59 */
13
+ minute: numericRange(minuteBounds.min, minuteBounds.max),
14
+ /** Second of the minute: 0-59 */
15
+ second: numericRange(secondBounds.min, secondBounds.max),
16
+ /** Millisecond of the second: 0-999 */
17
+ millisecond: numericRange(millisecondsBounds.min, millisecondsBounds.max),
18
+ /** The timezone that this date/time is meant for / originated from. */
19
+ timezone: utcTimezone,
20
+ });
21
+ /**
22
+ * Date part of {@link FullDate} represented in a shape definition.
23
+ *
24
+ * @category Shape
25
+ */
26
+ export const datePartShape = defineShape({
27
+ /**
28
+ * The full, four digit year.
29
+ *
30
+ * @example 2023;
31
+ */
32
+ year: 2023,
33
+ /** A month of the year: 1-12 */
34
+ month: numericRange(monthNumberBounds.min, monthNumberBounds.max),
35
+ /** A day of the month: 1-31 depending on the month */
36
+ day: numericRange(dayOfMonthBounds.min, dayOfMonthBounds.max),
37
+ /** The timezone that this date/time is meant for / originated from. */
38
+ timezone: utcTimezone,
39
+ });
40
+ /**
41
+ * The complete {@link FullDate} represented in a shape definition.
42
+ *
43
+ * @category Shape
44
+ */
45
+ export const fullDateShape = defineShape(and(datePartShape, timePartShape));
@@ -0,0 +1,21 @@
1
+ import { Timezone } from '../timezone/timezones.js';
2
+ import { FullDate } from './full-date-shape.js';
3
+ /**
4
+ * Asserts that the input is a valid {@link FullDate}.
5
+ *
6
+ * @category Assertion
7
+ * @throws An Error if the input is not a valid {@link FullDate}.
8
+ */
9
+ export declare function assertValidFullDate(input: unknown): asserts input is FullDate;
10
+ /**
11
+ * Checks and type guards that the input is a valid {@link FullDate}.
12
+ *
13
+ * @category Assertion
14
+ */
15
+ export declare function isValidFullDate(input: unknown): input is FullDate;
16
+ /**
17
+ * Checks and type guards that the given {@link FullDate} instance has the given timezone.
18
+ *
19
+ * @category Assertion
20
+ */
21
+ export declare function hasTimezone<const SpecificTimezone extends Timezone>(input: FullDate, timezone: SpecificTimezone): input is FullDate<SpecificTimezone>;
@@ -0,0 +1,38 @@
1
+ import { assertValidShape } from 'object-shape-tester';
2
+ import { assertValidTimezone } from '../timezone/timezone-checks.js';
3
+ import { fullDateShape } from './full-date-shape.js';
4
+ import { toLuxonDateTime } from './luxon-date-time-conversion.js';
5
+ /**
6
+ * Asserts that the input is a valid {@link FullDate}.
7
+ *
8
+ * @category Assertion
9
+ * @throws An Error if the input is not a valid {@link FullDate}.
10
+ */
11
+ export function assertValidFullDate(input) {
12
+ assertValidShape(input, fullDateShape);
13
+ assertValidTimezone(input.timezone);
14
+ /** Check that the input can be converted to a luxon date correctly. */
15
+ toLuxonDateTime(input);
16
+ }
17
+ /**
18
+ * Checks and type guards that the input is a valid {@link FullDate}.
19
+ *
20
+ * @category Assertion
21
+ */
22
+ export function isValidFullDate(input) {
23
+ try {
24
+ assertValidFullDate(input);
25
+ return true;
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }
31
+ /**
32
+ * Checks and type guards that the given {@link FullDate} instance has the given timezone.
33
+ *
34
+ * @category Assertion
35
+ */
36
+ export function hasTimezone(input, timezone) {
37
+ return input.timezone === timezone;
38
+ }
@@ -0,0 +1,19 @@
1
+ import { DateTime } from 'luxon';
2
+ import { Timezone } from '../timezone/timezones.js';
3
+ import { FullDate } from './full-date-shape.js';
4
+ /**
5
+ * Converts a {@link FullDate} object into a Luxon DateTime library. This is only needed if you need
6
+ * complex operations on dates. It does, however, internally power a lot of date-vir functionality
7
+ * as it uses the Luxon library for conversions between timezones.
8
+ *
9
+ * @category Internal
10
+ */
11
+ export declare function toLuxonDateTime(fullDateInput: Readonly<FullDate>): DateTime;
12
+ /**
13
+ * Convert a Luxon DateTime object into a {@link FullDate} instance. Used internally inside of
14
+ * date-vir, but could be helpful if you need it. Usually you should prefer using the
15
+ * `createFullDate` function instead.
16
+ *
17
+ * @category Internal
18
+ */
19
+ export declare function parseLuxonDateTime<const SpecificTimezone extends Timezone>(dateTimeInput: Readonly<DateTime>, forcedTimezone?: SpecificTimezone): FullDate<SpecificTimezone>;
@@ -0,0 +1,43 @@
1
+ import { omitObjectKeys } from '@augment-vir/common';
2
+ import { assertWrapDayOfMonth, assertWrapHour, assertWrapMillisecond, assertWrapMinute, assertWrapMonthNumber, assertWrapSecond, } from '@date-vir/duration';
3
+ import { DateTime } from 'luxon';
4
+ /**
5
+ * Converts a {@link FullDate} object into a Luxon DateTime library. This is only needed if you need
6
+ * complex operations on dates. It does, however, internally power a lot of date-vir functionality
7
+ * as it uses the Luxon library for conversions between timezones.
8
+ *
9
+ * @category Internal
10
+ */
11
+ export function toLuxonDateTime(fullDateInput) {
12
+ const dateTime = DateTime.fromObject(omitObjectKeys(fullDateInput, ['timezone']), {
13
+ zone: fullDateInput.timezone,
14
+ });
15
+ /** Ignore this edge case in coverage cause idk how to trigger it. */
16
+ /* c8 ignore next 3 */
17
+ if (!dateTime.isValid) {
18
+ throw new Error(dateTime.invalidExplanation ?? undefined);
19
+ }
20
+ return dateTime;
21
+ }
22
+ /**
23
+ * Convert a Luxon DateTime object into a {@link FullDate} instance. Used internally inside of
24
+ * date-vir, but could be helpful if you need it. Usually you should prefer using the
25
+ * `createFullDate` function instead.
26
+ *
27
+ * @category Internal
28
+ */
29
+ export function parseLuxonDateTime(dateTimeInput, forcedTimezone) {
30
+ if (!dateTimeInput.isValid) {
31
+ throw new Error(`Invalid input: '${dateTimeInput.toISO()}'`);
32
+ }
33
+ return {
34
+ day: assertWrapDayOfMonth(dateTimeInput.day),
35
+ month: assertWrapMonthNumber(dateTimeInput.month),
36
+ year: dateTimeInput.year,
37
+ hour: assertWrapHour(dateTimeInput.hour),
38
+ minute: assertWrapMinute(dateTimeInput.minute),
39
+ second: assertWrapSecond(dateTimeInput.second),
40
+ millisecond: assertWrapMillisecond(dateTimeInput.millisecond),
41
+ timezone: forcedTimezone ?? dateTimeInput.zoneName,
42
+ };
43
+ }
@@ -0,0 +1,33 @@
1
+ import { Timezone } from '../timezone/timezones.js';
2
+ import { FullDate } from './full-date-shape.js';
3
+ /**
4
+ * Parses any date string into a {@link FullDate} using the specified pattern and timezone. Prefer
5
+ * using {@link createFullDate} if possible.
6
+ *
7
+ * Since this supports any arbitrary date string pattern, it is more flexible than
8
+ * {@link createFullDate} but you must know the date pattern ahead of time.
9
+ *
10
+ * The `formatString` input is passed to Luxon. All format pattern options are listed here:
11
+ * https://moment.github.io/luxon/#/parsing?id=table-of-tokens
12
+ *
13
+ * @category FullDate
14
+ */
15
+ export declare function parseDateStringWithPattern<const SpecificTimezone extends Timezone>({ dateString, formatString, timezone, }: {
16
+ /** The date string to be parsed. */
17
+ dateString: string;
18
+ /**
19
+ * The format string that should match Luxon's expectations here:
20
+ * https://moment.github.io/luxon/#/parsing?id=table-of-tokens
21
+ */
22
+ formatString: string;
23
+ /** The timezone that this date/time is meant for / originated from. */
24
+ timezone: SpecificTimezone;
25
+ }): FullDate<SpecificTimezone>;
26
+ /**
27
+ * Read either an `HTMLInputElement`'s value directly, or the value string retrieved from an
28
+ * `HTMLInputElement`. Handles both `type="date"` and `type="time"` <input> elements.
29
+ *
30
+ * @category FullDate
31
+ * @category HTML
32
+ */
33
+ export declare function parseInputElementValue<const SpecificTimezone extends Timezone>(elementOrValue: Readonly<Pick<HTMLInputElement, 'value'>> | string | null | undefined, timezone: SpecificTimezone): FullDate<SpecificTimezone> | undefined;
@@ -0,0 +1,47 @@
1
+ import { check } from '@augment-vir/assert';
2
+ import { DateTime } from 'luxon';
3
+ import { createFullDate } from './create-full-date.js';
4
+ import { parseLuxonDateTime } from './luxon-date-time-conversion.js';
5
+ /**
6
+ * Parses any date string into a {@link FullDate} using the specified pattern and timezone. Prefer
7
+ * using {@link createFullDate} if possible.
8
+ *
9
+ * Since this supports any arbitrary date string pattern, it is more flexible than
10
+ * {@link createFullDate} but you must know the date pattern ahead of time.
11
+ *
12
+ * The `formatString` input is passed to Luxon. All format pattern options are listed here:
13
+ * https://moment.github.io/luxon/#/parsing?id=table-of-tokens
14
+ *
15
+ * @category FullDate
16
+ */
17
+ export function parseDateStringWithPattern({ dateString, formatString, timezone, }) {
18
+ try {
19
+ const dateTime = DateTime.fromFormat(dateString, formatString, {
20
+ zone: timezone,
21
+ setZone: true,
22
+ });
23
+ return parseLuxonDateTime(dateTime);
24
+ }
25
+ catch {
26
+ throw new Error(`Failed to parse string '${dateString}' with format '${formatString}'`);
27
+ }
28
+ }
29
+ /**
30
+ * Read either an `HTMLInputElement`'s value directly, or the value string retrieved from an
31
+ * `HTMLInputElement`. Handles both `type="date"` and `type="time"` <input> elements.
32
+ *
33
+ * @category FullDate
34
+ * @category HTML
35
+ */
36
+ export function parseInputElementValue(elementOrValue, timezone) {
37
+ if (!elementOrValue) {
38
+ return undefined;
39
+ }
40
+ const value = check.isString(elementOrValue) ? elementOrValue : elementOrValue.value;
41
+ try {
42
+ return createFullDate(value, timezone);
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
@@ -0,0 +1,9 @@
1
+ import { DateTime } from 'luxon';
2
+ import { Timezone } from '../timezone/timezones.js';
3
+ /**
4
+ * Tries extra known formats for parsing date strings, even those that browsers do not natively
5
+ * support.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export declare function parseDateString(dateString: string, timezone: Timezone): DateTime | undefined;
@@ -11,6 +11,12 @@ const knownStringFormats = [
11
11
  // january-2021
12
12
  'LLLL-y',
13
13
  ];
14
+ /**
15
+ * Tries extra known formats for parsing date strings, even those that browsers do not natively
16
+ * support.
17
+ *
18
+ * @category Internal
19
+ */
14
20
  export function parseDateString(dateString, timezone) {
15
21
  const isoAttempt = DateTime.fromISO(dateString, { zone: timezone });
16
22
  if (isoAttempt.isValid) {
@@ -0,0 +1,29 @@
1
+ export * from './date-operations/calculate-relative-date.js';
2
+ export * from './date-operations/combine-dates.js';
3
+ export * from './date-operations/date-position.js';
4
+ export * from './date-operations/diff-dates.js';
5
+ export * from './extra-utils/end.js';
6
+ export * from './extra-utils/has-date-props.js';
7
+ export * from './extra-utils/js-date-conversion.js';
8
+ export * from './extra-utils/now.js';
9
+ export * from './extra-utils/override-date.js';
10
+ export * from './extra-utils/zero.js';
11
+ export * from './formatting/formatted-string.js';
12
+ export * from './formatting/html-input.js';
13
+ export * from './formatting/relative-string.js';
14
+ export * from './formatting/simple-strings.js';
15
+ export * from './formatting/string-format-types.js';
16
+ export * from './formatting/timestamp.js';
17
+ export * from './full-date/create-full-date.js';
18
+ export * from './full-date/date-like.js';
19
+ export * from './full-date/format-presets.js';
20
+ export * from './full-date/full-date-parts.js';
21
+ export * from './full-date/full-date-shape.js';
22
+ export * from './full-date/is-valid-full-date.js';
23
+ export * from './full-date/luxon-date-time-conversion.js';
24
+ export * from './full-date/parsing.js';
25
+ export * from './locales.js';
26
+ export * from './timezone/timezone-checks.js';
27
+ export * from './timezone/timezone-names.js';
28
+ export * from './timezone/timezones.js';
29
+ export * from '@date-vir/duration';
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ export * from './date-operations/calculate-relative-date.js';
2
+ export * from './date-operations/combine-dates.js';
3
+ export * from './date-operations/date-position.js';
4
+ export * from './date-operations/diff-dates.js';
5
+ export * from './extra-utils/end.js';
6
+ export * from './extra-utils/has-date-props.js';
7
+ export * from './extra-utils/js-date-conversion.js';
8
+ export * from './extra-utils/now.js';
9
+ export * from './extra-utils/override-date.js';
10
+ export * from './extra-utils/zero.js';
11
+ export * from './formatting/formatted-string.js';
12
+ export * from './formatting/html-input.js';
13
+ export * from './formatting/relative-string.js';
14
+ export * from './formatting/simple-strings.js';
15
+ export * from './formatting/string-format-types.js';
16
+ export * from './formatting/timestamp.js';
17
+ export * from './full-date/create-full-date.js';
18
+ export * from './full-date/date-like.js';
19
+ export * from './full-date/format-presets.js';
20
+ export * from './full-date/full-date-parts.js';
21
+ export * from './full-date/full-date-shape.js';
22
+ export * from './full-date/is-valid-full-date.js';
23
+ export * from './full-date/luxon-date-time-conversion.js';
24
+ export * from './full-date/parsing.js';
25
+ export * from './locales.js';
26
+ export * from './timezone/timezone-checks.js';
27
+ export * from './timezone/timezone-names.js';
28
+ export * from './timezone/timezones.js';
29
+ export * from '@date-vir/duration';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The current user's default locale, useful for formatting purposes.
3
+ *
4
+ * @category Formatting
5
+ */
6
+ export declare const userLocale: string;
@@ -0,0 +1,7 @@
1
+ import { Settings } from 'luxon';
2
+ /**
3
+ * The current user's default locale, useful for formatting purposes.
4
+ *
5
+ * @category Formatting
6
+ */
7
+ export const userLocale = Settings.defaultLocale;
@@ -0,0 +1,21 @@
1
+ import { Timezone } from './timezones.js';
2
+ /**
3
+ * Asserts that the given input is a valid timezone name.
4
+ *
5
+ * Note that this may actually allow names beyond what is currently in the exact {@link Timezone}
6
+ * type, because this function checks to see if the given timezone can be used to construct a date,
7
+ * regardless of whether it's in our typed list or not.
8
+ *
9
+ * @category Assertion
10
+ */
11
+ export declare function assertValidTimezone(potentialTimezone: string, userMessage?: string | undefined): asserts potentialTimezone is Timezone;
12
+ /**
13
+ * Checks that the given timezone is valid.
14
+ *
15
+ * Note that this may actually allow names beyond what is currently in the exact {@link Timezone}
16
+ * type, because this function checks to see if the given timezone can be used to construct a date,
17
+ * regardless of whether it's in our typed list or not.
18
+ *
19
+ * @category Assertion
20
+ */
21
+ export declare function isValidTimezone(potentialTimezone: string): potentialTimezone is Timezone;
@@ -0,0 +1,34 @@
1
+ import { AssertionError } from '@augment-vir/assert';
2
+ import { Info } from 'luxon';
3
+ /**
4
+ * Asserts that the given input is a valid timezone name.
5
+ *
6
+ * Note that this may actually allow names beyond what is currently in the exact {@link Timezone}
7
+ * type, because this function checks to see if the given timezone can be used to construct a date,
8
+ * regardless of whether it's in our typed list or not.
9
+ *
10
+ * @category Assertion
11
+ */
12
+ export function assertValidTimezone(potentialTimezone, userMessage) {
13
+ if (!Info.isValidIANAZone(potentialTimezone)) {
14
+ throw new AssertionError(`'${potentialTimezone}' is not a valid time zone`, userMessage);
15
+ }
16
+ }
17
+ /**
18
+ * Checks that the given timezone is valid.
19
+ *
20
+ * Note that this may actually allow names beyond what is currently in the exact {@link Timezone}
21
+ * type, because this function checks to see if the given timezone can be used to construct a date,
22
+ * regardless of whether it's in our typed list or not.
23
+ *
24
+ * @category Assertion
25
+ */
26
+ export function isValidTimezone(potentialTimezone) {
27
+ try {
28
+ assertValidTimezone(potentialTimezone);
29
+ return true;
30
+ }
31
+ catch {
32
+ return false;
33
+ }
34
+ }
@@ -1,9 +1,15 @@
1
- import { ArrayElement } from '@augment-vir/common';
2
1
  /**
3
- * This list was generated from Firefox 106.0.2 (which gave me the longest list out of all the
4
- * browsers I had immediately available to me at the time) with the following code:
2
+ * All valid timezone names.
5
3
  *
6
- * Intl.supportedValuesOf('timeZone').map(zone => `'${zone}'`).join(',')
4
+ * The list of timezone names was generated from Firefox 106.0.2 (which gave me the longest list out
5
+ * of all the browsers I had available to me) with the following code:
6
+ *
7
+ * ```ts
8
+ * Intl.supportedValuesOf('timeZone')
9
+ * .map((zone) => `'${zone}'`)
10
+ * .join(',');
11
+ * ```
12
+ *
13
+ * @category Timezone
7
14
  */
8
15
  export declare const allTimezoneNames: readonly ["Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", "Africa/Algiers", "Africa/Asmara", "Africa/Bamako", "Africa/Bangui", "Africa/Banjul", "Africa/Bissau", "Africa/Blantyre", "Africa/Brazzaville", "Africa/Bujumbura", "Africa/Cairo", "Africa/Casablanca", "Africa/Ceuta", "Africa/Conakry", "Africa/Dakar", "Africa/Dar_es_Salaam", "Africa/Djibouti", "Africa/Douala", "Africa/El_Aaiun", "Africa/Freetown", "Africa/Gaborone", "Africa/Harare", "Africa/Johannesburg", "Africa/Juba", "Africa/Kampala", "Africa/Khartoum", "Africa/Kigali", "Africa/Kinshasa", "Africa/Lagos", "Africa/Libreville", "Africa/Lome", "Africa/Luanda", "Africa/Lubumbashi", "Africa/Lusaka", "Africa/Malabo", "Africa/Maputo", "Africa/Maseru", "Africa/Mbabane", "Africa/Mogadishu", "Africa/Monrovia", "Africa/Nairobi", "Africa/Ndjamena", "Africa/Niamey", "Africa/Nouakchott", "Africa/Ouagadougou", "Africa/Porto-Novo", "Africa/Sao_Tome", "Africa/Timbuktu", "Africa/Tripoli", "Africa/Tunis", "Africa/Windhoek", "America/Adak", "America/Anchorage", "America/Anguilla", "America/Antigua", "America/Araguaina", "America/Argentina/Buenos_Aires", "America/Argentina/Catamarca", "America/Argentina/ComodRivadavia", "America/Argentina/Cordoba", "America/Argentina/Jujuy", "America/Argentina/La_Rioja", "America/Argentina/Mendoza", "America/Argentina/Rio_Gallegos", "America/Argentina/Salta", "America/Argentina/San_Juan", "America/Argentina/San_Luis", "America/Argentina/Tucuman", "America/Argentina/Ushuaia", "America/Aruba", "America/Asuncion", "America/Atikokan", "America/Bahia", "America/Bahia_Banderas", "America/Barbados", "America/Belem", "America/Belize", "America/Blanc-Sablon", "America/Boa_Vista", "America/Bogota", "America/Boise", "America/Cambridge_Bay", "America/Campo_Grande", "America/Cancun", "America/Caracas", "America/Cayenne", "America/Cayman", "America/Chicago", "America/Chihuahua", "America/Coral_Harbour", "America/Costa_Rica", "America/Creston", "America/Cuiaba", "America/Curacao", "America/Danmarkshavn", "America/Dawson", "America/Dawson_Creek", "America/Denver", "America/Detroit", "America/Dominica", "America/Edmonton", "America/Eirunepe", "America/El_Salvador", "America/Ensenada", "America/Fort_Nelson", "America/Fortaleza", "America/Glace_Bay", "America/Goose_Bay", "America/Grand_Turk", "America/Grenada", "America/Guadeloupe", "America/Guatemala", "America/Guayaquil", "America/Guyana", "America/Halifax", "America/Havana", "America/Hermosillo", "America/Indiana/Indianapolis", "America/Indiana/Knox", "America/Indiana/Marengo", "America/Indiana/Petersburg", "America/Indiana/Tell_City", "America/Indiana/Vevay", "America/Indiana/Vincennes", "America/Indiana/Winamac", "America/Inuvik", "America/Iqaluit", "America/Jamaica", "America/Juneau", "America/Kentucky/Louisville", "America/Kentucky/Monticello", "America/La_Paz", "America/Lima", "America/Los_Angeles", "America/Maceio", "America/Managua", "America/Manaus", "America/Martinique", "America/Matamoros", "America/Mazatlan", "America/Menominee", "America/Merida", "America/Metlakatla", "America/Mexico_City", "America/Miquelon", "America/Moncton", "America/Monterrey", "America/Montevideo", "America/Montreal", "America/Montserrat", "America/Nassau", "America/New_York", "America/Nipigon", "America/Nome", "America/Noronha", "America/North_Dakota/Beulah", "America/North_Dakota/Center", "America/North_Dakota/New_Salem", "America/Nuuk", "America/Ojinaga", "America/Panama", "America/Pangnirtung", "America/Paramaribo", "America/Phoenix", "America/Port-au-Prince", "America/Port_of_Spain", "America/Porto_Velho", "America/Puerto_Rico", "America/Punta_Arenas", "America/Rainy_River", "America/Rankin_Inlet", "America/Recife", "America/Regina", "America/Resolute", "America/Rio_Branco", "America/Rosario", "America/Santarem", "America/Santiago", "America/Santo_Domingo", "America/Sao_Paulo", "America/Scoresbysund", "America/Sitka", "America/St_Johns", "America/St_Kitts", "America/St_Lucia", "America/St_Thomas", "America/St_Vincent", "America/Swift_Current", "America/Tegucigalpa", "America/Thule", "America/Thunder_Bay", "America/Tijuana", "America/Toronto", "America/Tortola", "America/Vancouver", "America/Whitehorse", "America/Winnipeg", "America/Yakutat", "America/Yellowknife", "Antarctica/Casey", "Antarctica/Davis", "Antarctica/DumontDUrville", "Antarctica/Macquarie", "Antarctica/Mawson", "Antarctica/McMurdo", "Antarctica/Palmer", "Antarctica/Rothera", "Antarctica/Syowa", "Antarctica/Troll", "Antarctica/Vostok", "Asia/Aden", "Asia/Almaty", "Asia/Amman", "Asia/Anadyr", "Asia/Aqtau", "Asia/Aqtobe", "Asia/Ashgabat", "Asia/Atyrau", "Asia/Baghdad", "Asia/Bahrain", "Asia/Baku", "Asia/Bangkok", "Asia/Barnaul", "Asia/Beirut", "Asia/Bishkek", "Asia/Brunei", "Asia/Chita", "Asia/Choibalsan", "Asia/Chongqing", "Asia/Colombo", "Asia/Damascus", "Asia/Dhaka", "Asia/Dili", "Asia/Dubai", "Asia/Dushanbe", "Asia/Famagusta", "Asia/Gaza", "Asia/Harbin", "Asia/Hebron", "Asia/Ho_Chi_Minh", "Asia/Hong_Kong", "Asia/Hovd", "Asia/Irkutsk", "Asia/Jakarta", "Asia/Jayapura", "Asia/Jerusalem", "Asia/Kabul", "Asia/Kamchatka", "Asia/Karachi", "Asia/Kashgar", "Asia/Kathmandu", "Asia/Khandyga", "Asia/Kolkata", "Asia/Krasnoyarsk", "Asia/Kuala_Lumpur", "Asia/Kuching", "Asia/Kuwait", "Asia/Macau", "Asia/Magadan", "Asia/Makassar", "Asia/Manila", "Asia/Muscat", "Asia/Nicosia", "Asia/Novokuznetsk", "Asia/Novosibirsk", "Asia/Omsk", "Asia/Oral", "Asia/Phnom_Penh", "Asia/Pontianak", "Asia/Pyongyang", "Asia/Qatar", "Asia/Qostanay", "Asia/Qyzylorda", "Asia/Riyadh", "Asia/Sakhalin", "Asia/Samarkand", "Asia/Seoul", "Asia/Shanghai", "Asia/Singapore", "Asia/Srednekolymsk", "Asia/Taipei", "Asia/Tashkent", "Asia/Tbilisi", "Asia/Tehran", "Asia/Tel_Aviv", "Asia/Thimphu", "Asia/Tokyo", "Asia/Tomsk", "Asia/Ulaanbaatar", "Asia/Urumqi", "Asia/Ust-Nera", "Asia/Vientiane", "Asia/Vladivostok", "Asia/Yakutsk", "Asia/Yangon", "Asia/Yekaterinburg", "Asia/Yerevan", "Atlantic/Azores", "Atlantic/Bermuda", "Atlantic/Canary", "Atlantic/Cape_Verde", "Atlantic/Faroe", "Atlantic/Jan_Mayen", "Atlantic/Madeira", "Atlantic/Reykjavik", "Atlantic/South_Georgia", "Atlantic/St_Helena", "Atlantic/Stanley", "Australia/Adelaide", "Australia/Brisbane", "Australia/Broken_Hill", "Australia/Currie", "Australia/Darwin", "Australia/Eucla", "Australia/Hobart", "Australia/Lindeman", "Australia/Lord_Howe", "Australia/Melbourne", "Australia/Perth", "Australia/Sydney", "CET", "CST6CDT", "EET", "EST", "EST5EDT", "Etc/GMT+1", "Etc/GMT+10", "Etc/GMT+11", "Etc/GMT+12", "Etc/GMT+2", "Etc/GMT+3", "Etc/GMT+4", "Etc/GMT+5", "Etc/GMT+6", "Etc/GMT+7", "Etc/GMT+8", "Etc/GMT+9", "Etc/GMT-1", "Etc/GMT-10", "Etc/GMT-11", "Etc/GMT-12", "Etc/GMT-13", "Etc/GMT-14", "Etc/GMT-2", "Etc/GMT-3", "Etc/GMT-4", "Etc/GMT-5", "Etc/GMT-6", "Etc/GMT-7", "Etc/GMT-8", "Etc/GMT-9", "Europe/Amsterdam", "Europe/Andorra", "Europe/Astrakhan", "Europe/Athens", "Europe/Belfast", "Europe/Belgrade", "Europe/Berlin", "Europe/Brussels", "Europe/Bucharest", "Europe/Budapest", "Europe/Chisinau", "Europe/Copenhagen", "Europe/Dublin", "Europe/Gibraltar", "Europe/Guernsey", "Europe/Helsinki", "Europe/Isle_of_Man", "Europe/Istanbul", "Europe/Jersey", "Europe/Kaliningrad", "Europe/Kirov", "Europe/Kyiv", "Europe/Lisbon", "Europe/Ljubljana", "Europe/London", "Europe/Luxembourg", "Europe/Madrid", "Europe/Malta", "Europe/Minsk", "Europe/Monaco", "Europe/Moscow", "Europe/Oslo", "Europe/Paris", "Europe/Prague", "Europe/Riga", "Europe/Rome", "Europe/Samara", "Europe/Sarajevo", "Europe/Saratov", "Europe/Simferopol", "Europe/Skopje", "Europe/Sofia", "Europe/Stockholm", "Europe/Tallinn", "Europe/Tirane", "Europe/Tiraspol", "Europe/Ulyanovsk", "Europe/Uzhgorod", "Europe/Vaduz", "Europe/Vienna", "Europe/Vilnius", "Europe/Volgograd", "Europe/Warsaw", "Europe/Zagreb", "Europe/Zaporozhye", "Europe/Zurich", "Factory", "HST", "Indian/Antananarivo", "Indian/Chagos", "Indian/Christmas", "Indian/Cocos", "Indian/Comoro", "Indian/Kerguelen", "Indian/Mahe", "Indian/Maldives", "Indian/Mauritius", "Indian/Mayotte", "Indian/Reunion", "MET", "MST", "MST7MDT", "PST8PDT", "Pacific/Apia", "Pacific/Auckland", "Pacific/Bougainville", "Pacific/Chatham", "Pacific/Chuuk", "Pacific/Easter", "Pacific/Efate", "Pacific/Enderbury", "Pacific/Fakaofo", "Pacific/Fiji", "Pacific/Funafuti", "Pacific/Galapagos", "Pacific/Gambier", "Pacific/Guadalcanal", "Pacific/Guam", "Pacific/Honolulu", "Pacific/Johnston", "Pacific/Kanton", "Pacific/Kiritimati", "Pacific/Kosrae", "Pacific/Kwajalein", "Pacific/Majuro", "Pacific/Marquesas", "Pacific/Midway", "Pacific/Nauru", "Pacific/Niue", "Pacific/Norfolk", "Pacific/Noumea", "Pacific/Pago_Pago", "Pacific/Palau", "Pacific/Pitcairn", "Pacific/Pohnpei", "Pacific/Port_Moresby", "Pacific/Rarotonga", "Pacific/Saipan", "Pacific/Tahiti", "Pacific/Tarawa", "Pacific/Tongatapu", "Pacific/Wake", "Pacific/Wallis", "UTC", "WET"];
9
- export type Timezone = ArrayElement<typeof allTimezoneNames>;
@@ -1,8 +1,16 @@
1
1
  /**
2
- * This list was generated from Firefox 106.0.2 (which gave me the longest list out of all the
3
- * browsers I had immediately available to me at the time) with the following code:
2
+ * All valid timezone names.
4
3
  *
5
- * Intl.supportedValuesOf('timeZone').map(zone => `'${zone}'`).join(',')
4
+ * The list of timezone names was generated from Firefox 106.0.2 (which gave me the longest list out
5
+ * of all the browsers I had available to me) with the following code:
6
+ *
7
+ * ```ts
8
+ * Intl.supportedValuesOf('timeZone')
9
+ * .map((zone) => `'${zone}'`)
10
+ * .join(',');
11
+ * ```
12
+ *
13
+ * @category Timezone
6
14
  */
7
15
  export const allTimezoneNames = [
8
16
  'Africa/Abidjan',
@@ -0,0 +1,42 @@
1
+ import type { ArrayElement } from '@augment-vir/common';
2
+ import { allTimezoneNames } from './timezone-names.js';
3
+ /**
4
+ * All possible timezone names.
5
+ *
6
+ * @category Timezone
7
+ * @see {@link allTimezoneNames}
8
+ */
9
+ export type Timezone = ArrayElement<typeof allTimezoneNames>;
10
+ /**
11
+ * An enum of all possible timezone names.
12
+ *
13
+ * @category Timezone
14
+ * @example
15
+ *
16
+ * ```ts
17
+ * import {Timezone} from 'date-vir';
18
+ *
19
+ * Timezone['Africa/Bamako'];
20
+ * ```
21
+ */
22
+ export declare const Timezone: Readonly<{
23
+ [SpecificTimezoneName in Timezone]: SpecificTimezoneName;
24
+ }>;
25
+ /**
26
+ * The timezone of the current user's environment.
27
+ *
28
+ * @category Timezone
29
+ */
30
+ export declare const userTimezone: Timezone;
31
+ /**
32
+ * The UTC timezone.
33
+ *
34
+ * @category Timezone
35
+ */
36
+ export declare const utcTimezone: "UTC";
37
+ /**
38
+ * The UTC timezone as a type.
39
+ *
40
+ * @category Timezone
41
+ */
42
+ export type UtcTimezone = typeof utcTimezone;