date-vir 7.0.3 → 7.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.
|
@@ -98,12 +98,12 @@ export declare function clearTime<const SpecificTimezone extends Timezone>(input
|
|
|
98
98
|
* ```
|
|
99
99
|
*/
|
|
100
100
|
export declare function clearParts<const SpecificTimezone extends Timezone>(inputFullDate: Readonly<FullDate<SpecificTimezone>>, parts: ReadonlyArray<Exclude<keyof FullDate, 'timezone'>>): {
|
|
101
|
+
year: number;
|
|
102
|
+
month: import("@date-vir/duration").MonthNumber;
|
|
103
|
+
day: import("@date-vir/duration").DayOfMonth;
|
|
101
104
|
hour: import("@date-vir/duration").Hour;
|
|
102
105
|
minute: import("@date-vir/duration").Minute;
|
|
103
106
|
second: import("@date-vir/duration").Minute;
|
|
104
107
|
millisecond: number;
|
|
105
|
-
year: number;
|
|
106
|
-
month: import("@date-vir/duration").MonthNumber;
|
|
107
|
-
day: import("@date-vir/duration").DayOfMonth;
|
|
108
108
|
timezone: SpecificTimezone;
|
|
109
109
|
};
|
|
@@ -27,6 +27,21 @@ export type RelativeStringOptions = PartialWithUndefined<{
|
|
|
27
27
|
* @default 0
|
|
28
28
|
*/
|
|
29
29
|
allowedDecimals: number;
|
|
30
|
+
/**
|
|
31
|
+
* Any values below this will trigger "just now".
|
|
32
|
+
*
|
|
33
|
+
* @default {
|
|
34
|
+
*
|
|
35
|
+
* minutes: 1.5,
|
|
36
|
+
* seconds: 5,
|
|
37
|
+
* milliseconds: 500,
|
|
38
|
+
* }
|
|
39
|
+
*/
|
|
40
|
+
justNowThresholds: {
|
|
41
|
+
minutes: number;
|
|
42
|
+
seconds: number;
|
|
43
|
+
milliseconds: number;
|
|
44
|
+
};
|
|
30
45
|
}>;
|
|
31
46
|
/**
|
|
32
47
|
* This function starts with a duration (either by being directly passed a duration or by diffing
|
|
@@ -2,6 +2,11 @@ import { check } from '@augment-vir/assert';
|
|
|
2
2
|
import { arrayToObject, filterMap } from '@augment-vir/common';
|
|
3
3
|
import { DurationUnit, convertDuration, flattenUnitSelection, singularDurationUnitNames, } from '@date-vir/duration';
|
|
4
4
|
import { diffDates } from '../date-operations/diff-dates.js';
|
|
5
|
+
const defaultJustNowThresholds = {
|
|
6
|
+
minutes: 1.5,
|
|
7
|
+
seconds: 5,
|
|
8
|
+
milliseconds: 500,
|
|
9
|
+
};
|
|
5
10
|
/**
|
|
6
11
|
* This function starts with a duration (either by being directly passed a duration or by diffing
|
|
7
12
|
* two dates into a duration) and converts that duration into a relative string like "1 month ago"
|
|
@@ -41,15 +46,25 @@ export function toRelativeString(datesOrDuration, units, options = {}) {
|
|
|
41
46
|
unit,
|
|
42
47
|
};
|
|
43
48
|
}, check.isTruthy).reverse();
|
|
49
|
+
const justNowThresholds = options.justNowThresholds || defaultJustNowThresholds;
|
|
44
50
|
const shouldUseJustNow = !options.blockJustNow &&
|
|
45
51
|
(!check.isLengthAtLeast(unitValues, 1) ||
|
|
46
|
-
(unitValues[0].unit === DurationUnit.Minutes &&
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
(unitValues[0].unit === DurationUnit.Minutes &&
|
|
53
|
+
/* node:coverage ignore next 1 */
|
|
54
|
+
(diff.minutes || 0) < justNowThresholds.minutes) ||
|
|
55
|
+
(unitValues[0].unit === DurationUnit.Seconds &&
|
|
56
|
+
/* node:coverage ignore next 1 */
|
|
57
|
+
(diff.seconds || 0) < justNowThresholds.seconds) ||
|
|
58
|
+
(unitValues[0].unit === DurationUnit.Milliseconds &&
|
|
59
|
+
/* node:coverage ignore next 1 */
|
|
60
|
+
(diff.milliseconds || 0) < justNowThresholds.milliseconds));
|
|
49
61
|
if (shouldUseJustNow) {
|
|
50
62
|
return 'just now';
|
|
51
63
|
}
|
|
52
64
|
else if (options.useOnlyLargestUnit) {
|
|
65
|
+
if (!unitValues[0]) {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
53
68
|
return toRelativeString(datesOrDuration, { [unitValues[0].unit]: true }, {
|
|
54
69
|
...options,
|
|
55
70
|
useOnlyLargestUnit: false,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-vir",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Easy and explicit dates and times.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -29,29 +29,29 @@
|
|
|
29
29
|
"scripts": {
|
|
30
30
|
"compile": "virmator compile",
|
|
31
31
|
"docs": "virmator docs",
|
|
32
|
-
"test": "virmator test web",
|
|
32
|
+
"test": "NODE_OPTIONS=\"--import tsx\" virmator test web",
|
|
33
33
|
"test:coverage": "npm run test coverage",
|
|
34
34
|
"test:docs": "virmator docs check"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@augment-vir/assert": "^31.0
|
|
37
|
+
"@augment-vir/assert": "^31.1.0",
|
|
38
38
|
"@augment-vir/common": "^31.0.1",
|
|
39
|
-
"@date-vir/duration": "^7.0
|
|
39
|
+
"@date-vir/duration": "^7.1.0",
|
|
40
40
|
"@types/luxon": "^3.4.2",
|
|
41
41
|
"luxon": "^3.5.0",
|
|
42
42
|
"object-shape-tester": "^3.1.4",
|
|
43
43
|
"type-fest": "^4.30.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@augment-vir/test": "^31.0
|
|
46
|
+
"@augment-vir/test": "^31.1.0",
|
|
47
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": "^23.
|
|
52
|
+
"element-vir": "^23.1.0",
|
|
53
53
|
"istanbul-smart-text-reporter": "^1.1.5",
|
|
54
|
-
"markdown-code-example-inserter": "^3.0.
|
|
54
|
+
"markdown-code-example-inserter": "^3.0.3",
|
|
55
55
|
"typedoc": "^0.27.4"
|
|
56
56
|
},
|
|
57
57
|
"engines": {
|