date-vir 6.0.1 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,149 @@
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. Only date units larger
120
+ * than a day are allowed.
121
+ *
122
+ * @category Calculation
123
+ * @example
124
+ *
125
+ * ```ts
126
+ * import {calculateDatePosition, DateUnit} from 'date-vir';
127
+ *
128
+ * calculateDatePosition(
129
+ * {
130
+ * day: 5,
131
+ * month: 4,
132
+ * year: 2020,
133
+ * },
134
+ * DateUnit.Month,
135
+ * );
136
+ * // result is 5
137
+ *
138
+ * calculateDatePosition(
139
+ * {
140
+ * day: 5,
141
+ * month: 4,
142
+ * year: 2020,
143
+ * },
144
+ * DateUnit.Week,
145
+ * );
146
+ * // result is
147
+ * ```
148
+ */
149
+ export declare function calculateDatePosition(date: Readonly<FullDate>, calculation: Readonly<DatePositionCalculation>): number;
@@ -0,0 +1,175 @@
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. Only date units larger
132
+ * than a day are allowed.
133
+ *
134
+ * @category Calculation
135
+ * @example
136
+ *
137
+ * ```ts
138
+ * import {calculateDatePosition, DateUnit} from 'date-vir';
139
+ *
140
+ * calculateDatePosition(
141
+ * {
142
+ * day: 5,
143
+ * month: 4,
144
+ * year: 2020,
145
+ * },
146
+ * DateUnit.Month,
147
+ * );
148
+ * // result is 5
149
+ *
150
+ * calculateDatePosition(
151
+ * {
152
+ * day: 5,
153
+ * month: 4,
154
+ * year: 2020,
155
+ * },
156
+ * DateUnit.Week,
157
+ * );
158
+ * // result is
159
+ * ```
160
+ */
161
+ export function calculateDatePosition(date, calculation) {
162
+ if (!isValidShape(calculation, datePositionCalculationShape)) {
163
+ throw new Error(`Invalid date position calculation for '${stringify(date)}': cannot get ${calculation.get} in ${calculation.in}.`);
164
+ }
165
+ const start = getStartDate(date, calculation.in);
166
+ const diffUnit = `${calculation.get}s`;
167
+ const diff = diffDates({ start, end: date }, { [diffUnit]: true });
168
+ const value = diff[diffUnit];
169
+ if (check.isIn(calculation.get, oneIndexedDateUnits)) {
170
+ return value + 1;
171
+ }
172
+ else {
173
+ return value;
174
+ }
175
+ }
@@ -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
+ };
@@ -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 const endTime = {
7
+ hour: 23,
8
+ minute: 59,
9
+ second: 59,
10
+ 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 Zero
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 Zero
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 Zero
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
- }, "hour" | "minute" | "second" | "millisecond">;
46
+ }, TimeKey>;
46
47
  /**
47
48
  * Clear the time parts of a {@link FullDate}, setting them all to `0`.
48
49
  *
49
- * @category Zero
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 Zero
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'>>): FullDate<SpecificTimezone>;
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
+ };
@@ -1,10 +1,10 @@
1
- import { pickObjectKeys, typedObjectFromEntries } from '@augment-vir/common';
2
- import { timeFullDateKeys } from '../full-date/full-date-parts.js';
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 Zero
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 Zero
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 Zero
28
+ * @category Constants
29
29
  */
30
- export const zeroTime = pickObjectKeys(zeroDate, timeFullDateKeys);
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 Zero
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, timeFullDateKeys);
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 Zero
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 const timeFullDateKeys: readonly ["hour", "minute", "second", "millisecond"];
31
- /**
32
- * {@link FullDate} keys used for telling time only.
33
- *
34
- * @category Internal
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 type DateFullDateKeys = ArrayElement<typeof dateFullDateKeys>;
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 const timeFullDateKeys = [
31
- 'hour',
32
- 'minute',
33
- 'second',
34
- 'millisecond',
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 const dateFullDateKeys = [
42
- 'year',
43
- 'month',
44
- 'day',
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: number;
12
+ hour: import("object-shape-tester").ShapeNumericRange<Hour>;
11
13
  /** Minute of the hour: 0-59 */
12
- minute: number;
14
+ minute: import("object-shape-tester").ShapeNumericRange<Minute>;
13
15
  /** Second of the minute: 0-59 */
14
- second: number;
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: number;
41
+ month: import("object-shape-tester").ShapeNumericRange<MonthNumber>;
40
42
  /** A day of the month: 1-31 depending on the month */
41
- day: number;
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: number;
66
+ month: import("object-shape-tester").ShapeNumericRange<MonthNumber>;
65
67
  /** A day of the month: 1-31 depending on the month */
66
- day: number;
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: number;
73
+ hour: import("object-shape-tester").ShapeNumericRange<Hour>;
72
74
  /** Minute of the hour: 0-59 */
73
- minute: number;
75
+ minute: import("object-shape-tester").ShapeNumericRange<Minute>;
74
76
  /** Second of the minute: 0-59 */
75
- second: number;
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 { and, defineShape } from 'object-shape-tester';
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: 14,
11
+ hour: numericRange(hourBounds.min, hourBounds.max),
11
12
  /** Minute of the hour: 0-59 */
12
- minute: 19,
13
+ minute: numericRange(minuteBounds.min, minuteBounds.max),
13
14
  /** Second of the minute: 0-59 */
14
- second: 7,
15
+ second: numericRange(secondBounds.min, secondBounds.max),
15
16
  /** Millisecond of the second: 0-999 */
16
- millisecond: 877,
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: 6,
34
+ month: numericRange(monthNumberBounds.min, monthNumberBounds.max),
34
35
  /** A day of the month: 1-31 depending on the month */
35
- day: 5,
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": "6.0.1",
3
+ "version": "7.0.0",
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.1.0",
38
- "@augment-vir/common": "^30.1.0",
39
- "@date-vir/duration": "^6.0.0",
37
+ "@augment-vir/assert": "^30.6.2",
38
+ "@augment-vir/common": "^30.6.2",
39
+ "@date-vir/duration": "^7.0.0",
40
40
  "@types/luxon": "^3.4.2",
41
41
  "luxon": "^3.5.0",
42
- "object-shape-tester": "^3.0.0",
42
+ "object-shape-tester": "^3.1.0",
43
43
  "type-fest": "^4.26.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@augment-vir/test": "^30.1.0",
47
- "@web/dev-server-esbuild": "^1.0.2",
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": "^22.2.2",
53
- "istanbul-smart-text-reporter": "^1.1.4",
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.7"
55
+ "typedoc": "^0.26.11"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=22"