date-vir 0.9.0 → 1.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.
|
@@ -1,13 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.diffDates = void 0;
|
|
3
|
+
exports.isDateAfter = exports.diffDates = exports.DiffUnit = void 0;
|
|
4
4
|
const luxon_date_time_conversion_1 = require("../full-date/luxon-date-time-conversion");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Exclude the higher order units of time measure for diffing because they vary significantly,
|
|
7
|
+
* causing inaccuracies and many issues. See
|
|
8
|
+
* https://moment.github.io/luxon/#/math?id=casual-vs-longterm-conversion-accuracy for more info.
|
|
9
|
+
*
|
|
10
|
+
* If you REALLY want to use these higher order units, convert the dates to luxon objects with
|
|
11
|
+
* toLuxonDateTime and then run diff calculations there.
|
|
12
|
+
*/
|
|
13
|
+
var DiffUnit;
|
|
14
|
+
(function (DiffUnit) {
|
|
15
|
+
DiffUnit["Weeks"] = "weeks";
|
|
16
|
+
DiffUnit["Days"] = "days";
|
|
17
|
+
DiffUnit["Hours"] = "hours";
|
|
18
|
+
DiffUnit["Minutes"] = "minutes";
|
|
19
|
+
DiffUnit["Seconds"] = "seconds";
|
|
20
|
+
DiffUnit["Milliseconds"] = "milliseconds";
|
|
21
|
+
})(DiffUnit || (exports.DiffUnit = DiffUnit = {}));
|
|
22
|
+
function diffDates({ start, end, unit, }) {
|
|
23
|
+
const luxonDateStart = (0, luxon_date_time_conversion_1.toLuxonDateTime)(start);
|
|
24
|
+
const luxonDateEnd = (0, luxon_date_time_conversion_1.toLuxonDateTime)(end);
|
|
25
|
+
const diff = luxonDateEnd.diff(luxonDateStart, unit).toObject();
|
|
11
26
|
return diff;
|
|
12
27
|
}
|
|
13
28
|
exports.diffDates = diffDates;
|
|
29
|
+
function isDateAfter({ start, end }) {
|
|
30
|
+
return diffDates({ start, end, unit: DiffUnit.Milliseconds }).milliseconds >= 0;
|
|
31
|
+
}
|
|
32
|
+
exports.isDateAfter = isDateAfter;
|
|
@@ -10,7 +10,22 @@ export type MaybeTuple<T> = T | AtLeastTuple<T, 1>;
|
|
|
10
10
|
* If you REALLY want to use these higher order units, convert the dates to luxon objects with
|
|
11
11
|
* toLuxonDateTime and then run diff calculations there.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export declare enum DiffUnit {
|
|
14
|
+
Weeks = "weeks",
|
|
15
|
+
Days = "days",
|
|
16
|
+
Hours = "hours",
|
|
17
|
+
Minutes = "minutes",
|
|
18
|
+
Seconds = "seconds",
|
|
19
|
+
Milliseconds = "milliseconds"
|
|
20
|
+
}
|
|
14
21
|
export type DiffDuration<DurationKeys extends MaybeTuple<DiffUnit>> = MaybeTuple<DiffUnit> extends DurationKeys ? Pick<RelativeTimeDuration, DiffUnit> : Pick<RequiredAndNotNull<RelativeTimeDuration>, DurationKeys extends AtLeastTuple<infer InnerValue, 1> ? InnerValue : DurationKeys>;
|
|
15
22
|
export type Duration<DurationKeys extends MaybeTuple<DiffUnit>> = DiffDuration<DurationKeys>;
|
|
16
|
-
export declare function diffDates<const DurationKeys extends MaybeTuple<DiffUnit> = MaybeTuple<DiffUnit>>(
|
|
23
|
+
export declare function diffDates<const DurationKeys extends MaybeTuple<DiffUnit> = MaybeTuple<DiffUnit>>({ start, end, unit, }: {
|
|
24
|
+
start: FullDate;
|
|
25
|
+
end: FullDate;
|
|
26
|
+
unit: DurationKeys;
|
|
27
|
+
}): DiffDuration<DurationKeys>;
|
|
28
|
+
export declare function isDateAfter({ start, end }: {
|
|
29
|
+
start: FullDate;
|
|
30
|
+
end: FullDate;
|
|
31
|
+
}): boolean;
|
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
import { toLuxonDateTime } from '../full-date/luxon-date-time-conversion';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Exclude the higher order units of time measure for diffing because they vary significantly,
|
|
4
|
+
* causing inaccuracies and many issues. See
|
|
5
|
+
* https://moment.github.io/luxon/#/math?id=casual-vs-longterm-conversion-accuracy for more info.
|
|
6
|
+
*
|
|
7
|
+
* If you REALLY want to use these higher order units, convert the dates to luxon objects with
|
|
8
|
+
* toLuxonDateTime and then run diff calculations there.
|
|
9
|
+
*/
|
|
10
|
+
export var DiffUnit;
|
|
11
|
+
(function (DiffUnit) {
|
|
12
|
+
DiffUnit["Weeks"] = "weeks";
|
|
13
|
+
DiffUnit["Days"] = "days";
|
|
14
|
+
DiffUnit["Hours"] = "hours";
|
|
15
|
+
DiffUnit["Minutes"] = "minutes";
|
|
16
|
+
DiffUnit["Seconds"] = "seconds";
|
|
17
|
+
DiffUnit["Milliseconds"] = "milliseconds";
|
|
18
|
+
})(DiffUnit || (DiffUnit = {}));
|
|
19
|
+
export function diffDates({ start, end, unit, }) {
|
|
20
|
+
const luxonDateStart = toLuxonDateTime(start);
|
|
21
|
+
const luxonDateEnd = toLuxonDateTime(end);
|
|
22
|
+
const diff = luxonDateEnd.diff(luxonDateStart, unit).toObject();
|
|
8
23
|
return diff;
|
|
9
24
|
}
|
|
25
|
+
export function isDateAfter({ start, end }) {
|
|
26
|
+
return diffDates({ start, end, unit: DiffUnit.Milliseconds }).milliseconds >= 0;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-vir",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Easy and explicit dates and times",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -40,38 +40,38 @@
|
|
|
40
40
|
"test:watch": "web-test-runner --watch --color --config configs/web-test-runner.config.mjs"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@augment-vir/common": "^
|
|
44
|
-
"@types/luxon": "^3.3.
|
|
45
|
-
"luxon": "^3.4.
|
|
43
|
+
"@augment-vir/common": "^17.0.0",
|
|
44
|
+
"@types/luxon": "^3.3.2",
|
|
45
|
+
"luxon": "^3.4.3",
|
|
46
46
|
"object-shape-tester": "^0.4.2",
|
|
47
|
-
"type-fest": "^4.
|
|
47
|
+
"type-fest": "^4.3.1"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@augment-vir/browser": "^
|
|
51
|
-
"@augment-vir/browser-testing": "^
|
|
50
|
+
"@augment-vir/browser": "^17.0.0",
|
|
51
|
+
"@augment-vir/browser-testing": "^17.0.0",
|
|
52
52
|
"@open-wc/testing": "^3.2.0",
|
|
53
|
-
"@types/chai": "^4.3.
|
|
53
|
+
"@types/chai": "^4.3.6",
|
|
54
54
|
"@types/mocha": "^10.0.1",
|
|
55
55
|
"@web/dev-server-esbuild": "^0.4.1",
|
|
56
|
-
"@web/test-runner": "^0.17.
|
|
56
|
+
"@web/test-runner": "^0.17.1",
|
|
57
57
|
"@web/test-runner-commands": "^0.8.0",
|
|
58
58
|
"@web/test-runner-playwright": "^0.10.1",
|
|
59
59
|
"@web/test-runner-visual-regression": "^0.8.2",
|
|
60
|
-
"cspell": "^7.
|
|
60
|
+
"cspell": "^7.3.2",
|
|
61
61
|
"element-vir": "^16.3.1",
|
|
62
|
-
"esbuild": "^0.19.
|
|
62
|
+
"esbuild": "^0.19.2",
|
|
63
63
|
"istanbul-smart-text-reporter": "^1.1.2",
|
|
64
64
|
"markdown-code-example-inserter": "^0.3.1",
|
|
65
|
-
"npm-check-updates": "
|
|
65
|
+
"npm-check-updates": "~16.12.3",
|
|
66
66
|
"prettier": "^2.8.8",
|
|
67
67
|
"prettier-plugin-interpolated-html-tags": "^0.0.4",
|
|
68
68
|
"prettier-plugin-jsdoc": "^0.4.2",
|
|
69
69
|
"prettier-plugin-multiline-arrays": "^2.0.0",
|
|
70
70
|
"prettier-plugin-organize-imports": "^3.2.3",
|
|
71
71
|
"prettier-plugin-packagejson": "^2.4.5",
|
|
72
|
-
"prettier-plugin-sort-json": "^
|
|
72
|
+
"prettier-plugin-sort-json": "^2.0.0",
|
|
73
73
|
"prettier-plugin-toml": "^0.3.1",
|
|
74
|
-
"typescript": "^5.
|
|
75
|
-
"virmator": "^7.
|
|
74
|
+
"typescript": "^5.2.2",
|
|
75
|
+
"virmator": "^7.4.1"
|
|
76
76
|
}
|
|
77
77
|
}
|