date-vir 5.3.1 → 6.0.1

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 (141) 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/diff-dates.d.ts +95 -0
  8. package/dist/date-operations/diff-dates.js +124 -0
  9. package/dist/extra-utils/has-date-props.d.ts +35 -0
  10. package/dist/extra-utils/has-date-props.js +46 -0
  11. package/dist/extra-utils/js-date-conversion.d.ts +26 -0
  12. package/dist/extra-utils/js-date-conversion.js +28 -0
  13. package/dist/extra-utils/now.d.ts +56 -0
  14. package/dist/extra-utils/now.js +68 -0
  15. package/dist/extra-utils/override-date.d.ts +27 -0
  16. package/dist/extra-utils/override-date.js +27 -0
  17. package/dist/extra-utils/zero.d.ts +99 -0
  18. package/dist/extra-utils/zero.js +94 -0
  19. package/dist/formatting/formatted-string.d.ts +58 -0
  20. package/dist/formatting/formatted-string.js +73 -0
  21. package/dist/formatting/html-input.d.ts +30 -0
  22. package/dist/formatting/html-input.js +47 -0
  23. package/dist/formatting/relative-string.d.ts +53 -0
  24. package/dist/formatting/relative-string.js +93 -0
  25. package/dist/formatting/simple-strings.d.ts +187 -0
  26. package/dist/formatting/simple-strings.js +120 -0
  27. package/dist/formatting/string-format-types.d.ts +59 -0
  28. package/dist/formatting/string-format-types.js +19 -0
  29. package/dist/formatting/timestamp.d.ts +51 -0
  30. package/dist/formatting/timestamp.js +61 -0
  31. package/dist/full-date/create-full-date.d.ts +91 -0
  32. package/dist/full-date/create-full-date.js +142 -0
  33. package/dist/full-date/date-like.d.ts +9 -0
  34. package/dist/{esm/full-date → full-date}/format-presets.d.ts +4 -2
  35. package/dist/{esm/full-date → full-date}/format-presets.js +4 -2
  36. package/dist/full-date/full-date-parts.d.ts +48 -0
  37. package/dist/full-date/full-date-parts.js +45 -0
  38. package/dist/full-date/full-date-shape.d.ts +106 -0
  39. package/dist/{esm/full-date → full-date}/full-date-shape.js +15 -22
  40. package/dist/full-date/is-valid-full-date.d.ts +21 -0
  41. package/dist/full-date/is-valid-full-date.js +38 -0
  42. package/dist/full-date/luxon-date-time-conversion.d.ts +19 -0
  43. package/dist/{esm/full-date → full-date}/luxon-date-time-conversion.js +10 -6
  44. package/dist/full-date/parsing.d.ts +33 -0
  45. package/dist/full-date/parsing.js +47 -0
  46. package/dist/full-date/string-parsing.d.ts +9 -0
  47. package/dist/{esm/full-date → full-date}/string-parsing.js +6 -0
  48. package/dist/index.d.ts +27 -0
  49. package/dist/index.js +27 -0
  50. package/dist/locales.d.ts +6 -0
  51. package/dist/locales.js +7 -0
  52. package/dist/timezone/timezone-checks.d.ts +21 -0
  53. package/dist/timezone/timezone-checks.js +34 -0
  54. package/dist/{esm/timezone → timezone}/timezone-names.d.ts +11 -5
  55. package/dist/{esm/timezone → timezone}/timezone-names.js +11 -3
  56. package/dist/timezone/timezones.d.ts +42 -0
  57. package/dist/timezone/timezones.js +31 -0
  58. package/package.json +30 -48
  59. package/cspell.config.cjs +0 -13
  60. package/dist/cjs/date-operations/calculate-relative-date.js +0 -12
  61. package/dist/cjs/date-operations/combine-dates.js +0 -50
  62. package/dist/cjs/date-operations/diff-dates.js +0 -105
  63. package/dist/cjs/duration/duration-unit.js +0 -41
  64. package/dist/cjs/duration/duration-utils.js +0 -42
  65. package/dist/cjs/duration/duration.js +0 -2
  66. package/dist/cjs/extra-utils/date-transforms.js +0 -8
  67. package/dist/cjs/extra-utils/has-date-props.js +0 -25
  68. package/dist/cjs/extra-utils/js-date-conversion.js +0 -8
  69. package/dist/cjs/extra-utils/now.js +0 -22
  70. package/dist/cjs/extra-utils/zero.js +0 -31
  71. package/dist/cjs/formatting/formatted-string.js +0 -34
  72. package/dist/cjs/formatting/html-input.js +0 -37
  73. package/dist/cjs/formatting/relative-string.js +0 -77
  74. package/dist/cjs/formatting/simple-strings.js +0 -58
  75. package/dist/cjs/formatting/string-format-types.js +0 -9
  76. package/dist/cjs/formatting/timestamp.js +0 -21
  77. package/dist/cjs/full-date/create-full-date.js +0 -81
  78. package/dist/cjs/full-date/date-like.js +0 -2
  79. package/dist/cjs/full-date/format-presets.js +0 -32
  80. package/dist/cjs/full-date/full-date-shape.js +0 -54
  81. package/dist/cjs/full-date/is-valid-full-date.js +0 -28
  82. package/dist/cjs/full-date/luxon-date-time-conversion.js +0 -43
  83. package/dist/cjs/full-date/parsing.js +0 -48
  84. package/dist/cjs/full-date/string-parsing.js +0 -33
  85. package/dist/cjs/index.js +0 -44
  86. package/dist/cjs/locales.js +0 -5
  87. package/dist/cjs/timezone/timezone-checks.js +0 -34
  88. package/dist/cjs/timezone/timezone-names.js +0 -479
  89. package/dist/cjs/timezone/timezones.js +0 -14
  90. package/dist/esm/date-operations/calculate-relative-date.d.ts +0 -8
  91. package/dist/esm/date-operations/combine-dates.d.ts +0 -35
  92. package/dist/esm/date-operations/diff-dates.d.ts +0 -66
  93. package/dist/esm/date-operations/diff-dates.js +0 -100
  94. package/dist/esm/duration/duration-unit.d.ts +0 -27
  95. package/dist/esm/duration/duration-unit.js +0 -38
  96. package/dist/esm/duration/duration-utils.d.ts +0 -11
  97. package/dist/esm/duration/duration-utils.js +0 -37
  98. package/dist/esm/duration/duration.d.ts +0 -32
  99. package/dist/esm/duration/duration.js +0 -1
  100. package/dist/esm/extra-utils/date-transforms.d.ts +0 -4
  101. package/dist/esm/extra-utils/date-transforms.js +0 -4
  102. package/dist/esm/extra-utils/has-date-props.d.ts +0 -9
  103. package/dist/esm/extra-utils/has-date-props.js +0 -20
  104. package/dist/esm/extra-utils/js-date-conversion.d.ts +0 -2
  105. package/dist/esm/extra-utils/js-date-conversion.js +0 -4
  106. package/dist/esm/extra-utils/now.d.ts +0 -5
  107. package/dist/esm/extra-utils/now.js +0 -16
  108. package/dist/esm/extra-utils/zero.d.ts +0 -31
  109. package/dist/esm/extra-utils/zero.js +0 -26
  110. package/dist/esm/formatting/formatted-string.d.ts +0 -14
  111. package/dist/esm/formatting/formatted-string.js +0 -29
  112. package/dist/esm/formatting/html-input.d.ts +0 -19
  113. package/dist/esm/formatting/html-input.js +0 -33
  114. package/dist/esm/formatting/relative-string.d.ts +0 -31
  115. package/dist/esm/formatting/relative-string.js +0 -73
  116. package/dist/esm/formatting/simple-strings.d.ts +0 -71
  117. package/dist/esm/formatting/simple-strings.js +0 -51
  118. package/dist/esm/formatting/string-format-types.d.ts +0 -7
  119. package/dist/esm/formatting/string-format-types.js +0 -5
  120. package/dist/esm/formatting/timestamp.d.ts +0 -6
  121. package/dist/esm/formatting/timestamp.js +0 -16
  122. package/dist/esm/full-date/create-full-date.d.ts +0 -21
  123. package/dist/esm/full-date/create-full-date.js +0 -73
  124. package/dist/esm/full-date/date-like.d.ts +0 -5
  125. package/dist/esm/full-date/full-date-shape.d.ts +0 -80
  126. package/dist/esm/full-date/is-valid-full-date.d.ts +0 -5
  127. package/dist/esm/full-date/is-valid-full-date.js +0 -22
  128. package/dist/esm/full-date/luxon-date-time-conversion.d.ts +0 -15
  129. package/dist/esm/full-date/parsing.d.ts +0 -27
  130. package/dist/esm/full-date/parsing.js +0 -43
  131. package/dist/esm/full-date/string-parsing.d.ts +0 -3
  132. package/dist/esm/index.d.ts +0 -28
  133. package/dist/esm/index.js +0 -28
  134. package/dist/esm/locales.d.ts +0 -1
  135. package/dist/esm/locales.js +0 -2
  136. package/dist/esm/timezone/timezone-checks.d.ts +0 -17
  137. package/dist/esm/timezone/timezone-checks.js +0 -29
  138. package/dist/esm/timezone/timezones.d.ts +0 -480
  139. package/dist/esm/timezone/timezones.js +0 -11
  140. package/public/index.css +0 -7
  141. /package/dist/{esm/full-date → full-date}/date-like.js +0 -0
@@ -0,0 +1,187 @@
1
+ import type { SetOptionalAndNullable } from '@augment-vir/common';
2
+ import { FullDate } from '../full-date/full-date-shape.js';
3
+ import { JustDateString, JustTimeString, JustTimeWithSecondsString } from './string-format-types.js';
4
+ /**
5
+ * Create a string based on just the date parts of a FullDate.
6
+ *
7
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
8
+ *
9
+ * Example output: `'2023-12-05'`
10
+ *
11
+ * @category Internal
12
+ */
13
+ export declare function toSimpleDatePartString(fullDate: Pick<FullDate, 'year' | 'month' | 'day'>): JustDateString;
14
+ /**
15
+ * Creates a string based on just the time parts of a FullDate.
16
+ *
17
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
18
+ *
19
+ * Example output: `'05:32:21'`
20
+ *
21
+ * @category Internal
22
+ */
23
+ export declare function toSimpleTimePartString(fullDate: Pick<FullDate, 'hour' | 'minute' | 'second'> | Pick<FullDate, 'hour' | 'minute'>, includeSeconds: boolean): JustTimeWithSecondsString | JustTimeString;
24
+ /**
25
+ * The parts of {@link FullDate} required for {@link toDatePartStrings}.
26
+ *
27
+ * @category Internal
28
+ */
29
+ export type FullDateForParts = SetOptionalAndNullable<FullDate, 'millisecond'>;
30
+ /**
31
+ * Splits a FullDate up into multiple formatted string representations.
32
+ *
33
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
34
+ *
35
+ * This uses numbers for everything.
36
+ *
37
+ * @category Formatting
38
+ * @example
39
+ *
40
+ * ```ts
41
+ * import {toDatePartStrings, utcTimezone} from 'date-vir';
42
+ *
43
+ * let result = toDatePartStrings(
44
+ * {
45
+ * year: 2024,
46
+ * month: 4,
47
+ * day: 24,
48
+ * hour: 6,
49
+ * minute: 4,
50
+ * second: 9,
51
+ * millisecond: 123,
52
+ * timezone: utcTimezone,
53
+ * },
54
+ * {includeSeconds: true},
55
+ * );
56
+ * // outputs:
57
+ * result = {
58
+ * date: '2024-04-24',
59
+ * time: '06:04:09',
60
+ * timezone: 'UTC',
61
+ * };
62
+ * ```
63
+ */
64
+ export declare function toDatePartStrings(fullDate: FullDateForParts, options: {
65
+ includeSeconds: true;
66
+ }): {
67
+ date: JustDateString;
68
+ time: JustTimeWithSecondsString;
69
+ timezone: string;
70
+ };
71
+ /**
72
+ * Splits a FullDate up into multiple formatted string representations.
73
+ *
74
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
75
+ *
76
+ * This uses numbers for everything.
77
+ *
78
+ * @category Formatting
79
+ * @example
80
+ *
81
+ * ```ts
82
+ * import {toDatePartStrings, utcTimezone} from 'date-vir';
83
+ *
84
+ * let result = toDatePartStrings(
85
+ * {
86
+ * year: 2024,
87
+ * month: 4,
88
+ * day: 24,
89
+ * hour: 6,
90
+ * minute: 4,
91
+ * second: 9,
92
+ * millisecond: 123,
93
+ * timezone: utcTimezone,
94
+ * },
95
+ * {includeSeconds: true},
96
+ * );
97
+ * // outputs:
98
+ * result = {
99
+ * date: '2024-04-24',
100
+ * time: '06:04:09',
101
+ * timezone: 'UTC',
102
+ * };
103
+ * ```
104
+ */
105
+ export declare function toDatePartStrings(fullDate: SetOptionalAndNullable<FullDateForParts, 'second'>, options: {
106
+ includeSeconds: false;
107
+ }): {
108
+ date: JustDateString;
109
+ time: JustTimeString;
110
+ timezone: string;
111
+ };
112
+ /**
113
+ * Splits a FullDate up into multiple formatted string representations.
114
+ *
115
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
116
+ *
117
+ * This uses numbers for everything.
118
+ *
119
+ * @category Formatting
120
+ * @example
121
+ *
122
+ * ```ts
123
+ * import {toDatePartStrings, utcTimezone} from 'date-vir';
124
+ *
125
+ * let result = toDatePartStrings(
126
+ * {
127
+ * year: 2024,
128
+ * month: 4,
129
+ * day: 24,
130
+ * hour: 6,
131
+ * minute: 4,
132
+ * second: 9,
133
+ * millisecond: 123,
134
+ * timezone: utcTimezone,
135
+ * },
136
+ * {includeSeconds: true},
137
+ * );
138
+ * // outputs:
139
+ * result = {
140
+ * date: '2024-04-24',
141
+ * time: '06:04:09',
142
+ * timezone: 'UTC',
143
+ * };
144
+ * ```
145
+ */
146
+ export declare function toDatePartStrings(fullDate: FullDateForParts, options: {
147
+ includeSeconds: boolean;
148
+ }): {
149
+ date: JustDateString;
150
+ time: JustTimeWithSecondsString | JustTimeString;
151
+ timezone: string;
152
+ };
153
+ /**
154
+ * Converts a date into a simple, unambiguous date string.
155
+ *
156
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
157
+ *
158
+ * @category Formatting
159
+ * @example
160
+ *
161
+ * ```ts
162
+ * import {toSimpleString} from 'date-vir';
163
+ *
164
+ * let result = toSimpleString(
165
+ * {
166
+ * year: 2024,
167
+ * month: 4,
168
+ * day: 24,
169
+ * hour: 6,
170
+ * minute: 4,
171
+ * second: 9,
172
+ * millisecond: 123,
173
+ * timezone: utcTimezone,
174
+ * },
175
+ * {
176
+ * includeSeconds: false,
177
+ * includeTimezone: false,
178
+ * },
179
+ * );
180
+ * // outputs:
181
+ * result = '2024-04-24 06:04';
182
+ * ```
183
+ */
184
+ export declare function toSimpleString(fullDate: FullDateForParts, options: {
185
+ includeSeconds: boolean;
186
+ includeTimezone: boolean;
187
+ }): string;
@@ -0,0 +1,120 @@
1
+ import { check } from '@augment-vir/assert';
2
+ /**
3
+ * Create a string based on just the date parts of a FullDate.
4
+ *
5
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
6
+ *
7
+ * Example output: `'2023-12-05'`
8
+ *
9
+ * @category Internal
10
+ */
11
+ export function toSimpleDatePartString(fullDate) {
12
+ const dateParts = [
13
+ String(Math.abs(fullDate.year)).padStart(4, '0'),
14
+ String(Math.abs(fullDate.month)).padStart(2, '0'),
15
+ String(Math.abs(fullDate.day)).padStart(2, '0'),
16
+ ];
17
+ const dateString = dateParts.join('-');
18
+ return dateString;
19
+ }
20
+ /**
21
+ * Creates a string based on just the time parts of a FullDate.
22
+ *
23
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
24
+ *
25
+ * Example output: `'05:32:21'`
26
+ *
27
+ * @category Internal
28
+ */
29
+ export function toSimpleTimePartString(fullDate, includeSeconds) {
30
+ const seconds = check.hasKey(fullDate, 'second') && includeSeconds
31
+ ? String(Math.abs(fullDate.second)).padStart(2, '0')
32
+ : undefined;
33
+ const timeParts = [
34
+ String(Math.abs(fullDate.hour)).padStart(2, '0'),
35
+ String(Math.abs(fullDate.minute)).padStart(2, '0'),
36
+ seconds,
37
+ ].filter(check.isTruthy);
38
+ return timeParts.join(':');
39
+ }
40
+ /**
41
+ * Splits a FullDate up into multiple formatted string representations.
42
+ *
43
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
44
+ *
45
+ * This uses numbers for everything.
46
+ *
47
+ * @category Formatting
48
+ * @example
49
+ *
50
+ * ```ts
51
+ * import {toDatePartStrings, utcTimezone} from 'date-vir';
52
+ *
53
+ * let result = toDatePartStrings(
54
+ * {
55
+ * year: 2024,
56
+ * month: 4,
57
+ * day: 24,
58
+ * hour: 6,
59
+ * minute: 4,
60
+ * second: 9,
61
+ * millisecond: 123,
62
+ * timezone: utcTimezone,
63
+ * },
64
+ * {includeSeconds: true},
65
+ * );
66
+ * // outputs:
67
+ * result = {
68
+ * date: '2024-04-24',
69
+ * time: '06:04:09',
70
+ * timezone: 'UTC',
71
+ * };
72
+ * ```
73
+ */
74
+ export function toDatePartStrings(fullDate, options) {
75
+ return {
76
+ date: toSimpleDatePartString(fullDate),
77
+ time: toSimpleTimePartString(fullDate, options.includeSeconds),
78
+ timezone: fullDate.timezone,
79
+ };
80
+ }
81
+ /**
82
+ * Converts a date into a simple, unambiguous date string.
83
+ *
84
+ * **CAUTION**: this does not user locale setting. Prefer {@link toLocaleString} whenever possible.
85
+ *
86
+ * @category Formatting
87
+ * @example
88
+ *
89
+ * ```ts
90
+ * import {toSimpleString} from 'date-vir';
91
+ *
92
+ * let result = toSimpleString(
93
+ * {
94
+ * year: 2024,
95
+ * month: 4,
96
+ * day: 24,
97
+ * hour: 6,
98
+ * minute: 4,
99
+ * second: 9,
100
+ * millisecond: 123,
101
+ * timezone: utcTimezone,
102
+ * },
103
+ * {
104
+ * includeSeconds: false,
105
+ * includeTimezone: false,
106
+ * },
107
+ * );
108
+ * // outputs:
109
+ * result = '2024-04-24 06:04';
110
+ * ```
111
+ */
112
+ export function toSimpleString(fullDate, options) {
113
+ const parts = toDatePartStrings(fullDate, options);
114
+ const stringParts = [
115
+ parts.date,
116
+ parts.time,
117
+ options.includeTimezone && `(${parts.timezone})`,
118
+ ].filter(check.isTruthy);
119
+ return stringParts.join(' ');
120
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * A string that represents only date parts of a date. It's intended to be used like this:
3
+ * year-month-day.
4
+ *
5
+ * @category Internal
6
+ */
7
+ export type JustDateString = `${number}-${number}-${number}`;
8
+ /**
9
+ * A string that represents only time parts of a date, with seconds. It's intended to be used like
10
+ * this: hour:minute:seconds.
11
+ *
12
+ * @category Internal
13
+ */
14
+ export type JustTimeWithSecondsString = `${number}:${number}:${number}`;
15
+ /**
16
+ * A string that represents only time parts of a date, without seconds. It's intended to be used
17
+ * like this: hour:minute.
18
+ *
19
+ * @category Internal
20
+ */
21
+ export type JustTimeString = `${number}:${number}`;
22
+ /**
23
+ * A string that represents date and time parts of a date, with seconds. It's intended to be used
24
+ * like this: year-month-dayThour:minute:seconds.
25
+ *
26
+ * @category Internal
27
+ */
28
+ export type DateTimeWithSeconds = `${JustDateString}T${JustTimeWithSecondsString}`;
29
+ /**
30
+ * A string that represents date and time parts of a date, without seconds. It's intended to be used
31
+ * like this: year-month-dayThour:minute.
32
+ *
33
+ * @category Internal
34
+ */
35
+ export type DateTimeString = `${JustDateString}T${JustTimeString}`;
36
+ /**
37
+ * A full UTC ISO date time string: YYYY-MM-DDTHH:mm:ss.sssZ.
38
+ *
39
+ * @category ISO
40
+ * @see
41
+ * - https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-time-string-format
42
+ * - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format
43
+ */
44
+ export type UtcIsoString = `${JustDateString}T${JustTimeWithSecondsString}.${number}Z`;
45
+ /**
46
+ * Checks if the input is a valid UTC ISO string and type guards the input.
47
+ *
48
+ * @category ISO
49
+ * @category Assertion
50
+ * @example
51
+ *
52
+ * ```ts
53
+ * import {isValidIsoString} from 'date-vir';
54
+ *
55
+ * isValidIsoString('no'); // `false`
56
+ * isValidIsoString('2024-05-01T20:18:17.123Z'); // `true`
57
+ * ```
58
+ */
59
+ export declare function isValidIsoString(input: unknown): input is UtcIsoString;
@@ -0,0 +1,19 @@
1
+ import { DateTime } from 'luxon';
2
+ /**
3
+ * Checks if the input is a valid UTC ISO string and type guards the input.
4
+ *
5
+ * @category ISO
6
+ * @category Assertion
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {isValidIsoString} from 'date-vir';
11
+ *
12
+ * isValidIsoString('no'); // `false`
13
+ * isValidIsoString('2024-05-01T20:18:17.123Z'); // `true`
14
+ * ```
15
+ */
16
+ export function isValidIsoString(input) {
17
+ const datetime = DateTime.fromISO(input);
18
+ return datetime.toUTC().toISO() === input;
19
+ }
@@ -0,0 +1,51 @@
1
+ import { FullDate } from '../full-date/full-date-shape.js';
2
+ import { UtcIsoString } from './string-format-types.js';
3
+ /**
4
+ * Convert a FullDate into a unix timestamp with milliseconds.
5
+ *
6
+ * @category Formatting
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {toTimestamp} from 'date-vir';
11
+ *
12
+ * const exampleDate: FullDate = {
13
+ * year: 2024,
14
+ * month: 1,
15
+ * day: 5,
16
+ * hour: 1,
17
+ * minute: 1,
18
+ * second: 1,
19
+ * millisecond: 1,
20
+ * timezone: 'UTC',
21
+ * };
22
+ *
23
+ * toTimestamp(exampleDate); // `1704416461001`
24
+ * ```
25
+ */
26
+ export declare function toTimestamp(fullDate: FullDate): number;
27
+ /**
28
+ * Convert a FullDate into a UTC ISO string, always ending in Z.
29
+ *
30
+ * @category ISO
31
+ * @category Formatting
32
+ * @example
33
+ *
34
+ * ```ts
35
+ * import {toUtcIsoString} from 'date-vir';
36
+ *
37
+ * const exampleDate: FullDate = {
38
+ * year: 2024,
39
+ * month: 1,
40
+ * day: 5,
41
+ * hour: 1,
42
+ * minute: 1,
43
+ * second: 1,
44
+ * millisecond: 1,
45
+ * timezone: 'UTC',
46
+ * };
47
+ *
48
+ * toUtcIsoString(exampleDate); // `'2024-01-05T01:01:01.001Z'`
49
+ * ```
50
+ */
51
+ export declare function toUtcIsoString(fullDate: FullDate): UtcIsoString;
@@ -0,0 +1,61 @@
1
+ import { toLuxonDateTime } from '../full-date/luxon-date-time-conversion.js';
2
+ import { utcTimezone } from '../timezone/timezones.js';
3
+ /**
4
+ * Convert a FullDate into a unix timestamp with milliseconds.
5
+ *
6
+ * @category Formatting
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {toTimestamp} from 'date-vir';
11
+ *
12
+ * const exampleDate: FullDate = {
13
+ * year: 2024,
14
+ * month: 1,
15
+ * day: 5,
16
+ * hour: 1,
17
+ * minute: 1,
18
+ * second: 1,
19
+ * millisecond: 1,
20
+ * timezone: 'UTC',
21
+ * };
22
+ *
23
+ * toTimestamp(exampleDate); // `1704416461001`
24
+ * ```
25
+ */
26
+ export function toTimestamp(fullDate) {
27
+ return toLuxonDateTime(fullDate).toMillis();
28
+ }
29
+ /**
30
+ * Convert a FullDate into a UTC ISO string, always ending in Z.
31
+ *
32
+ * @category ISO
33
+ * @category Formatting
34
+ * @example
35
+ *
36
+ * ```ts
37
+ * import {toUtcIsoString} from 'date-vir';
38
+ *
39
+ * const exampleDate: FullDate = {
40
+ * year: 2024,
41
+ * month: 1,
42
+ * day: 5,
43
+ * hour: 1,
44
+ * minute: 1,
45
+ * second: 1,
46
+ * millisecond: 1,
47
+ * timezone: 'UTC',
48
+ * };
49
+ *
50
+ * toUtcIsoString(exampleDate); // `'2024-01-05T01:01:01.001Z'`
51
+ * ```
52
+ */
53
+ export function toUtcIsoString(fullDate) {
54
+ const isoString = toLuxonDateTime(fullDate).setZone(utcTimezone).toISO();
55
+ /** Ignore this edge case in the types and idk how to trigger it. */
56
+ /* c8 ignore next 3 */
57
+ if (!isoString) {
58
+ throw new Error(`Unable to get ISO string for '${JSON.stringify(fullDate)}'`);
59
+ }
60
+ return isoString;
61
+ }
@@ -0,0 +1,91 @@
1
+ import { Timezone, UtcTimezone } from '../timezone/timezones.js';
2
+ import { DateLike } from './date-like.js';
3
+ import { FullDate } from './full-date-shape.js';
4
+ /**
5
+ * Parses the given {@link DateLike} and converts it into a {@link FullDate} instance with the user's
6
+ * current timezone.
7
+ *
8
+ * @category FullDate
9
+ * @example
10
+ *
11
+ * ```ts
12
+ * import {createFullDateInUserTimezone} from 'date-vir';
13
+ *
14
+ * createFullDateInUserTimezone('June 1, 2024');
15
+ * createFullDateInUserTimezone(new Date());
16
+ * createFullDateInUserTimezone(112300120);
17
+ * ```
18
+ */
19
+ export declare function createFullDateInUserTimezone(dateLike: Readonly<DateLike>): FullDate;
20
+ /**
21
+ * Parses the given {@link DateLike} and converts it into a {@link FullDate} instance with the UTC
22
+ * timezone.
23
+ *
24
+ * @category FullDate
25
+ * @example
26
+ *
27
+ * ```ts
28
+ * import {createUtcFullDate} from 'date-vir';
29
+ *
30
+ * createUtcFullDate('June 1, 2024');
31
+ * createUtcFullDate(new Date());
32
+ * createUtcFullDate(112300120);
33
+ * ```
34
+ */
35
+ export declare function createUtcFullDate(dateLike: Readonly<DateLike>): FullDate<UtcTimezone>;
36
+ /**
37
+ * Parses the given {@link DateLike} and converts it into a {@link FullDate} instance with the given
38
+ * timezone.
39
+ *
40
+ * @category FullDate
41
+ * @example
42
+ *
43
+ * ```ts
44
+ * import {createFullDate, timezones, utcTimezone} from 'date-vir';
45
+ *
46
+ * createFullDate('June 1, 2024', utcTimezone);
47
+ * createFullDate(new Date(), timezones['Australia/Brisbane']);
48
+ * createFullDate(112300120, timezones['Etc/GMT-11']);
49
+ * ```
50
+ */
51
+ export declare function createFullDate<const SpecificTimezone extends Timezone>(
52
+ /** The original date representation to be converted into a FullDate. */
53
+ dateLike: Readonly<DateLike>,
54
+ /** The timezone that this date/time is meant for / originated from. */
55
+ timezone: SpecificTimezone): FullDate<SpecificTimezone>;
56
+ /**
57
+ * Converts a {@link FullDate} instance into a new instance with the original's date and time
58
+ * represented in the new timezone.
59
+ *
60
+ * @category Conversion
61
+ * @example
62
+ *
63
+ * ```ts
64
+ * import {toNewTimezone} from 'date-vir';
65
+ *
66
+ * const exampleDate: FullDate = {
67
+ * year: 2024,
68
+ * month: 1,
69
+ * day: 5,
70
+ * hour: 1,
71
+ * minute: 1,
72
+ * second: 1,
73
+ * millisecond: 1,
74
+ * timezone: 'UTC',
75
+ * };
76
+ *
77
+ * let result = toNewTimezone(exampleDate, timezones['Australia/Brisbane']);
78
+ * // output:
79
+ * result = {
80
+ * year: 2024,
81
+ * month: 1,
82
+ * day: 5,
83
+ * hour: 11,
84
+ * minute: 1,
85
+ * second: 1,
86
+ * millisecond: 1,
87
+ * timezone: timezones['Australia/Brisbane'],
88
+ * };
89
+ * ```
90
+ */
91
+ export declare function toNewTimezone<const SpecificTimezone extends Timezone>(fullDate: Readonly<FullDate>, timezone: SpecificTimezone): FullDate<SpecificTimezone>;