date-vir 8.1.1 → 8.2.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/combine-dates.js +2 -2
- package/dist/date-operations/date-position.js +10 -3
- package/dist/date-operations/diff-dates.js +3 -1
- package/dist/formatting/formatted-string.js +3 -1
- package/dist/formatting/relative-string.js +17 -5
- package/dist/full-date/create-full-date.js +3 -1
- package/dist/full-date/full-date-shape.js +24 -6
- package/dist/full-date/string-parsing.js +10 -2
- package/package.json +7 -7
|
@@ -73,7 +73,9 @@ export function getStartDate(date, unit) {
|
|
|
73
73
|
* day of the week.
|
|
74
74
|
*/
|
|
75
75
|
if (unit === DateUnit.Week) {
|
|
76
|
-
return calculateRelativeDate(createFullDate(toLuxonDateTime(calculateRelativeDate(date, {
|
|
76
|
+
return calculateRelativeDate(createFullDate(toLuxonDateTime(calculateRelativeDate(date, {
|
|
77
|
+
days: 1,
|
|
78
|
+
})).startOf(unit), date.timezone), {
|
|
77
79
|
days: -1,
|
|
78
80
|
});
|
|
79
81
|
}
|
|
@@ -113,7 +115,9 @@ export function getEndDate(date, unit) {
|
|
|
113
115
|
* day of the week.
|
|
114
116
|
*/
|
|
115
117
|
if (unit === DateUnit.Week) {
|
|
116
|
-
return calculateRelativeDate(createFullDate(toLuxonDateTime(calculateRelativeDate(date, {
|
|
118
|
+
return calculateRelativeDate(createFullDate(toLuxonDateTime(calculateRelativeDate(date, {
|
|
119
|
+
days: 1,
|
|
120
|
+
})).endOf(unit), date.timezone), {
|
|
117
121
|
days: -1,
|
|
118
122
|
});
|
|
119
123
|
}
|
|
@@ -211,7 +215,10 @@ export function calculateDatePosition(date, calculation) {
|
|
|
211
215
|
})
|
|
212
216
|
: start;
|
|
213
217
|
const diffUnit = `${calculation.get}s`;
|
|
214
|
-
const diff = diffDates({
|
|
218
|
+
const diff = diffDates({
|
|
219
|
+
start: startWithOffset,
|
|
220
|
+
end: date,
|
|
221
|
+
}, {
|
|
215
222
|
[diffUnit]: true,
|
|
216
223
|
});
|
|
217
224
|
const value = assertWrap.isDefined(diff[diffUnit]);
|
|
@@ -68,6 +68,8 @@ formatOptions) {
|
|
|
68
68
|
* ```
|
|
69
69
|
*/
|
|
70
70
|
export function toFormattedString(fullDate, format, localeOverride = userLocale) {
|
|
71
|
-
const formattedString = toLuxonDateTime(fullDate).toFormat(format, {
|
|
71
|
+
const formattedString = toLuxonDateTime(fullDate).toFormat(format, {
|
|
72
|
+
locale: localeOverride,
|
|
73
|
+
});
|
|
72
74
|
return fixChromiumSpace(formattedString);
|
|
73
75
|
}
|
|
@@ -62,7 +62,9 @@ units, options) {
|
|
|
62
62
|
largestToSmallestSelectedUnit,
|
|
63
63
|
});
|
|
64
64
|
const unitCounts = {};
|
|
65
|
-
const isDiffPositive = convertDuration(diff, {
|
|
65
|
+
const isDiffPositive = convertDuration(diff, {
|
|
66
|
+
milliseconds: true,
|
|
67
|
+
}).milliseconds >= 0;
|
|
66
68
|
largestToSmallestSelectedUnit.forEach((unit) => {
|
|
67
69
|
if (options.useOnlyLargestUnit && Object.keys(unitCounts).length) {
|
|
68
70
|
return;
|
|
@@ -72,7 +74,11 @@ units, options) {
|
|
|
72
74
|
unitCounts[unit] = unitCount;
|
|
73
75
|
}
|
|
74
76
|
});
|
|
75
|
-
const shouldUseJustNow = determineShouldUseJustNow({
|
|
77
|
+
const shouldUseJustNow = determineShouldUseJustNow({
|
|
78
|
+
options,
|
|
79
|
+
smallestSelectedUnit,
|
|
80
|
+
unitCounts,
|
|
81
|
+
});
|
|
76
82
|
const i18n = {
|
|
77
83
|
...defaultRelativeStringI18n,
|
|
78
84
|
...options.i18n,
|
|
@@ -122,10 +128,16 @@ units, options) {
|
|
|
122
128
|
}
|
|
123
129
|
function getRelativeStringDiff({ datesOrDuration, units, options, largestToSmallestSelectedUnit, }) {
|
|
124
130
|
if (options.useOnlyLargestUnit) {
|
|
125
|
-
return findLargestDiff({
|
|
131
|
+
return findLargestDiff({
|
|
132
|
+
datesOrDuration,
|
|
133
|
+
largestToSmallestSelectedUnit,
|
|
134
|
+
options,
|
|
135
|
+
});
|
|
126
136
|
}
|
|
127
137
|
else {
|
|
128
|
-
return createDiff(datesOrDuration, {
|
|
138
|
+
return createDiff(datesOrDuration, {
|
|
139
|
+
decimalCount: undefined,
|
|
140
|
+
}, units);
|
|
129
141
|
}
|
|
130
142
|
}
|
|
131
143
|
function createDiff(datesOrDuration, options, units) {
|
|
@@ -155,7 +167,7 @@ function determineShouldUseJustNow({ options, smallestSelectedUnit, unitCounts,
|
|
|
155
167
|
if (!(smallestSelectedUnit in thresholds) || Object.keys(unitCounts).length > 1) {
|
|
156
168
|
return false;
|
|
157
169
|
}
|
|
158
|
-
if (!Object.keys(unitCounts).length || smallestSelectedUnit in unitCounts) {
|
|
170
|
+
else if (!Object.keys(unitCounts).length || smallestSelectedUnit in unitCounts) {
|
|
159
171
|
/* node:coverage disable: these fallbacks aren't required at runtime but are required for type safety. */
|
|
160
172
|
/**
|
|
161
173
|
* We've already verify that `smallestSelectedUnit` is in `thresholds` so the `|| 0`
|
|
@@ -126,7 +126,9 @@ function convertDateLikeToLuxonDateTime(dateLike, timezone) {
|
|
|
126
126
|
return dateLike.setZone(timezone);
|
|
127
127
|
}
|
|
128
128
|
else if (check.isNumber(dateLike)) {
|
|
129
|
-
return DateTime.fromMillis(dateLike, {
|
|
129
|
+
return DateTime.fromMillis(dateLike, {
|
|
130
|
+
zone: utcTimezone,
|
|
131
|
+
}).setZone(timezone);
|
|
130
132
|
}
|
|
131
133
|
else if (check.isString(dateLike)) {
|
|
132
134
|
const parsedStringDate = parseDateString(dateLike, timezone);
|
|
@@ -8,13 +8,25 @@ import { Timezone, utcTimezone } from '../timezone/timezones.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export const timePartShape = defineShape({
|
|
10
10
|
/** Hour of the day in 24 time: 0-23 */
|
|
11
|
-
hour: rangeShape({
|
|
11
|
+
hour: rangeShape({
|
|
12
|
+
...hourBounds,
|
|
13
|
+
default: hourBounds.min,
|
|
14
|
+
}),
|
|
12
15
|
/** Minute of the hour: 0-59 */
|
|
13
|
-
minute: rangeShape({
|
|
16
|
+
minute: rangeShape({
|
|
17
|
+
...minuteBounds,
|
|
18
|
+
default: minuteBounds.min,
|
|
19
|
+
}),
|
|
14
20
|
/** Second of the minute: 0-59 */
|
|
15
|
-
second: rangeShape({
|
|
21
|
+
second: rangeShape({
|
|
22
|
+
...secondBounds,
|
|
23
|
+
default: secondBounds.min,
|
|
24
|
+
}),
|
|
16
25
|
/** Millisecond of the second: 0-999 */
|
|
17
|
-
millisecond: rangeShape({
|
|
26
|
+
millisecond: rangeShape({
|
|
27
|
+
...millisecondsBounds,
|
|
28
|
+
default: millisecondsBounds.min,
|
|
29
|
+
}),
|
|
18
30
|
/** The timezone that this date/time is meant for / originated from. */
|
|
19
31
|
timezone: enumShape(Timezone, utcTimezone),
|
|
20
32
|
});
|
|
@@ -31,9 +43,15 @@ export const datePartShape = defineShape({
|
|
|
31
43
|
*/
|
|
32
44
|
year: 2023,
|
|
33
45
|
/** A month of the year: 1-12 */
|
|
34
|
-
month: rangeShape({
|
|
46
|
+
month: rangeShape({
|
|
47
|
+
...monthNumberBounds,
|
|
48
|
+
default: monthNumberBounds.min,
|
|
49
|
+
}),
|
|
35
50
|
/** A day of the month: 1-31 depending on the month */
|
|
36
|
-
day: rangeShape({
|
|
51
|
+
day: rangeShape({
|
|
52
|
+
...dayOfMonthBounds,
|
|
53
|
+
default: dayOfMonthBounds.min,
|
|
54
|
+
}),
|
|
37
55
|
/** The timezone that this date/time is meant for / originated from. */
|
|
38
56
|
timezone: enumShape(Timezone, utcTimezone),
|
|
39
57
|
});
|
|
@@ -34,6 +34,10 @@ const knownStringFormats = [
|
|
|
34
34
|
// padded hour
|
|
35
35
|
// Sat, 01 Jun 2025 6:23:21 +0000
|
|
36
36
|
'ccc, d LLL y HH:mm:ss ZZZ',
|
|
37
|
+
// 3/11 | 3:01pm
|
|
38
|
+
"L/d '|' h:mma",
|
|
39
|
+
// 03/11 | 03:01pm
|
|
40
|
+
"LL/dd '|' hh:mma",
|
|
37
41
|
];
|
|
38
42
|
/**
|
|
39
43
|
* Tries extra known formats for parsing date strings, even those that browsers do not natively
|
|
@@ -42,13 +46,17 @@ const knownStringFormats = [
|
|
|
42
46
|
* @category Internal
|
|
43
47
|
*/
|
|
44
48
|
export function parseDateString(dateString, timezone) {
|
|
45
|
-
const isoAttempt = DateTime.fromISO(dateString, {
|
|
49
|
+
const isoAttempt = DateTime.fromISO(dateString, {
|
|
50
|
+
zone: timezone,
|
|
51
|
+
});
|
|
46
52
|
if (isoAttempt.isValid) {
|
|
47
53
|
return isoAttempt;
|
|
48
54
|
}
|
|
49
55
|
let finalizedDateTime;
|
|
50
56
|
knownStringFormats.some((format) => {
|
|
51
|
-
const dateTimeAttempt = DateTime.fromFormat(dateString.trim(), format, {
|
|
57
|
+
const dateTimeAttempt = DateTime.fromFormat(dateString.trim(), format, {
|
|
58
|
+
zone: timezone,
|
|
59
|
+
});
|
|
52
60
|
if (!dateTimeAttempt.isValid) {
|
|
53
61
|
return false;
|
|
54
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-vir",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.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": "^31.
|
|
38
|
-
"@augment-vir/common": "^31.
|
|
39
|
-
"@date-vir/duration": "^8.
|
|
37
|
+
"@augment-vir/assert": "^31.68.1",
|
|
38
|
+
"@augment-vir/common": "^31.68.1",
|
|
39
|
+
"@date-vir/duration": "^8.2.1",
|
|
40
40
|
"@types/luxon": "^3.7.1",
|
|
41
41
|
"luxon": "^3.7.2",
|
|
42
42
|
"object-shape-tester": "^6.11.0",
|
|
43
43
|
"type-fest": "^5.4.4"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@augment-vir/test": "^31.
|
|
46
|
+
"@augment-vir/test": "^31.68.1",
|
|
47
47
|
"@web/dev-server-esbuild": "^1.0.5",
|
|
48
48
|
"@web/test-runner": "^0.20.2",
|
|
49
49
|
"@web/test-runner-commands": "^0.9.0",
|
|
50
50
|
"@web/test-runner-playwright": "^0.11.1",
|
|
51
51
|
"@web/test-runner-visual-regression": "^0.10.0",
|
|
52
|
-
"element-vir": "^26.14.
|
|
52
|
+
"element-vir": "^26.14.6",
|
|
53
53
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
54
54
|
"markdown-code-example-inserter": "^3.0.3",
|
|
55
|
-
"typedoc": "^0.28.
|
|
55
|
+
"typedoc": "^0.28.17",
|
|
56
56
|
"typescript": "^5.9.3"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|