date-vir 6.0.1 → 7.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.
- package/dist/date-operations/date-position.d.ts +148 -0
- package/dist/date-operations/date-position.js +174 -0
- package/dist/extra-utils/end.d.ts +11 -0
- package/dist/extra-utils/end.js +11 -0
- package/dist/extra-utils/zero.d.ts +17 -7
- package/dist/extra-utils/zero.js +9 -9
- package/dist/full-date/full-date-parts.d.ts +11 -15
- package/dist/full-date/full-date-parts.js +13 -11
- package/dist/full-date/full-date-shape.d.ts +16 -14
- package/dist/full-date/full-date-shape.js +8 -7
- package/dist/full-date/luxon-date-time-conversion.js +7 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/timezone/timezones.js +0 -1
- package/package.json +10 -10
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { DateUnit } from '@date-vir/duration';
|
|
2
|
+
import { type FullDate } from '../full-date/full-date-shape.js';
|
|
3
|
+
import { Timezone } from '../timezone/timezones.js';
|
|
4
|
+
/**
|
|
5
|
+
* Get the {@link DateUnit} value of a {@link FullDate}.
|
|
6
|
+
*
|
|
7
|
+
* @category Calculation
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {getDateUnit, DateUnit, utcTimezone} from 'date-vir';
|
|
12
|
+
*
|
|
13
|
+
* getDateUnit(
|
|
14
|
+
* {
|
|
15
|
+
* year: 2024,
|
|
16
|
+
* month: 11,
|
|
17
|
+
* day: 7,
|
|
18
|
+
*
|
|
19
|
+
* hour: 12,
|
|
20
|
+
* minute: 12,
|
|
21
|
+
* second: 12,
|
|
22
|
+
* millisecond: 12,
|
|
23
|
+
*
|
|
24
|
+
* timezone: utcTimezone,
|
|
25
|
+
* },
|
|
26
|
+
* DateUnit.Week,
|
|
27
|
+
* ); // outputs `45`
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function getDateUnit(date: Readonly<FullDate>, unit: DateUnit): number;
|
|
31
|
+
/**
|
|
32
|
+
* Get the start date of a specific {@link DateUnit} based on a given {@link FullDate}.
|
|
33
|
+
*
|
|
34
|
+
* @category Calculation
|
|
35
|
+
* @example
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* import {getStartDate, DateUnit, utcTimezone} from 'date-vir';
|
|
39
|
+
*
|
|
40
|
+
* getStartDate(
|
|
41
|
+
* {
|
|
42
|
+
* year: 2024,
|
|
43
|
+
* month: 11,
|
|
44
|
+
* day: 7,
|
|
45
|
+
*
|
|
46
|
+
* hour: 12,
|
|
47
|
+
* minute: 12,
|
|
48
|
+
* second: 12,
|
|
49
|
+
* millisecond: 12,
|
|
50
|
+
*
|
|
51
|
+
* timezone: utcTimezone,
|
|
52
|
+
* },
|
|
53
|
+
* DateUnit.Month,
|
|
54
|
+
* ); // outputs {year: 2024, month: 11, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0, timezone: utcTimezone}
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function getStartDate<const SpecificTimezone extends Timezone>(date: Readonly<FullDate<SpecificTimezone>>, unit: DateUnit): FullDate<SpecificTimezone>;
|
|
58
|
+
/**
|
|
59
|
+
* Get the end date of a specific {@link DateUnit} based on a given {@link FullDate}.
|
|
60
|
+
*
|
|
61
|
+
* @category Calculation
|
|
62
|
+
* @example
|
|
63
|
+
*
|
|
64
|
+
* ```ts
|
|
65
|
+
* import {getEndDate, DateUnit, utcTimezone} from 'date-vir';
|
|
66
|
+
*
|
|
67
|
+
* getEndDate(
|
|
68
|
+
* {
|
|
69
|
+
* year: 2024,
|
|
70
|
+
* month: 11,
|
|
71
|
+
* day: 7,
|
|
72
|
+
*
|
|
73
|
+
* hour: 12,
|
|
74
|
+
* minute: 12,
|
|
75
|
+
* second: 12,
|
|
76
|
+
* millisecond: 12,
|
|
77
|
+
*
|
|
78
|
+
* timezone: utcTimezone,
|
|
79
|
+
* },
|
|
80
|
+
* DateUnit.Month,
|
|
81
|
+
* ); // outputs {year: 2024, month: 11, day: 30, hour: 23, minute: 59, second: 59, millisecond: 999, timezone: utcTimezone}
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function getEndDate<const SpecificTimezone extends Timezone>(date: Readonly<FullDate<SpecificTimezone>>, unit: DateUnit): FullDate<SpecificTimezone>;
|
|
85
|
+
/**
|
|
86
|
+
* Shape definition for all valid date position calculations. Used for {@link calculateDatePosition}.
|
|
87
|
+
*
|
|
88
|
+
* @category Internal
|
|
89
|
+
*/
|
|
90
|
+
export declare const datePositionCalculationShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").ShapeOr<[{
|
|
91
|
+
get: import("object-shape-tester").ShapeExact<readonly [DateUnit.Month]>;
|
|
92
|
+
in: import("object-shape-tester").ShapeOr<[import("object-shape-tester").ShapeExact<readonly [DateUnit.Year]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Quarter]>]>;
|
|
93
|
+
}, {
|
|
94
|
+
get: import("object-shape-tester").ShapeExact<readonly [DateUnit.Week]>;
|
|
95
|
+
in: import("object-shape-tester").ShapeOr<[import("object-shape-tester").ShapeExact<readonly [DateUnit.Year]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Quarter]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Month]>]>;
|
|
96
|
+
}, {
|
|
97
|
+
get: import("object-shape-tester").ShapeExact<readonly [DateUnit.Day]>;
|
|
98
|
+
in: import("object-shape-tester").ShapeOr<[import("object-shape-tester").ShapeExact<readonly [DateUnit.Year]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Quarter]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Month]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Week]>]>;
|
|
99
|
+
}, {
|
|
100
|
+
get: import("object-shape-tester").ShapeExact<readonly [DateUnit.Hour]>;
|
|
101
|
+
in: import("object-shape-tester").ShapeOr<[import("object-shape-tester").ShapeExact<readonly [DateUnit.Year]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Quarter]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Month]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Week]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Day]>]>;
|
|
102
|
+
}, {
|
|
103
|
+
get: import("object-shape-tester").ShapeExact<readonly [DateUnit.Minute]>;
|
|
104
|
+
in: import("object-shape-tester").ShapeOr<[import("object-shape-tester").ShapeExact<readonly [DateUnit.Year]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Quarter]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Month]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Week]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Day]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Hour]>]>;
|
|
105
|
+
}, {
|
|
106
|
+
get: import("object-shape-tester").ShapeExact<readonly [DateUnit.Second]>;
|
|
107
|
+
in: import("object-shape-tester").ShapeOr<[import("object-shape-tester").ShapeExact<readonly [DateUnit.Year]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Quarter]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Month]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Week]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Day]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Hour]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Minute]>]>;
|
|
108
|
+
}, {
|
|
109
|
+
get: import("object-shape-tester").ShapeExact<readonly [DateUnit.Millisecond]>;
|
|
110
|
+
in: import("object-shape-tester").ShapeOr<[import("object-shape-tester").ShapeExact<readonly [DateUnit.Year]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Quarter]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Month]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Week]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Day]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Hour]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Minute]>, import("object-shape-tester").ShapeExact<readonly [DateUnit.Second]>]>;
|
|
111
|
+
}]>, false>;
|
|
112
|
+
/**
|
|
113
|
+
* All valid date position calculations. Used for {@link calculateDatePosition}.
|
|
114
|
+
*
|
|
115
|
+
* @category Internal
|
|
116
|
+
*/
|
|
117
|
+
export type DatePositionCalculation = typeof datePositionCalculationShape.runtimeType;
|
|
118
|
+
/**
|
|
119
|
+
* Calculate the position of the given date's day within the given date unit.
|
|
120
|
+
*
|
|
121
|
+
* @category Calculation
|
|
122
|
+
* @example
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* import {calculateDatePosition, DateUnit} from 'date-vir';
|
|
126
|
+
*
|
|
127
|
+
* calculateDatePosition(
|
|
128
|
+
* {
|
|
129
|
+
* day: 5,
|
|
130
|
+
* month: 4,
|
|
131
|
+
* year: 2020,
|
|
132
|
+
* },
|
|
133
|
+
* DateUnit.Month,
|
|
134
|
+
* );
|
|
135
|
+
* // result is 5
|
|
136
|
+
*
|
|
137
|
+
* calculateDatePosition(
|
|
138
|
+
* {
|
|
139
|
+
* day: 5,
|
|
140
|
+
* month: 4,
|
|
141
|
+
* year: 2020,
|
|
142
|
+
* },
|
|
143
|
+
* DateUnit.Week,
|
|
144
|
+
* );
|
|
145
|
+
* // result is
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function calculateDatePosition(date: Readonly<FullDate>, calculation: Readonly<DatePositionCalculation>): number;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { stringify } from '@augment-vir/common';
|
|
3
|
+
import { DateUnit, oneIndexedDateUnits } from '@date-vir/duration';
|
|
4
|
+
import { defineShape, exact, isValidShape, or } from 'object-shape-tester';
|
|
5
|
+
import { createFullDate } from '../full-date/create-full-date.js';
|
|
6
|
+
import { toLuxonDateTime } from '../full-date/luxon-date-time-conversion.js';
|
|
7
|
+
import { diffDates } from './diff-dates.js';
|
|
8
|
+
/**
|
|
9
|
+
* Get the {@link DateUnit} value of a {@link FullDate}.
|
|
10
|
+
*
|
|
11
|
+
* @category Calculation
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import {getDateUnit, DateUnit, utcTimezone} from 'date-vir';
|
|
16
|
+
*
|
|
17
|
+
* getDateUnit(
|
|
18
|
+
* {
|
|
19
|
+
* year: 2024,
|
|
20
|
+
* month: 11,
|
|
21
|
+
* day: 7,
|
|
22
|
+
*
|
|
23
|
+
* hour: 12,
|
|
24
|
+
* minute: 12,
|
|
25
|
+
* second: 12,
|
|
26
|
+
* millisecond: 12,
|
|
27
|
+
*
|
|
28
|
+
* timezone: utcTimezone,
|
|
29
|
+
* },
|
|
30
|
+
* DateUnit.Week,
|
|
31
|
+
* ); // outputs `45`
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function getDateUnit(date, unit) {
|
|
35
|
+
const luxonInstance = toLuxonDateTime(date);
|
|
36
|
+
if (unit === DateUnit.Week) {
|
|
37
|
+
return luxonInstance.weekNumber;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return luxonInstance[unit];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the start date of a specific {@link DateUnit} based on a given {@link FullDate}.
|
|
45
|
+
*
|
|
46
|
+
* @category Calculation
|
|
47
|
+
* @example
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* import {getStartDate, DateUnit, utcTimezone} from 'date-vir';
|
|
51
|
+
*
|
|
52
|
+
* getStartDate(
|
|
53
|
+
* {
|
|
54
|
+
* year: 2024,
|
|
55
|
+
* month: 11,
|
|
56
|
+
* day: 7,
|
|
57
|
+
*
|
|
58
|
+
* hour: 12,
|
|
59
|
+
* minute: 12,
|
|
60
|
+
* second: 12,
|
|
61
|
+
* millisecond: 12,
|
|
62
|
+
*
|
|
63
|
+
* timezone: utcTimezone,
|
|
64
|
+
* },
|
|
65
|
+
* DateUnit.Month,
|
|
66
|
+
* ); // outputs {year: 2024, month: 11, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0, timezone: utcTimezone}
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function getStartDate(date, unit) {
|
|
70
|
+
const luxonInstance = toLuxonDateTime(date);
|
|
71
|
+
return createFullDate(luxonInstance.startOf(unit), date.timezone);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the end date of a specific {@link DateUnit} based on a given {@link FullDate}.
|
|
75
|
+
*
|
|
76
|
+
* @category Calculation
|
|
77
|
+
* @example
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* import {getEndDate, DateUnit, utcTimezone} from 'date-vir';
|
|
81
|
+
*
|
|
82
|
+
* getEndDate(
|
|
83
|
+
* {
|
|
84
|
+
* year: 2024,
|
|
85
|
+
* month: 11,
|
|
86
|
+
* day: 7,
|
|
87
|
+
*
|
|
88
|
+
* hour: 12,
|
|
89
|
+
* minute: 12,
|
|
90
|
+
* second: 12,
|
|
91
|
+
* millisecond: 12,
|
|
92
|
+
*
|
|
93
|
+
* timezone: utcTimezone,
|
|
94
|
+
* },
|
|
95
|
+
* DateUnit.Month,
|
|
96
|
+
* ); // outputs {year: 2024, month: 11, day: 30, hour: 23, minute: 59, second: 59, millisecond: 999, timezone: utcTimezone}
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function getEndDate(date, unit) {
|
|
100
|
+
const luxonInstance = toLuxonDateTime(date);
|
|
101
|
+
return createFullDate(luxonInstance.endOf(unit), date.timezone);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Shape definition for all valid date position calculations. Used for {@link calculateDatePosition}.
|
|
105
|
+
*
|
|
106
|
+
* @category Internal
|
|
107
|
+
*/
|
|
108
|
+
export const datePositionCalculationShape = defineShape(or({
|
|
109
|
+
get: exact(DateUnit.Month),
|
|
110
|
+
in: or(exact(DateUnit.Year), exact(DateUnit.Quarter)),
|
|
111
|
+
}, {
|
|
112
|
+
get: exact(DateUnit.Week),
|
|
113
|
+
in: or(exact(DateUnit.Year), exact(DateUnit.Quarter), exact(DateUnit.Month)),
|
|
114
|
+
}, {
|
|
115
|
+
get: exact(DateUnit.Day),
|
|
116
|
+
in: or(exact(DateUnit.Year), exact(DateUnit.Quarter), exact(DateUnit.Month), exact(DateUnit.Week)),
|
|
117
|
+
}, {
|
|
118
|
+
get: exact(DateUnit.Hour),
|
|
119
|
+
in: or(exact(DateUnit.Year), exact(DateUnit.Quarter), exact(DateUnit.Month), exact(DateUnit.Week), exact(DateUnit.Day)),
|
|
120
|
+
}, {
|
|
121
|
+
get: exact(DateUnit.Minute),
|
|
122
|
+
in: or(exact(DateUnit.Year), exact(DateUnit.Quarter), exact(DateUnit.Month), exact(DateUnit.Week), exact(DateUnit.Day), exact(DateUnit.Hour)),
|
|
123
|
+
}, {
|
|
124
|
+
get: exact(DateUnit.Second),
|
|
125
|
+
in: or(exact(DateUnit.Year), exact(DateUnit.Quarter), exact(DateUnit.Month), exact(DateUnit.Week), exact(DateUnit.Day), exact(DateUnit.Hour), exact(DateUnit.Minute)),
|
|
126
|
+
}, {
|
|
127
|
+
get: exact(DateUnit.Millisecond),
|
|
128
|
+
in: or(exact(DateUnit.Year), exact(DateUnit.Quarter), exact(DateUnit.Month), exact(DateUnit.Week), exact(DateUnit.Day), exact(DateUnit.Hour), exact(DateUnit.Minute), exact(DateUnit.Second)),
|
|
129
|
+
}));
|
|
130
|
+
/**
|
|
131
|
+
* Calculate the position of the given date's day within the given date unit.
|
|
132
|
+
*
|
|
133
|
+
* @category Calculation
|
|
134
|
+
* @example
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* import {calculateDatePosition, DateUnit} from 'date-vir';
|
|
138
|
+
*
|
|
139
|
+
* calculateDatePosition(
|
|
140
|
+
* {
|
|
141
|
+
* day: 5,
|
|
142
|
+
* month: 4,
|
|
143
|
+
* year: 2020,
|
|
144
|
+
* },
|
|
145
|
+
* DateUnit.Month,
|
|
146
|
+
* );
|
|
147
|
+
* // result is 5
|
|
148
|
+
*
|
|
149
|
+
* calculateDatePosition(
|
|
150
|
+
* {
|
|
151
|
+
* day: 5,
|
|
152
|
+
* month: 4,
|
|
153
|
+
* year: 2020,
|
|
154
|
+
* },
|
|
155
|
+
* DateUnit.Week,
|
|
156
|
+
* );
|
|
157
|
+
* // result is
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export function calculateDatePosition(date, calculation) {
|
|
161
|
+
if (!isValidShape(calculation, datePositionCalculationShape)) {
|
|
162
|
+
throw new Error(`Invalid date position calculation for '${stringify(date)}': cannot get ${calculation.get} in ${calculation.in}.`);
|
|
163
|
+
}
|
|
164
|
+
const start = getStartDate(date, calculation.in);
|
|
165
|
+
const diffUnit = `${calculation.get}s`;
|
|
166
|
+
const diff = diffDates({ start, end: date }, { [diffUnit]: true });
|
|
167
|
+
const value = diff[diffUnit];
|
|
168
|
+
if (check.isIn(calculation.get, oneIndexedDateUnits)) {
|
|
169
|
+
return value + 1;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A partial {@link FullDate} instance that has the highest value for each time property.
|
|
3
|
+
*
|
|
4
|
+
* @category Constants
|
|
5
|
+
*/
|
|
6
|
+
export declare const endTime: {
|
|
7
|
+
readonly hour: 23;
|
|
8
|
+
readonly minute: 59;
|
|
9
|
+
readonly second: 59;
|
|
10
|
+
readonly millisecond: 999;
|
|
11
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { TimeKey } from '../full-date/full-date-parts.js';
|
|
1
2
|
import { FullDate } from '../full-date/full-date-shape.js';
|
|
2
3
|
import { 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
|
*
|
|
6
|
-
* @category
|
|
7
|
+
* @category Constants
|
|
7
8
|
*/
|
|
8
9
|
export declare const zeroDate: {
|
|
9
10
|
readonly year: 0;
|
|
@@ -18,7 +19,7 @@ export declare const zeroDate: {
|
|
|
18
19
|
* A {@link FullDate} instance that has the lowest, valid, non-negative, value for each property.
|
|
19
20
|
* Alias for {@link zeroDate}.
|
|
20
21
|
*
|
|
21
|
-
* @category
|
|
22
|
+
* @category Constants
|
|
22
23
|
*/
|
|
23
24
|
export declare const emptyDate: {
|
|
24
25
|
readonly year: 0;
|
|
@@ -32,7 +33,7 @@ export declare const emptyDate: {
|
|
|
32
33
|
/**
|
|
33
34
|
* An object that contains the time parts of {@link FullDate} all set to `0`.
|
|
34
35
|
*
|
|
35
|
-
* @category
|
|
36
|
+
* @category Constants
|
|
36
37
|
*/
|
|
37
38
|
export declare const zeroTime: Pick<{
|
|
38
39
|
year: 0;
|
|
@@ -42,11 +43,11 @@ export declare const zeroTime: Pick<{
|
|
|
42
43
|
minute: 0;
|
|
43
44
|
second: 0;
|
|
44
45
|
millisecond: 0;
|
|
45
|
-
},
|
|
46
|
+
}, TimeKey>;
|
|
46
47
|
/**
|
|
47
48
|
* Clear the time parts of a {@link FullDate}, setting them all to `0`.
|
|
48
49
|
*
|
|
49
|
-
* @category
|
|
50
|
+
* @category Clear
|
|
50
51
|
* @example
|
|
51
52
|
*
|
|
52
53
|
* ```ts
|
|
@@ -72,7 +73,7 @@ export declare function clearTime<const SpecificTimezone extends Timezone>(input
|
|
|
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.
|
|
74
75
|
*
|
|
75
|
-
* @category
|
|
76
|
+
* @category Clear
|
|
76
77
|
* @example
|
|
77
78
|
*
|
|
78
79
|
* ```ts
|
|
@@ -96,4 +97,13 @@ export declare function clearTime<const SpecificTimezone extends Timezone>(input
|
|
|
96
97
|
* // `{year: 0, month: 1, day: 1, hour: 1, minute: 1, second: 1, millisecond: 1, timezone: 'UTC'}`
|
|
97
98
|
* ```
|
|
98
99
|
*/
|
|
99
|
-
export declare function clearParts<const SpecificTimezone extends Timezone>(inputFullDate: Readonly<FullDate<SpecificTimezone>>, parts: ReadonlyArray<Exclude<keyof FullDate, 'timezone'>>):
|
|
100
|
+
export declare function clearParts<const SpecificTimezone extends Timezone>(inputFullDate: Readonly<FullDate<SpecificTimezone>>, parts: ReadonlyArray<Exclude<keyof FullDate, 'timezone'>>): {
|
|
101
|
+
hour: import("@date-vir/duration").Hour;
|
|
102
|
+
minute: import("@date-vir/duration").Minute;
|
|
103
|
+
second: import("@date-vir/duration").Minute;
|
|
104
|
+
millisecond: number;
|
|
105
|
+
year: number;
|
|
106
|
+
month: import("@date-vir/duration").MonthNumber;
|
|
107
|
+
day: import("@date-vir/duration").DayOfMonth;
|
|
108
|
+
timezone: SpecificTimezone;
|
|
109
|
+
};
|
package/dist/extra-utils/zero.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { pickObjectKeys, typedObjectFromEntries } from '@augment-vir/common';
|
|
2
|
-
import {
|
|
1
|
+
import { getEnumValues, pickObjectKeys, typedObjectFromEntries } from '@augment-vir/common';
|
|
2
|
+
import { TimeKey } from '../full-date/full-date-parts.js';
|
|
3
3
|
import { overrideDateParts } from './override-date.js';
|
|
4
4
|
/**
|
|
5
5
|
* A {@link FullDate} instance that has the lowest, valid, non-negative, value for each property.
|
|
6
6
|
*
|
|
7
|
-
* @category
|
|
7
|
+
* @category Constants
|
|
8
8
|
*/
|
|
9
9
|
export const zeroDate = {
|
|
10
10
|
year: 0,
|
|
@@ -19,19 +19,19 @@ export const zeroDate = {
|
|
|
19
19
|
* A {@link FullDate} instance that has the lowest, valid, non-negative, value for each property.
|
|
20
20
|
* Alias for {@link zeroDate}.
|
|
21
21
|
*
|
|
22
|
-
* @category
|
|
22
|
+
* @category Constants
|
|
23
23
|
*/
|
|
24
24
|
export const emptyDate = zeroDate;
|
|
25
25
|
/**
|
|
26
26
|
* An object that contains the time parts of {@link FullDate} all set to `0`.
|
|
27
27
|
*
|
|
28
|
-
* @category
|
|
28
|
+
* @category Constants
|
|
29
29
|
*/
|
|
30
|
-
export const zeroTime = pickObjectKeys(zeroDate,
|
|
30
|
+
export const zeroTime = pickObjectKeys(zeroDate, getEnumValues(TimeKey));
|
|
31
31
|
/**
|
|
32
32
|
* Clear the time parts of a {@link FullDate}, setting them all to `0`.
|
|
33
33
|
*
|
|
34
|
-
* @category
|
|
34
|
+
* @category Clear
|
|
35
35
|
* @example
|
|
36
36
|
*
|
|
37
37
|
* ```ts
|
|
@@ -53,13 +53,13 @@ export const zeroTime = pickObjectKeys(zeroDate, timeFullDateKeys);
|
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
55
|
export function clearTime(inputFullDate) {
|
|
56
|
-
return clearParts(inputFullDate,
|
|
56
|
+
return clearParts(inputFullDate, getEnumValues(TimeKey));
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
59
|
* Clear all the selected parts of {@link FullDate} by setting them each to their lowest, valid
|
|
60
60
|
* value. See {@link zeroDate} for the lowest valid values for each property.
|
|
61
61
|
*
|
|
62
|
-
* @category
|
|
62
|
+
* @category Clear
|
|
63
63
|
* @example
|
|
64
64
|
*
|
|
65
65
|
* ```ts
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ArrayElement } from '@augment-vir/common';
|
|
2
1
|
/**
|
|
3
2
|
* Represents various parts of a {@link FullDate}. Each value is also a valid "type" attribute for an
|
|
4
3
|
* `<input>` HTML element.
|
|
@@ -27,22 +26,19 @@ export declare enum FullDatePart {
|
|
|
27
26
|
*
|
|
28
27
|
* @category Internal
|
|
29
28
|
*/
|
|
30
|
-
export declare
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export type TimeFullDateKeys = ArrayElement<typeof timeFullDateKeys>;
|
|
37
|
-
/**
|
|
38
|
-
* {@link FullDate} keys used for telling the date only.
|
|
39
|
-
*
|
|
40
|
-
* @category Internal
|
|
41
|
-
*/
|
|
42
|
-
export declare const dateFullDateKeys: readonly ["year", "month", "day"];
|
|
29
|
+
export declare enum TimeKey {
|
|
30
|
+
Hour = "hour",
|
|
31
|
+
Minute = "minute",
|
|
32
|
+
Second = "second",
|
|
33
|
+
Millisecond = "millisecond"
|
|
34
|
+
}
|
|
43
35
|
/**
|
|
44
36
|
* {@link FullDate} keys used for telling the date only.
|
|
45
37
|
*
|
|
46
38
|
* @category Internal
|
|
47
39
|
*/
|
|
48
|
-
export
|
|
40
|
+
export declare enum DateKey {
|
|
41
|
+
Year = "year",
|
|
42
|
+
Month = "month",
|
|
43
|
+
Day = "day"
|
|
44
|
+
}
|
|
@@ -27,19 +27,21 @@ export var FullDatePart;
|
|
|
27
27
|
*
|
|
28
28
|
* @category Internal
|
|
29
29
|
*/
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
];
|
|
30
|
+
export var TimeKey;
|
|
31
|
+
(function (TimeKey) {
|
|
32
|
+
TimeKey["Hour"] = "hour";
|
|
33
|
+
TimeKey["Minute"] = "minute";
|
|
34
|
+
TimeKey["Second"] = "second";
|
|
35
|
+
TimeKey["Millisecond"] = "millisecond";
|
|
36
|
+
})(TimeKey || (TimeKey = {}));
|
|
36
37
|
/**
|
|
37
38
|
* {@link FullDate} keys used for telling the date only.
|
|
38
39
|
*
|
|
39
40
|
* @category Internal
|
|
40
41
|
*/
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
];
|
|
42
|
+
export var DateKey;
|
|
43
|
+
(function (DateKey) {
|
|
44
|
+
DateKey["Year"] = "year";
|
|
45
|
+
DateKey["Month"] = "month";
|
|
46
|
+
DateKey["Day"] = "day";
|
|
47
|
+
})(DateKey || (DateKey = {}));
|
|
@@ -1,4 +1,6 @@
|
|
|
1
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';
|
|
2
4
|
import { type Timezone } from '../timezone/timezones.js';
|
|
3
5
|
/**
|
|
4
6
|
* Time part of {@link FullDate} represented in a shape definition.
|
|
@@ -7,13 +9,13 @@ import { type Timezone } from '../timezone/timezones.js';
|
|
|
7
9
|
*/
|
|
8
10
|
export declare const timePartShape: import("object-shape-tester").ShapeDefinition<{
|
|
9
11
|
/** Hour of the day in 24 time: 0-23 */
|
|
10
|
-
hour:
|
|
12
|
+
hour: import("object-shape-tester").ShapeNumericRange<Hour>;
|
|
11
13
|
/** Minute of the hour: 0-59 */
|
|
12
|
-
minute:
|
|
14
|
+
minute: import("object-shape-tester").ShapeNumericRange<Minute>;
|
|
13
15
|
/** Second of the minute: 0-59 */
|
|
14
|
-
second:
|
|
16
|
+
second: import("object-shape-tester").ShapeNumericRange<Minute>;
|
|
15
17
|
/** Millisecond of the second: 0-999 */
|
|
16
|
-
millisecond: number
|
|
18
|
+
millisecond: import("object-shape-tester").ShapeNumericRange<number>;
|
|
17
19
|
/** The timezone that this date/time is meant for / originated from. */
|
|
18
20
|
timezone: Timezone;
|
|
19
21
|
}, false>;
|
|
@@ -36,9 +38,9 @@ export declare const datePartShape: import("object-shape-tester").ShapeDefinitio
|
|
|
36
38
|
*/
|
|
37
39
|
year: number;
|
|
38
40
|
/** A month of the year: 1-12 */
|
|
39
|
-
month:
|
|
41
|
+
month: import("object-shape-tester").ShapeNumericRange<MonthNumber>;
|
|
40
42
|
/** A day of the month: 1-31 depending on the month */
|
|
41
|
-
day:
|
|
43
|
+
day: import("object-shape-tester").ShapeNumericRange<DayOfMonth>;
|
|
42
44
|
/** The timezone that this date/time is meant for / originated from. */
|
|
43
45
|
timezone: Timezone;
|
|
44
46
|
}, false>;
|
|
@@ -61,20 +63,20 @@ export declare const fullDateShape: import("object-shape-tester").ShapeDefinitio
|
|
|
61
63
|
*/
|
|
62
64
|
year: number;
|
|
63
65
|
/** A month of the year: 1-12 */
|
|
64
|
-
month:
|
|
66
|
+
month: import("object-shape-tester").ShapeNumericRange<MonthNumber>;
|
|
65
67
|
/** A day of the month: 1-31 depending on the month */
|
|
66
|
-
day:
|
|
68
|
+
day: import("object-shape-tester").ShapeNumericRange<DayOfMonth>;
|
|
67
69
|
/** The timezone that this date/time is meant for / originated from. */
|
|
68
70
|
timezone: Timezone;
|
|
69
71
|
}, false>, import("object-shape-tester").ShapeDefinition<{
|
|
70
72
|
/** Hour of the day in 24 time: 0-23 */
|
|
71
|
-
hour:
|
|
73
|
+
hour: import("object-shape-tester").ShapeNumericRange<Hour>;
|
|
72
74
|
/** Minute of the hour: 0-59 */
|
|
73
|
-
minute:
|
|
75
|
+
minute: import("object-shape-tester").ShapeNumericRange<Minute>;
|
|
74
76
|
/** Second of the minute: 0-59 */
|
|
75
|
-
second:
|
|
77
|
+
second: import("object-shape-tester").ShapeNumericRange<Minute>;
|
|
76
78
|
/** Millisecond of the second: 0-999 */
|
|
77
|
-
millisecond: number
|
|
79
|
+
millisecond: import("object-shape-tester").ShapeNumericRange<number>;
|
|
78
80
|
/** The timezone that this date/time is meant for / originated from. */
|
|
79
81
|
timezone: Timezone;
|
|
80
82
|
}, false>]>, false>;
|
|
@@ -101,6 +103,6 @@ export declare const fullDateShape: import("object-shape-tester").ShapeDefinitio
|
|
|
101
103
|
* };
|
|
102
104
|
* ```
|
|
103
105
|
*/
|
|
104
|
-
export type FullDate<SpecificTimezone extends Timezone = Timezone> = Overwrite<(typeof fullDateShape)['runtimeType'], {
|
|
106
|
+
export type FullDate<SpecificTimezone extends Timezone = Timezone> = Simplify<Overwrite<(typeof fullDateShape)['runtimeType'], {
|
|
105
107
|
timezone: SpecificTimezone;
|
|
106
|
-
}
|
|
108
|
+
}>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dayOfMonthBounds, hourBounds, millisecondsBounds, minuteBounds, monthNumberBounds, secondBounds, } from '@date-vir/duration';
|
|
2
|
+
import { and, defineShape, numericRange } from 'object-shape-tester';
|
|
2
3
|
import { utcTimezone } from '../timezone/timezones.js';
|
|
3
4
|
/**
|
|
4
5
|
* Time part of {@link FullDate} represented in a shape definition.
|
|
@@ -7,13 +8,13 @@ import { utcTimezone } from '../timezone/timezones.js';
|
|
|
7
8
|
*/
|
|
8
9
|
export const timePartShape = defineShape({
|
|
9
10
|
/** Hour of the day in 24 time: 0-23 */
|
|
10
|
-
hour:
|
|
11
|
+
hour: numericRange(hourBounds.min, hourBounds.max),
|
|
11
12
|
/** Minute of the hour: 0-59 */
|
|
12
|
-
minute:
|
|
13
|
+
minute: numericRange(minuteBounds.min, minuteBounds.max),
|
|
13
14
|
/** Second of the minute: 0-59 */
|
|
14
|
-
second:
|
|
15
|
+
second: numericRange(secondBounds.min, secondBounds.max),
|
|
15
16
|
/** Millisecond of the second: 0-999 */
|
|
16
|
-
millisecond:
|
|
17
|
+
millisecond: numericRange(millisecondsBounds.min, millisecondsBounds.max),
|
|
17
18
|
/** The timezone that this date/time is meant for / originated from. */
|
|
18
19
|
timezone: utcTimezone,
|
|
19
20
|
});
|
|
@@ -30,9 +31,9 @@ export const datePartShape = defineShape({
|
|
|
30
31
|
*/
|
|
31
32
|
year: 2023,
|
|
32
33
|
/** A month of the year: 1-12 */
|
|
33
|
-
month:
|
|
34
|
+
month: numericRange(monthNumberBounds.min, monthNumberBounds.max),
|
|
34
35
|
/** A day of the month: 1-31 depending on the month */
|
|
35
|
-
day:
|
|
36
|
+
day: numericRange(dayOfMonthBounds.min, dayOfMonthBounds.max),
|
|
36
37
|
/** The timezone that this date/time is meant for / originated from. */
|
|
37
38
|
timezone: utcTimezone,
|
|
38
39
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { omitObjectKeys } from '@augment-vir/common';
|
|
2
|
+
import { assertWrapDayOfMonth, assertWrapHour, assertWrapMillisecond, assertWrapMinute, assertWrapMonthNumber, assertWrapSecond, } from '@date-vir/duration';
|
|
2
3
|
import { DateTime } from 'luxon';
|
|
3
4
|
/**
|
|
4
5
|
* Converts a {@link FullDate} object into a Luxon DateTime library. This is only needed if you need
|
|
@@ -30,13 +31,13 @@ export function parseLuxonDateTime(dateTimeInput, forcedTimezone) {
|
|
|
30
31
|
throw new Error(`Invalid input: '${dateTimeInput.toISO()}'`);
|
|
31
32
|
}
|
|
32
33
|
return {
|
|
33
|
-
day: dateTimeInput.day,
|
|
34
|
-
month: dateTimeInput.month,
|
|
34
|
+
day: assertWrapDayOfMonth(dateTimeInput.day),
|
|
35
|
+
month: assertWrapMonthNumber(dateTimeInput.month),
|
|
35
36
|
year: dateTimeInput.year,
|
|
36
|
-
hour: dateTimeInput.hour,
|
|
37
|
-
minute: dateTimeInput.minute,
|
|
38
|
-
second: dateTimeInput.second,
|
|
39
|
-
millisecond: dateTimeInput.millisecond,
|
|
37
|
+
hour: assertWrapHour(dateTimeInput.hour),
|
|
38
|
+
minute: assertWrapMinute(dateTimeInput.minute),
|
|
39
|
+
second: assertWrapSecond(dateTimeInput.second),
|
|
40
|
+
millisecond: assertWrapMillisecond(dateTimeInput.millisecond),
|
|
40
41
|
timezone: forcedTimezone ?? dateTimeInput.zoneName,
|
|
41
42
|
};
|
|
42
43
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './date-operations/calculate-relative-date.js';
|
|
2
2
|
export * from './date-operations/combine-dates.js';
|
|
3
|
+
export * from './date-operations/date-position.js';
|
|
3
4
|
export * from './date-operations/diff-dates.js';
|
|
5
|
+
export * from './extra-utils/end.js';
|
|
4
6
|
export * from './extra-utils/has-date-props.js';
|
|
5
7
|
export * from './extra-utils/js-date-conversion.js';
|
|
6
8
|
export * from './extra-utils/now.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './date-operations/calculate-relative-date.js';
|
|
2
2
|
export * from './date-operations/combine-dates.js';
|
|
3
|
+
export * from './date-operations/date-position.js';
|
|
3
4
|
export * from './date-operations/diff-dates.js';
|
|
5
|
+
export * from './extra-utils/end.js';
|
|
4
6
|
export * from './extra-utils/has-date-props.js';
|
|
5
7
|
export * from './extra-utils/js-date-conversion.js';
|
|
6
8
|
export * from './extra-utils/now.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-vir",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.1",
|
|
4
4
|
"description": "Easy and explicit dates and times.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -34,25 +34,25 @@
|
|
|
34
34
|
"test:docs": "virmator docs check"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@augment-vir/assert": "^30.
|
|
38
|
-
"@augment-vir/common": "^30.
|
|
39
|
-
"@date-vir/duration": "^
|
|
37
|
+
"@augment-vir/assert": "^30.6.2",
|
|
38
|
+
"@augment-vir/common": "^30.6.2",
|
|
39
|
+
"@date-vir/duration": "^7.0.1",
|
|
40
40
|
"@types/luxon": "^3.4.2",
|
|
41
41
|
"luxon": "^3.5.0",
|
|
42
|
-
"object-shape-tester": "^3.
|
|
42
|
+
"object-shape-tester": "^3.1.0",
|
|
43
43
|
"type-fest": "^4.26.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@augment-vir/test": "^30.
|
|
47
|
-
"@web/dev-server-esbuild": "^1.0.
|
|
46
|
+
"@augment-vir/test": "^30.6.2",
|
|
47
|
+
"@web/dev-server-esbuild": "^1.0.3",
|
|
48
48
|
"@web/test-runner": "^0.19.0",
|
|
49
49
|
"@web/test-runner-commands": "^0.9.0",
|
|
50
50
|
"@web/test-runner-playwright": "^0.11.0",
|
|
51
51
|
"@web/test-runner-visual-regression": "^0.10.0",
|
|
52
|
-
"element-vir": "^
|
|
53
|
-
"istanbul-smart-text-reporter": "^1.1.
|
|
52
|
+
"element-vir": "^23.0.0",
|
|
53
|
+
"istanbul-smart-text-reporter": "^1.1.5",
|
|
54
54
|
"markdown-code-example-inserter": "^3.0.0",
|
|
55
|
-
"typedoc": "^0.26.
|
|
55
|
+
"typedoc": "^0.26.11"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|
|
58
58
|
"node": ">=22"
|