date-vir 0.2.6 → 0.3.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.
- package/dist/cjs/{full-date → date-operations}/calculate-relative-date.js +1 -1
- package/dist/cjs/{full-date → date-operations}/combine-dates.js +1 -1
- package/dist/cjs/date-operations/diff-dates.js +13 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/relative-time-duration.js +2 -0
- package/dist/esm/date-operations/calculate-relative-date.d.ts +3 -0
- package/dist/esm/{full-date → date-operations}/calculate-relative-date.js +1 -1
- package/dist/esm/{full-date → date-operations}/combine-dates.d.ts +1 -1
- package/dist/esm/{full-date → date-operations}/combine-dates.js +1 -1
- package/dist/esm/date-operations/diff-dates.d.ts +15 -0
- package/dist/esm/date-operations/diff-dates.js +9 -0
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/relative-time-duration.d.ts +2 -0
- package/dist/esm/relative-time-duration.js +1 -0
- package/package.json +9 -8
- package/dist/esm/full-date/calculate-relative-date.d.ts +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateRelativeDate = void 0;
|
|
4
|
-
const luxon_date_time_conversion_1 = require("
|
|
4
|
+
const luxon_date_time_conversion_1 = require("../full-date/luxon-date-time-conversion");
|
|
5
5
|
function calculateRelativeDate(fullDate, relativeCalculation) {
|
|
6
6
|
return (0, luxon_date_time_conversion_1.parseLuxonDateTime)((0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).plus(relativeCalculation));
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.combineDateParts = void 0;
|
|
4
4
|
const object_shape_tester_1 = require("object-shape-tester");
|
|
5
|
-
const full_date_shape_1 = require("
|
|
5
|
+
const full_date_shape_1 = require("../full-date/full-date-shape");
|
|
6
6
|
function combineDateParts(maybeDateParts) {
|
|
7
7
|
const timePart = (0, object_shape_tester_1.isValidShape)(maybeDateParts.time, full_date_shape_1.timePartShape, {
|
|
8
8
|
allowExtraKeys: true,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.diffDates = void 0;
|
|
4
|
+
const luxon_date_time_conversion_1 = require("../full-date/luxon-date-time-conversion");
|
|
5
|
+
const primitive_conversions_1 = require("../full-date/primitive-conversions");
|
|
6
|
+
function diffDates(fullDateA, fullDateB, unit) {
|
|
7
|
+
const isALater = (0, primitive_conversions_1.toTimestamp)(fullDateA) > (0, primitive_conversions_1.toTimestamp)(fullDateB);
|
|
8
|
+
const luxonDateA = (0, luxon_date_time_conversion_1.toLuxonDateTime)(isALater ? fullDateA : fullDateB);
|
|
9
|
+
const luxonDateB = (0, luxon_date_time_conversion_1.toLuxonDateTime)(isALater ? fullDateB : fullDateA);
|
|
10
|
+
const diff = luxonDateA.diff(luxonDateB, unit).toObject();
|
|
11
|
+
return diff;
|
|
12
|
+
}
|
|
13
|
+
exports.diffDates = diffDates;
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
18
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./date-operations/calculate-relative-date"), exports);
|
|
18
|
+
__exportStar(require("./date-operations/combine-dates"), exports);
|
|
19
19
|
__exportStar(require("./full-date/create-full-date"), exports);
|
|
20
20
|
__exportStar(require("./full-date/date-like"), exports);
|
|
21
21
|
__exportStar(require("./full-date/format-presets"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseLuxonDateTime, toLuxonDateTime } from '
|
|
1
|
+
import { parseLuxonDateTime, toLuxonDateTime } from '../full-date/luxon-date-time-conversion';
|
|
2
2
|
export function calculateRelativeDate(fullDate, relativeCalculation) {
|
|
3
3
|
return parseLuxonDateTime(toLuxonDateTime(fullDate).plus(relativeCalculation));
|
|
4
4
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatePart, FullDate, FullDatePartEnum, TimePart } from '
|
|
1
|
+
import { DatePart, FullDate, FullDatePartEnum, TimePart } from '../full-date/full-date-shape';
|
|
2
2
|
type MaybeDateParts = Partial<{
|
|
3
3
|
[FullDatePartEnum.Date]: DatePart | undefined | Partial<FullDate>;
|
|
4
4
|
[FullDatePartEnum.Time]: TimePart | undefined | Partial<FullDate>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isValidShape } from 'object-shape-tester';
|
|
2
|
-
import { FullDatePartEnum, datePartShape, timePartShape, } from '
|
|
2
|
+
import { FullDatePartEnum, datePartShape, timePartShape, } from '../full-date/full-date-shape';
|
|
3
3
|
export function combineDateParts(maybeDateParts) {
|
|
4
4
|
const timePart = isValidShape(maybeDateParts.time, timePartShape, {
|
|
5
5
|
allowExtraKeys: true,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AtLeastTuple, RequiredAndNotNull } from '@augment-vir/common';
|
|
2
|
+
import { FullDate } from '../full-date/full-date-shape';
|
|
3
|
+
import { RelativeTimeDuration } from '../relative-time-duration';
|
|
4
|
+
export type MaybeTuple<T> = T | AtLeastTuple<T, 1>;
|
|
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
|
+
export type DiffUnit = Exclude<keyof RelativeTimeDuration, 'months' | 'years' | 'quarters'>;
|
|
14
|
+
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
|
+
export declare function diffDates<const DurationKeys extends MaybeTuple<DiffUnit> = MaybeTuple<DiffUnit>>(fullDateA: FullDate, fullDateB: FullDate, unit: DurationKeys): DiffDuration<DurationKeys>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { toLuxonDateTime } from '../full-date/luxon-date-time-conversion';
|
|
2
|
+
import { toTimestamp } from '../full-date/primitive-conversions';
|
|
3
|
+
export function diffDates(fullDateA, fullDateB, unit) {
|
|
4
|
+
const isALater = toTimestamp(fullDateA) > toTimestamp(fullDateB);
|
|
5
|
+
const luxonDateA = toLuxonDateTime(isALater ? fullDateA : fullDateB);
|
|
6
|
+
const luxonDateB = toLuxonDateTime(isALater ? fullDateB : fullDateA);
|
|
7
|
+
const diff = luxonDateA.diff(luxonDateB, unit).toObject();
|
|
8
|
+
return diff;
|
|
9
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './date-operations/calculate-relative-date';
|
|
2
|
+
export * from './date-operations/combine-dates';
|
|
3
3
|
export * from './full-date/create-full-date';
|
|
4
4
|
export * from './full-date/date-like';
|
|
5
5
|
export * from './full-date/format-presets';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './date-operations/calculate-relative-date';
|
|
2
|
+
export * from './date-operations/combine-dates';
|
|
3
3
|
export * from './full-date/create-full-date';
|
|
4
4
|
export * from './full-date/date-like';
|
|
5
5
|
export * from './full-date/format-presets';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-vir",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Easy and explicit dates and times",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -40,25 +40,26 @@
|
|
|
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": "^
|
|
43
|
+
"@augment-vir/common": "^15.0.0",
|
|
44
44
|
"@types/luxon": "^3.3.0",
|
|
45
45
|
"luxon": "^3.3.0",
|
|
46
46
|
"object-shape-tester": "^0.3.0",
|
|
47
|
-
"type-fest": "^3.
|
|
47
|
+
"type-fest": "^3.12.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@augment-vir/browser
|
|
51
|
-
"@
|
|
50
|
+
"@augment-vir/browser": "^15.0.0",
|
|
51
|
+
"@augment-vir/browser-testing": "^15.0.0",
|
|
52
|
+
"@open-wc/testing": "^3.2.0",
|
|
52
53
|
"@types/chai": "^4.3.5",
|
|
53
54
|
"@types/mocha": "^10.0.1",
|
|
54
55
|
"@web/dev-server-esbuild": "^0.4.1",
|
|
55
56
|
"@web/test-runner": "^0.16.1",
|
|
56
57
|
"@web/test-runner-commands": "^0.7.0",
|
|
57
|
-
"@web/test-runner-playwright": "^0.10.
|
|
58
|
+
"@web/test-runner-playwright": "^0.10.1",
|
|
58
59
|
"@web/test-runner-visual-regression": "^0.8.0",
|
|
59
60
|
"cspell": "^6.31.1",
|
|
60
61
|
"element-vir": "^13.0.4",
|
|
61
|
-
"esbuild": "^0.
|
|
62
|
+
"esbuild": "^0.18.3",
|
|
62
63
|
"istanbul-smart-text-reporter": "^1.1.2",
|
|
63
64
|
"markdown-code-example-inserter": "^0.3.1",
|
|
64
65
|
"npm-check-updates": "^16.10.12",
|
|
@@ -71,6 +72,6 @@
|
|
|
71
72
|
"prettier-plugin-sort-json": "^1.0.0",
|
|
72
73
|
"prettier-plugin-toml": "^0.3.1",
|
|
73
74
|
"typescript": "~5.0.4",
|
|
74
|
-
"virmator": "^6.6.
|
|
75
|
+
"virmator": "^6.6.4"
|
|
75
76
|
}
|
|
76
77
|
}
|