date-vir 7.4.0 → 7.4.2
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/dist/date-operations/combine-dates.js +3 -3
- package/dist/date-operations/date-position.d.ts +22 -22
- package/dist/date-operations/date-position.js +17 -17
- package/dist/duration-shape.d.ts +1 -5
- package/dist/duration-shape.js +3 -3
- package/dist/formatting/html-input.js +1 -1
- package/dist/formatting/string-format-types.d.ts +1 -1
- package/dist/formatting/string-format-types.js +6 -6
- package/dist/full-date/full-date-shape.d.ts +23 -972
- package/dist/full-date/full-date-shape.js +9 -9
- package/dist/full-date/string-parsing.js +13 -1
- package/package.json +10 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { checkValidShape } from 'object-shape-tester';
|
|
2
2
|
import { datePartShape, timePartShape, } from '../full-date/full-date-shape.js';
|
|
3
3
|
/**
|
|
4
4
|
* Combine two parts of a {@link FullDate} objects into a filled-in {@link FullDate}. Note that the
|
|
@@ -8,7 +8,7 @@ import { datePartShape, timePartShape, } from '../full-date/full-date-shape.js';
|
|
|
8
8
|
* @category Util
|
|
9
9
|
*/
|
|
10
10
|
export function combineDateParts(maybeDateParts) {
|
|
11
|
-
const timePart =
|
|
11
|
+
const timePart = checkValidShape(maybeDateParts.time, timePartShape, {
|
|
12
12
|
allowExtraKeys: true,
|
|
13
13
|
})
|
|
14
14
|
? {
|
|
@@ -19,7 +19,7 @@ export function combineDateParts(maybeDateParts) {
|
|
|
19
19
|
timezone: maybeDateParts.time.timezone,
|
|
20
20
|
}
|
|
21
21
|
: undefined;
|
|
22
|
-
const datePart =
|
|
22
|
+
const datePart = checkValidShape(maybeDateParts.date, datePartShape, {
|
|
23
23
|
allowExtraKeys: true,
|
|
24
24
|
})
|
|
25
25
|
? {
|
|
@@ -87,28 +87,28 @@ export declare function getEndDate<const SpecificTimezone extends Timezone>(date
|
|
|
87
87
|
*
|
|
88
88
|
* @category Internal
|
|
89
89
|
*/
|
|
90
|
-
export declare const datePositionCalculationShape: import("object-shape-tester").
|
|
91
|
-
get: import("
|
|
92
|
-
in: import("
|
|
93
|
-
}
|
|
94
|
-
get: import("
|
|
95
|
-
in: import("
|
|
96
|
-
}
|
|
97
|
-
get: import("
|
|
98
|
-
in: import("
|
|
99
|
-
}
|
|
100
|
-
get: import("
|
|
101
|
-
in: import("
|
|
102
|
-
}
|
|
103
|
-
get: import("
|
|
104
|
-
in: import("
|
|
105
|
-
}
|
|
106
|
-
get: import("
|
|
107
|
-
in: import("
|
|
108
|
-
}
|
|
109
|
-
get: import("
|
|
110
|
-
in: import("
|
|
111
|
-
}]
|
|
90
|
+
export declare const datePositionCalculationShape: import("object-shape-tester").Shape<import("object-shape-tester").Shape<import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TObject<{
|
|
91
|
+
get: import("@sinclair/typebox").TUnsafe<DateUnit.Month>;
|
|
92
|
+
in: import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<DateUnit.Year> | import("@sinclair/typebox").TUnsafe<DateUnit.Quarter>)[]>;
|
|
93
|
+
}> | import("@sinclair/typebox").TObject<{
|
|
94
|
+
get: import("@sinclair/typebox").TUnsafe<DateUnit.Week>;
|
|
95
|
+
in: import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<DateUnit.Month> | import("@sinclair/typebox").TUnsafe<DateUnit.Year> | import("@sinclair/typebox").TUnsafe<DateUnit.Quarter>)[]>;
|
|
96
|
+
}> | import("@sinclair/typebox").TObject<{
|
|
97
|
+
get: import("@sinclair/typebox").TUnsafe<DateUnit.Day>;
|
|
98
|
+
in: import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<DateUnit.Month> | import("@sinclair/typebox").TUnsafe<DateUnit.Year> | import("@sinclair/typebox").TUnsafe<DateUnit.Quarter> | import("@sinclair/typebox").TUnsafe<DateUnit.Week>)[]>;
|
|
99
|
+
}> | import("@sinclair/typebox").TObject<{
|
|
100
|
+
get: import("@sinclair/typebox").TUnsafe<DateUnit.Hour>;
|
|
101
|
+
in: import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<DateUnit.Month> | import("@sinclair/typebox").TUnsafe<DateUnit.Year> | import("@sinclair/typebox").TUnsafe<DateUnit.Quarter> | import("@sinclair/typebox").TUnsafe<DateUnit.Week> | import("@sinclair/typebox").TUnsafe<DateUnit.Day>)[]>;
|
|
102
|
+
}> | import("@sinclair/typebox").TObject<{
|
|
103
|
+
get: import("@sinclair/typebox").TUnsafe<DateUnit.Minute>;
|
|
104
|
+
in: import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<DateUnit.Month> | import("@sinclair/typebox").TUnsafe<DateUnit.Year> | import("@sinclair/typebox").TUnsafe<DateUnit.Quarter> | import("@sinclair/typebox").TUnsafe<DateUnit.Week> | import("@sinclair/typebox").TUnsafe<DateUnit.Day> | import("@sinclair/typebox").TUnsafe<DateUnit.Hour>)[]>;
|
|
105
|
+
}> | import("@sinclair/typebox").TObject<{
|
|
106
|
+
get: import("@sinclair/typebox").TUnsafe<DateUnit.Second>;
|
|
107
|
+
in: import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<DateUnit.Month> | import("@sinclair/typebox").TUnsafe<DateUnit.Year> | import("@sinclair/typebox").TUnsafe<DateUnit.Quarter> | import("@sinclair/typebox").TUnsafe<DateUnit.Week> | import("@sinclair/typebox").TUnsafe<DateUnit.Day> | import("@sinclair/typebox").TUnsafe<DateUnit.Hour> | import("@sinclair/typebox").TUnsafe<DateUnit.Minute>)[]>;
|
|
108
|
+
}> | import("@sinclair/typebox").TObject<{
|
|
109
|
+
get: import("@sinclair/typebox").TUnsafe<DateUnit.Millisecond>;
|
|
110
|
+
in: import("@sinclair/typebox").TUnion<(import("@sinclair/typebox").TUnsafe<DateUnit.Month> | import("@sinclair/typebox").TUnsafe<DateUnit.Year> | import("@sinclair/typebox").TUnsafe<DateUnit.Quarter> | import("@sinclair/typebox").TUnsafe<DateUnit.Week> | import("@sinclair/typebox").TUnsafe<DateUnit.Day> | import("@sinclair/typebox").TUnsafe<DateUnit.Hour> | import("@sinclair/typebox").TUnsafe<DateUnit.Minute> | import("@sinclair/typebox").TUnsafe<DateUnit.Second>)[]>;
|
|
111
|
+
}>)[]>>>;
|
|
112
112
|
/**
|
|
113
113
|
* All valid date position calculations. Used for {@link calculateDatePosition}.
|
|
114
114
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
2
|
import { stringify } from '@augment-vir/common';
|
|
3
3
|
import { DateUnit, oneIndexedDateUnits } from '@date-vir/duration';
|
|
4
|
-
import {
|
|
4
|
+
import { checkValidShape, defineShape, exactShape, unionShape } from 'object-shape-tester';
|
|
5
5
|
import { createFullDate } from '../full-date/create-full-date.js';
|
|
6
6
|
import { toLuxonDateTime } from '../full-date/luxon-date-time-conversion.js';
|
|
7
7
|
import { calculateRelativeDate } from './calculate-relative-date.js';
|
|
@@ -126,27 +126,27 @@ export function getEndDate(date, unit) {
|
|
|
126
126
|
*
|
|
127
127
|
* @category Internal
|
|
128
128
|
*/
|
|
129
|
-
export const datePositionCalculationShape = defineShape(
|
|
130
|
-
get:
|
|
131
|
-
in:
|
|
129
|
+
export const datePositionCalculationShape = defineShape(unionShape({
|
|
130
|
+
get: exactShape(DateUnit.Month),
|
|
131
|
+
in: unionShape(exactShape(DateUnit.Year), exactShape(DateUnit.Quarter)),
|
|
132
132
|
}, {
|
|
133
|
-
get:
|
|
134
|
-
in:
|
|
133
|
+
get: exactShape(DateUnit.Week),
|
|
134
|
+
in: unionShape(exactShape(DateUnit.Year), exactShape(DateUnit.Quarter), exactShape(DateUnit.Month)),
|
|
135
135
|
}, {
|
|
136
|
-
get:
|
|
137
|
-
in:
|
|
136
|
+
get: exactShape(DateUnit.Day),
|
|
137
|
+
in: unionShape(exactShape(DateUnit.Year), exactShape(DateUnit.Quarter), exactShape(DateUnit.Month), exactShape(DateUnit.Week)),
|
|
138
138
|
}, {
|
|
139
|
-
get:
|
|
140
|
-
in:
|
|
139
|
+
get: exactShape(DateUnit.Hour),
|
|
140
|
+
in: unionShape(exactShape(DateUnit.Year), exactShape(DateUnit.Quarter), exactShape(DateUnit.Month), exactShape(DateUnit.Week), exactShape(DateUnit.Day)),
|
|
141
141
|
}, {
|
|
142
|
-
get:
|
|
143
|
-
in:
|
|
142
|
+
get: exactShape(DateUnit.Minute),
|
|
143
|
+
in: unionShape(exactShape(DateUnit.Year), exactShape(DateUnit.Quarter), exactShape(DateUnit.Month), exactShape(DateUnit.Week), exactShape(DateUnit.Day), exactShape(DateUnit.Hour)),
|
|
144
144
|
}, {
|
|
145
|
-
get:
|
|
146
|
-
in:
|
|
145
|
+
get: exactShape(DateUnit.Second),
|
|
146
|
+
in: unionShape(exactShape(DateUnit.Year), exactShape(DateUnit.Quarter), exactShape(DateUnit.Month), exactShape(DateUnit.Week), exactShape(DateUnit.Day), exactShape(DateUnit.Hour), exactShape(DateUnit.Minute)),
|
|
147
147
|
}, {
|
|
148
|
-
get:
|
|
149
|
-
in:
|
|
148
|
+
get: exactShape(DateUnit.Millisecond),
|
|
149
|
+
in: unionShape(exactShape(DateUnit.Year), exactShape(DateUnit.Quarter), exactShape(DateUnit.Month), exactShape(DateUnit.Week), exactShape(DateUnit.Day), exactShape(DateUnit.Hour), exactShape(DateUnit.Minute), exactShape(DateUnit.Second)),
|
|
150
150
|
}));
|
|
151
151
|
/**
|
|
152
152
|
* Calculate the position of the given date's "get" unit within the given "in" unit.
|
|
@@ -198,7 +198,7 @@ export const datePositionCalculationShape = defineShape(or({
|
|
|
198
198
|
* ```
|
|
199
199
|
*/
|
|
200
200
|
export function calculateDatePosition(date, calculation) {
|
|
201
|
-
if (!
|
|
201
|
+
if (!checkValidShape(calculation, datePositionCalculationShape)) {
|
|
202
202
|
throw new Error(`Invalid date position calculation for '${stringify(date)}': cannot get ${calculation.get} in ${calculation.in}.`);
|
|
203
203
|
}
|
|
204
204
|
const start = getStartDate(date, calculation.in);
|
package/dist/duration-shape.d.ts
CHANGED
|
@@ -4,8 +4,4 @@ import { DurationUnit } from '@date-vir/duration';
|
|
|
4
4
|
*
|
|
5
5
|
* @category Duration
|
|
6
6
|
*/
|
|
7
|
-
export declare const anyDurationShape: import("
|
|
8
|
-
keys: import("object-shape-tester").ShapeEnum<readonly [typeof DurationUnit]>;
|
|
9
|
-
values: number;
|
|
10
|
-
required: false;
|
|
11
|
-
}]>;
|
|
7
|
+
export declare const anyDurationShape: import("@sinclair/typebox").TUnsafe<Partial<Record<DurationUnit, number>>>;
|
package/dist/duration-shape.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DurationUnit } from '@date-vir/duration';
|
|
2
|
-
import { enumShape,
|
|
2
|
+
import { enumShape, recordShape } from 'object-shape-tester';
|
|
3
3
|
/**
|
|
4
4
|
* A shape definition for `AnyDuration`.
|
|
5
5
|
*
|
|
6
6
|
* @category Duration
|
|
7
7
|
*/
|
|
8
|
-
export const anyDurationShape =
|
|
8
|
+
export const anyDurationShape = recordShape({
|
|
9
9
|
keys: enumShape(DurationUnit),
|
|
10
10
|
values: -1,
|
|
11
|
-
|
|
11
|
+
partial: true,
|
|
12
12
|
});
|
|
@@ -42,6 +42,6 @@ export function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
|
42
42
|
return `${datePart}T${timePart}`;
|
|
43
43
|
}
|
|
44
44
|
else {
|
|
45
|
-
throw new Error(`Unexpected inputTyped: '${
|
|
45
|
+
throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of FullDatePart, one of ${getEnumValues(FullDatePart).join(', ')}.`);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -47,7 +47,7 @@ export type UtcIsoString = `${JustDateString}T${JustTimeWithSecondsString}.${num
|
|
|
47
47
|
*
|
|
48
48
|
* @category ISO
|
|
49
49
|
*/
|
|
50
|
-
export declare const utcIsoStringShape: import("object-shape-tester").
|
|
50
|
+
export declare const utcIsoStringShape: (defaultValue?: `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z` | undefined) => import("object-shape-tester").Shape<import("@sinclair/typebox").TUnsafe<`${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`>>;
|
|
51
51
|
/**
|
|
52
52
|
* Checks if the input is a valid UTC ISO string and type guards the input.
|
|
53
53
|
*
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
|
-
import {
|
|
2
|
+
import { createCustomShape } from 'object-shape-tester';
|
|
3
3
|
/**
|
|
4
4
|
* A shape definition for {@link UtcIsoString}.
|
|
5
5
|
*
|
|
6
6
|
* @category ISO
|
|
7
7
|
*/
|
|
8
|
-
export const utcIsoStringShape =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export const utcIsoStringShape = createCustomShape({
|
|
9
|
+
default: new Date().toISOString(),
|
|
10
|
+
name: 'UtcIsoString',
|
|
11
|
+
checkValue(value) {
|
|
12
12
|
return isValidIsoString(value);
|
|
13
13
|
},
|
|
14
|
-
})
|
|
14
|
+
});
|
|
15
15
|
/**
|
|
16
16
|
* Checks if the input is a valid UTC ISO string and type guards the input.
|
|
17
17
|
*
|