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.
- package/README.md +13 -13
- package/dist/date-operations/calculate-relative-date.d.ts +2 -1
- package/dist/date-operations/combine-dates.d.ts +9 -8
- package/dist/date-operations/date-position.d.ts +3 -2
- package/dist/date-operations/diff-dates.d.ts +4 -4
- package/dist/date-operations/diff-dates.js +4 -4
- package/dist/duration-shape.d.ts +294 -0
- package/dist/duration-shape.js +18 -1
- package/dist/extra-utils/has-date-props.d.ts +3 -2
- package/dist/extra-utils/js-date-conversion.d.ts +2 -2
- package/dist/extra-utils/js-date-conversion.js +2 -2
- package/dist/extra-utils/now.d.ts +4 -4
- package/dist/extra-utils/now.js +2 -2
- package/dist/extra-utils/override-date.d.ts +5 -4
- package/dist/extra-utils/override-date.js +3 -3
- package/dist/extra-utils/zero.d.ts +9 -8
- package/dist/extra-utils/zero.js +6 -6
- package/dist/formatting/simple-strings.d.ts +7 -6
- package/dist/formatting/simple-strings.js +1 -1
- package/dist/formatting/timestamp.d.ts +6 -6
- package/dist/formatting/timestamp.js +6 -6
- package/dist/full-date/create-full-date.d.ts +10 -10
- package/dist/full-date/create-full-date.js +7 -7
- package/dist/full-date/date-like.d.ts +2 -1
- package/dist/full-date/full-date-shape.d.ts +10 -9
- package/dist/full-date/is-valid-full-date.d.ts +2 -1
- package/dist/full-date/luxon-date-time-conversion.d.ts +2 -1
- package/dist/full-date/luxon-date-time-conversion.js +7 -2
- package/dist/full-date/maybe-create-date.d.ts +2 -1
- package/dist/full-date/parsing.d.ts +3 -2
- package/dist/full-date/string-parsing.d.ts +2 -1
- package/dist/full-date/string-parsing.js +0 -1
- package/dist/timezone/timezone-checks.d.ts +15 -2
- package/dist/timezone/timezone-checks.js +25 -8
- package/dist/timezone/timezone-shape.d.ts +4 -3
- package/dist/timezone/timezone-shape.js +2 -2
- package/dist/timezone/timezones.d.ts +21 -8
- package/dist/timezone/timezones.js +6 -5
- package/package.json +2 -2
|
@@ -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:
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
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
|
|
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;
|
package/dist/extra-utils/zero.js
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
152
|
+
timezone: Timezone;
|
|
152
153
|
};
|
|
153
154
|
/**
|
|
154
155
|
* Converts a date into a simple, unambiguous date string.
|
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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,
|
|
48
|
+
* import {createFullDate, TimezoneName, utcTimezone} from 'date-vir';
|
|
49
49
|
*
|
|
50
50
|
* createFullDate('June 1, 2024', utcTimezone);
|
|
51
|
-
* createFullDate(new Date(),
|
|
52
|
-
* createFullDate(112300120,
|
|
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
|
|
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:
|
|
80
|
+
* timezone: utcTimezone,
|
|
81
81
|
* };
|
|
82
82
|
*
|
|
83
|
-
* let result = toNewTimezone(exampleDate,
|
|
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:
|
|
93
|
+
* timezone: TimezoneName['Australia/Brisbane'],
|
|
94
94
|
* };
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
|
-
export declare function toNewTimezone<const SpecificTimezone extends
|
|
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,
|
|
56
|
+
* import {createFullDate, TimezoneName, utcTimezone} from 'date-vir';
|
|
57
57
|
*
|
|
58
58
|
* createFullDate('June 1, 2024', utcTimezone);
|
|
59
|
-
* createFullDate(new Date(),
|
|
60
|
-
* createFullDate(112300120,
|
|
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:
|
|
94
|
+
* timezone: utcTimezone,
|
|
95
95
|
* };
|
|
96
96
|
*
|
|
97
|
-
* let result = toNewTimezone(exampleDate,
|
|
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:
|
|
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
|
|
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<
|
|
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
|
|
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<
|
|
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
|
|
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:
|
|
63
|
+
timezone: Timezone;
|
|
63
64
|
} & {
|
|
64
65
|
year: number;
|
|
65
66
|
month: MonthNumber;
|
|
66
67
|
day: DayOfMonth;
|
|
67
|
-
timezone:
|
|
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,
|
|
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:
|
|
91
|
+
* timezone: TimezoneName['Australia/Brisbane'],
|
|
91
92
|
* };
|
|
92
93
|
* ```
|
|
93
94
|
*/
|
|
94
|
-
export type FullDate<SpecificTimezone extends
|
|
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
|
|
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
|
|
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 ??
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
9
|
+
export declare function parseDateString(dateString: string, timezone: Timezone): DateTime | undefined;
|