date-vir 5.3.2 → 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.
- package/LICENSE-MIT +1 -1
- package/README.md +28 -28
- package/dist/date-operations/calculate-relative-date.d.ts +17 -0
- package/dist/{esm/date-operations → date-operations}/calculate-relative-date.js +10 -1
- package/dist/date-operations/combine-dates.d.ts +43 -0
- package/dist/{esm/date-operations → date-operations}/combine-dates.js +6 -4
- package/dist/date-operations/date-position.d.ts +149 -0
- package/dist/date-operations/date-position.js +175 -0
- package/dist/date-operations/diff-dates.d.ts +95 -0
- package/dist/date-operations/diff-dates.js +124 -0
- package/dist/extra-utils/end.d.ts +11 -0
- package/dist/extra-utils/end.js +11 -0
- package/dist/extra-utils/has-date-props.d.ts +35 -0
- package/dist/extra-utils/has-date-props.js +46 -0
- package/dist/extra-utils/js-date-conversion.d.ts +26 -0
- package/dist/extra-utils/js-date-conversion.js +28 -0
- package/dist/extra-utils/now.d.ts +56 -0
- package/dist/extra-utils/now.js +68 -0
- package/dist/extra-utils/override-date.d.ts +27 -0
- package/dist/extra-utils/override-date.js +27 -0
- package/dist/extra-utils/zero.d.ts +109 -0
- package/dist/extra-utils/zero.js +94 -0
- package/dist/formatting/formatted-string.d.ts +58 -0
- package/dist/formatting/formatted-string.js +73 -0
- package/dist/formatting/html-input.d.ts +30 -0
- package/dist/formatting/html-input.js +47 -0
- package/dist/formatting/relative-string.d.ts +53 -0
- package/dist/formatting/relative-string.js +93 -0
- package/dist/formatting/simple-strings.d.ts +187 -0
- package/dist/formatting/simple-strings.js +120 -0
- package/dist/formatting/string-format-types.d.ts +59 -0
- package/dist/formatting/string-format-types.js +19 -0
- package/dist/formatting/timestamp.d.ts +51 -0
- package/dist/formatting/timestamp.js +61 -0
- package/dist/full-date/create-full-date.d.ts +91 -0
- package/dist/full-date/create-full-date.js +142 -0
- package/dist/full-date/date-like.d.ts +9 -0
- package/dist/{esm/full-date → full-date}/format-presets.d.ts +4 -2
- package/dist/{esm/full-date → full-date}/format-presets.js +4 -2
- package/dist/full-date/full-date-parts.d.ts +44 -0
- package/dist/full-date/full-date-parts.js +47 -0
- package/dist/full-date/full-date-shape.d.ts +108 -0
- package/dist/full-date/full-date-shape.js +45 -0
- package/dist/full-date/is-valid-full-date.d.ts +21 -0
- package/dist/full-date/is-valid-full-date.js +38 -0
- package/dist/full-date/luxon-date-time-conversion.d.ts +19 -0
- package/dist/full-date/luxon-date-time-conversion.js +43 -0
- package/dist/full-date/parsing.d.ts +33 -0
- package/dist/full-date/parsing.js +47 -0
- package/dist/full-date/string-parsing.d.ts +9 -0
- package/dist/{esm/full-date → full-date}/string-parsing.js +6 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +29 -0
- package/dist/locales.d.ts +6 -0
- package/dist/locales.js +7 -0
- package/dist/timezone/timezone-checks.d.ts +21 -0
- package/dist/timezone/timezone-checks.js +34 -0
- package/dist/{esm/timezone → timezone}/timezone-names.d.ts +11 -5
- package/dist/{esm/timezone → timezone}/timezone-names.js +11 -3
- package/dist/timezone/timezones.d.ts +42 -0
- package/dist/timezone/timezones.js +31 -0
- package/package.json +33 -51
- package/cspell.config.cjs +0 -13
- package/dist/cjs/date-operations/calculate-relative-date.js +0 -12
- package/dist/cjs/date-operations/combine-dates.js +0 -50
- package/dist/cjs/date-operations/diff-dates.js +0 -105
- package/dist/cjs/duration/duration-unit.js +0 -41
- package/dist/cjs/duration/duration-utils.js +0 -42
- package/dist/cjs/duration/duration.js +0 -2
- package/dist/cjs/extra-utils/date-transforms.js +0 -8
- package/dist/cjs/extra-utils/has-date-props.js +0 -25
- package/dist/cjs/extra-utils/js-date-conversion.js +0 -8
- package/dist/cjs/extra-utils/now.js +0 -22
- package/dist/cjs/extra-utils/zero.js +0 -31
- package/dist/cjs/formatting/formatted-string.js +0 -34
- package/dist/cjs/formatting/html-input.js +0 -37
- package/dist/cjs/formatting/relative-string.js +0 -77
- package/dist/cjs/formatting/simple-strings.js +0 -58
- package/dist/cjs/formatting/string-format-types.js +0 -9
- package/dist/cjs/formatting/timestamp.js +0 -21
- package/dist/cjs/full-date/create-full-date.js +0 -81
- package/dist/cjs/full-date/date-like.js +0 -2
- package/dist/cjs/full-date/format-presets.js +0 -32
- package/dist/cjs/full-date/full-date-shape.js +0 -54
- package/dist/cjs/full-date/is-valid-full-date.js +0 -28
- package/dist/cjs/full-date/luxon-date-time-conversion.js +0 -43
- package/dist/cjs/full-date/parsing.js +0 -48
- package/dist/cjs/full-date/string-parsing.js +0 -33
- package/dist/cjs/index.js +0 -44
- package/dist/cjs/locales.js +0 -5
- package/dist/cjs/timezone/timezone-checks.js +0 -34
- package/dist/cjs/timezone/timezone-names.js +0 -479
- package/dist/cjs/timezone/timezones.js +0 -14
- package/dist/esm/date-operations/calculate-relative-date.d.ts +0 -8
- package/dist/esm/date-operations/combine-dates.d.ts +0 -35
- package/dist/esm/date-operations/diff-dates.d.ts +0 -66
- package/dist/esm/date-operations/diff-dates.js +0 -100
- package/dist/esm/duration/duration-unit.d.ts +0 -27
- package/dist/esm/duration/duration-unit.js +0 -38
- package/dist/esm/duration/duration-utils.d.ts +0 -11
- package/dist/esm/duration/duration-utils.js +0 -37
- package/dist/esm/duration/duration.d.ts +0 -32
- package/dist/esm/duration/duration.js +0 -1
- package/dist/esm/extra-utils/date-transforms.d.ts +0 -4
- package/dist/esm/extra-utils/date-transforms.js +0 -4
- package/dist/esm/extra-utils/has-date-props.d.ts +0 -9
- package/dist/esm/extra-utils/has-date-props.js +0 -20
- package/dist/esm/extra-utils/js-date-conversion.d.ts +0 -2
- package/dist/esm/extra-utils/js-date-conversion.js +0 -4
- package/dist/esm/extra-utils/now.d.ts +0 -6
- package/dist/esm/extra-utils/now.js +0 -16
- package/dist/esm/extra-utils/zero.d.ts +0 -31
- package/dist/esm/extra-utils/zero.js +0 -26
- package/dist/esm/formatting/formatted-string.d.ts +0 -14
- package/dist/esm/formatting/formatted-string.js +0 -29
- package/dist/esm/formatting/html-input.d.ts +0 -19
- package/dist/esm/formatting/html-input.js +0 -33
- package/dist/esm/formatting/relative-string.d.ts +0 -31
- package/dist/esm/formatting/relative-string.js +0 -73
- package/dist/esm/formatting/simple-strings.d.ts +0 -71
- package/dist/esm/formatting/simple-strings.js +0 -51
- package/dist/esm/formatting/string-format-types.d.ts +0 -7
- package/dist/esm/formatting/string-format-types.js +0 -5
- package/dist/esm/formatting/timestamp.d.ts +0 -6
- package/dist/esm/formatting/timestamp.js +0 -16
- package/dist/esm/full-date/create-full-date.d.ts +0 -21
- package/dist/esm/full-date/create-full-date.js +0 -73
- package/dist/esm/full-date/date-like.d.ts +0 -5
- package/dist/esm/full-date/full-date-shape.d.ts +0 -80
- package/dist/esm/full-date/full-date-shape.js +0 -51
- package/dist/esm/full-date/is-valid-full-date.d.ts +0 -5
- package/dist/esm/full-date/is-valid-full-date.js +0 -22
- package/dist/esm/full-date/luxon-date-time-conversion.d.ts +0 -15
- package/dist/esm/full-date/luxon-date-time-conversion.js +0 -38
- package/dist/esm/full-date/parsing.d.ts +0 -27
- package/dist/esm/full-date/parsing.js +0 -43
- package/dist/esm/full-date/string-parsing.d.ts +0 -3
- package/dist/esm/index.d.ts +0 -28
- package/dist/esm/index.js +0 -28
- package/dist/esm/locales.d.ts +0 -1
- package/dist/esm/locales.js +0 -2
- package/dist/esm/timezone/timezone-checks.d.ts +0 -17
- package/dist/esm/timezone/timezone-checks.js +0 -29
- package/dist/esm/timezone/timezones.d.ts +0 -480
- package/dist/esm/timezone/timezones.js +0 -11
- package/public/index.css +0 -7
- /package/dist/{esm/full-date → full-date}/date-like.js +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable sonarjs/no-redeclare */
|
|
2
|
+
import { Settings } from 'luxon';
|
|
3
|
+
import { allTimezoneNames } from './timezone-names.js';
|
|
4
|
+
/**
|
|
5
|
+
* An enum of all possible timezone names.
|
|
6
|
+
*
|
|
7
|
+
* @category Timezone
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {Timezone} from 'date-vir';
|
|
12
|
+
*
|
|
13
|
+
* Timezone['Africa/Bamako'];
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const Timezone = allTimezoneNames.reduce((accum, timezoneName) => {
|
|
17
|
+
accum[timezoneName] = timezoneName;
|
|
18
|
+
return accum;
|
|
19
|
+
}, {});
|
|
20
|
+
/**
|
|
21
|
+
* The timezone of the current user's environment.
|
|
22
|
+
*
|
|
23
|
+
* @category Timezone
|
|
24
|
+
*/
|
|
25
|
+
export const userTimezone = Settings.defaultZone.name;
|
|
26
|
+
/**
|
|
27
|
+
* The UTC timezone.
|
|
28
|
+
*
|
|
29
|
+
* @category Timezone
|
|
30
|
+
*/
|
|
31
|
+
export const utcTimezone = Timezone.UTC;
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "date-vir",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Easy and explicit dates and times",
|
|
3
|
+
"version": "7.0.0",
|
|
4
|
+
"description": "Easy and explicit dates and times.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
7
|
+
"duration",
|
|
7
8
|
"time",
|
|
9
|
+
"util",
|
|
8
10
|
"vir"
|
|
9
11
|
],
|
|
10
12
|
"homepage": "https://github.com/electrovir/date-vir",
|
|
@@ -13,69 +15,49 @@
|
|
|
13
15
|
},
|
|
14
16
|
"repository": {
|
|
15
17
|
"type": "git",
|
|
16
|
-
"url": "https://github.com/electrovir/date-vir"
|
|
18
|
+
"url": "git+https://github.com/electrovir/date-vir.git"
|
|
17
19
|
},
|
|
18
20
|
"license": "(MIT or CC0 1.0)",
|
|
19
21
|
"author": {
|
|
20
22
|
"name": "electrovir",
|
|
21
23
|
"url": "https://github.com/electrovir"
|
|
22
24
|
},
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "dist/index.js",
|
|
27
|
+
"module": "dist/index.js",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
26
29
|
"scripts": {
|
|
27
|
-
"compile": "
|
|
28
|
-
"docs": "virmator docs
|
|
29
|
-
"
|
|
30
|
-
"publish": "virmator publish \"npm run compile && npm run test:all\"",
|
|
31
|
-
"start": "npm install && virmator frontend",
|
|
32
|
-
"test": "virmator test-web",
|
|
33
|
-
"test:all": "concurrently --colors --kill-others-on-fail -c auto --names types,tests,spelling,format,docs,deps \"npm run test:types\" \"npm run test:coverage\" \"npm run test:spelling\" \"npm run test:format\" \"npm run test:docs\" \"npm run test:deps\"",
|
|
30
|
+
"compile": "virmator compile",
|
|
31
|
+
"docs": "virmator docs",
|
|
32
|
+
"test": "virmator test web",
|
|
34
33
|
"test:coverage": "npm run test coverage",
|
|
35
|
-
"test:
|
|
36
|
-
"test:deps": "virmator deps check",
|
|
37
|
-
"test:docs": "virmator docs check --index src/index.ts README.md",
|
|
38
|
-
"test:format": "virmator format check",
|
|
39
|
-
"test:spelling": "virmator spellcheck",
|
|
40
|
-
"test:types": "tsc --noEmit",
|
|
41
|
-
"test:watch": "web-test-runner --watch --color --config configs/web-test-runner.config.mjs"
|
|
34
|
+
"test:docs": "virmator docs check"
|
|
42
35
|
},
|
|
43
36
|
"dependencies": {
|
|
44
|
-
"@augment-vir/
|
|
37
|
+
"@augment-vir/assert": "^30.6.2",
|
|
38
|
+
"@augment-vir/common": "^30.6.2",
|
|
39
|
+
"@date-vir/duration": "^7.0.0",
|
|
45
40
|
"@types/luxon": "^3.4.2",
|
|
46
|
-
"luxon": "^3.
|
|
47
|
-
"object-shape-tester": "^
|
|
48
|
-
"type-fest": "^4.
|
|
41
|
+
"luxon": "^3.5.0",
|
|
42
|
+
"object-shape-tester": "^3.1.0",
|
|
43
|
+
"type-fest": "^4.26.1"
|
|
49
44
|
},
|
|
50
45
|
"devDependencies": {
|
|
51
|
-
"@augment-vir/
|
|
52
|
-
"@
|
|
53
|
-
"@
|
|
54
|
-
"@types/chai": "^4.3.16",
|
|
55
|
-
"@types/mocha": "^10.0.6",
|
|
56
|
-
"@web/dev-server-esbuild": "^1.0.2",
|
|
57
|
-
"@web/test-runner": "^0.18.2",
|
|
46
|
+
"@augment-vir/test": "^30.6.2",
|
|
47
|
+
"@web/dev-server-esbuild": "^1.0.3",
|
|
48
|
+
"@web/test-runner": "^0.19.0",
|
|
58
49
|
"@web/test-runner-commands": "^0.9.0",
|
|
59
50
|
"@web/test-runner-playwright": "^0.11.0",
|
|
60
|
-
"@web/test-runner-visual-regression": "^0.
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
"prettier-plugin-multiline-arrays": "^3.0.6",
|
|
72
|
-
"prettier-plugin-organize-imports": "^3.2.4",
|
|
73
|
-
"prettier-plugin-packagejson": "^2.5.0",
|
|
74
|
-
"prettier-plugin-sort-json": "^4.0.0",
|
|
75
|
-
"prettier-plugin-toml": "^2.0.1",
|
|
76
|
-
"run-time-assertions": "^1.5.1",
|
|
77
|
-
"typedoc": "^0.25.13",
|
|
78
|
-
"typescript": "^5.4.5",
|
|
79
|
-
"virmator": "^11.5.2"
|
|
51
|
+
"@web/test-runner-visual-regression": "^0.10.0",
|
|
52
|
+
"element-vir": "^23.0.0",
|
|
53
|
+
"istanbul-smart-text-reporter": "^1.1.5",
|
|
54
|
+
"markdown-code-example-inserter": "^3.0.0",
|
|
55
|
+
"typedoc": "^0.26.11"
|
|
56
|
+
},
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=22"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
80
62
|
}
|
|
81
63
|
}
|
package/cspell.config.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateRelativeDate = void 0;
|
|
4
|
-
const luxon_date_time_conversion_1 = require("../full-date/luxon-date-time-conversion");
|
|
5
|
-
/**
|
|
6
|
-
* Calculates a new date starting at the given fullDate and adding the given offsets. Offsets can be
|
|
7
|
-
* negative to go backwards in time.
|
|
8
|
-
*/
|
|
9
|
-
function calculateRelativeDate(fullDate, offset) {
|
|
10
|
-
return (0, luxon_date_time_conversion_1.parseLuxonDateTime)((0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).plus(offset));
|
|
11
|
-
}
|
|
12
|
-
exports.calculateRelativeDate = calculateRelativeDate;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.combineDateParts = void 0;
|
|
4
|
-
const object_shape_tester_1 = require("object-shape-tester");
|
|
5
|
-
const full_date_shape_1 = require("../full-date/full-date-shape");
|
|
6
|
-
/**
|
|
7
|
-
* Combine two parts of a FullDate objects into a filled-in FullDate. Note that the timezones must
|
|
8
|
-
* match for both inputs. If two complete FullDate objects are passed in, only the respective parts
|
|
9
|
-
* of each is used.
|
|
10
|
-
*/
|
|
11
|
-
function combineDateParts(maybeDateParts) {
|
|
12
|
-
const timePart = (0, object_shape_tester_1.isValidShape)(maybeDateParts.time, full_date_shape_1.timePartShape, {
|
|
13
|
-
allowExtraKeys: true,
|
|
14
|
-
})
|
|
15
|
-
? {
|
|
16
|
-
hour: maybeDateParts.time.hour,
|
|
17
|
-
minute: maybeDateParts.time.minute,
|
|
18
|
-
second: maybeDateParts.time.second,
|
|
19
|
-
millisecond: maybeDateParts.time.millisecond,
|
|
20
|
-
timezone: maybeDateParts.time.timezone,
|
|
21
|
-
}
|
|
22
|
-
: undefined;
|
|
23
|
-
const datePart = (0, object_shape_tester_1.isValidShape)(maybeDateParts.date, full_date_shape_1.datePartShape, {
|
|
24
|
-
allowExtraKeys: true,
|
|
25
|
-
})
|
|
26
|
-
? {
|
|
27
|
-
year: maybeDateParts.date.year,
|
|
28
|
-
month: maybeDateParts.date.month,
|
|
29
|
-
day: maybeDateParts.date.day,
|
|
30
|
-
timezone: maybeDateParts.date.timezone,
|
|
31
|
-
}
|
|
32
|
-
: undefined;
|
|
33
|
-
if (timePart && datePart) {
|
|
34
|
-
if (timePart.timezone !== datePart.timezone) {
|
|
35
|
-
throw new Error(`Time and date parts have mismatching timezones. Got '${timePart.timezone}' and '${datePart.timezone}'.`);
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
...timePart,
|
|
39
|
-
...datePart,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
if (timePart) {
|
|
43
|
-
return timePart;
|
|
44
|
-
}
|
|
45
|
-
if (datePart) {
|
|
46
|
-
return datePart;
|
|
47
|
-
}
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
exports.combineDateParts = combineDateParts;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isDateAfter = exports.diffDates = exports.DiffType = void 0;
|
|
4
|
-
const common_1 = require("@augment-vir/common");
|
|
5
|
-
const duration_unit_1 = require("../duration/duration-unit");
|
|
6
|
-
const duration_utils_1 = require("../duration/duration-utils");
|
|
7
|
-
const luxon_date_time_conversion_1 = require("../full-date/luxon-date-time-conversion");
|
|
8
|
-
const accuracyPriority = {
|
|
9
|
-
longterm: 1,
|
|
10
|
-
casual: 0,
|
|
11
|
-
};
|
|
12
|
-
const conversionAccuracies = {
|
|
13
|
-
[duration_unit_1.DurationUnit.Years]: 'longterm',
|
|
14
|
-
[duration_unit_1.DurationUnit.Quarters]: 'longterm',
|
|
15
|
-
[duration_unit_1.DurationUnit.Months]: 'longterm',
|
|
16
|
-
[duration_unit_1.DurationUnit.Weeks]: 'casual',
|
|
17
|
-
[duration_unit_1.DurationUnit.Days]: 'casual',
|
|
18
|
-
[duration_unit_1.DurationUnit.Hours]: 'casual',
|
|
19
|
-
[duration_unit_1.DurationUnit.Minutes]: 'casual',
|
|
20
|
-
[duration_unit_1.DurationUnit.Seconds]: 'casual',
|
|
21
|
-
[duration_unit_1.DurationUnit.Milliseconds]: 'casual',
|
|
22
|
-
};
|
|
23
|
-
function getHighestPriorityConversionAccuracy(units) {
|
|
24
|
-
const currentConversionAccuracies = units.map((unit) => conversionAccuracies[unit]);
|
|
25
|
-
const highestPriorityAccuracy = currentConversionAccuracies.reduce((priorityAccuracy, currentAccuracy) => {
|
|
26
|
-
if (accuracyPriority[currentAccuracy] > accuracyPriority[priorityAccuracy]) {
|
|
27
|
-
return currentAccuracy;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return priorityAccuracy;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
return highestPriorityAccuracy;
|
|
34
|
-
}
|
|
35
|
-
var DiffType;
|
|
36
|
-
(function (DiffType) {
|
|
37
|
-
/**
|
|
38
|
-
* Causes the diffDates function to output the diff split between each unit provided. To get the
|
|
39
|
-
* full duration, each output unit needs to be added together.
|
|
40
|
-
*/
|
|
41
|
-
DiffType["AdditiveUnits"] = "additive-units";
|
|
42
|
-
/**
|
|
43
|
-
* Causes the diffDates function to output the diff in each unit provided with each unit being
|
|
44
|
-
* equivalent in value. Meaning, each unit will be the same duration of time converted into that
|
|
45
|
-
* unit.
|
|
46
|
-
*/
|
|
47
|
-
DiffType["EquivalentUnits"] = "equivalent-units";
|
|
48
|
-
})(DiffType || (exports.DiffType = DiffType = {}));
|
|
49
|
-
function diffDates({ start, end, units: unitsInput, unit: unitInput, diffType: diffTypeInput, decimalCount, }) {
|
|
50
|
-
const luxonDateStart = (0, luxon_date_time_conversion_1.toLuxonDateTime)(start);
|
|
51
|
-
const luxonDateEnd = (0, luxon_date_time_conversion_1.toLuxonDateTime)(end);
|
|
52
|
-
const units = (unitsInput ?? [unitInput]);
|
|
53
|
-
const diffType = units.length === 1
|
|
54
|
-
? /**
|
|
55
|
-
* When only one unit is provided, it doesn't matter which diff type we use so lets just use this
|
|
56
|
-
* one.
|
|
57
|
-
*/
|
|
58
|
-
DiffType.EquivalentUnits
|
|
59
|
-
: diffTypeInput;
|
|
60
|
-
if (!diffType) {
|
|
61
|
-
throw new Error('Failed to diff dates: no diffType was provided.');
|
|
62
|
-
}
|
|
63
|
-
if (diffType === DiffType.AdditiveUnits) {
|
|
64
|
-
const conversionAccuracy = getHighestPriorityConversionAccuracy(units);
|
|
65
|
-
const additiveDiff = luxonDateEnd
|
|
66
|
-
.diff(luxonDateStart, (0, common_1.makeWritable)(units), {
|
|
67
|
-
conversionAccuracy,
|
|
68
|
-
})
|
|
69
|
-
.toObject();
|
|
70
|
-
return (0, duration_utils_1.roundDuration)(additiveDiff, decimalCount);
|
|
71
|
-
}
|
|
72
|
-
else if (diffType === DiffType.EquivalentUnits) {
|
|
73
|
-
const allUnitDiffEntries = units.map((durationUnit) => {
|
|
74
|
-
const diff = luxonDateEnd
|
|
75
|
-
.diff(luxonDateStart, durationUnit, {
|
|
76
|
-
conversionAccuracy: conversionAccuracies[durationUnit],
|
|
77
|
-
})
|
|
78
|
-
.toObject();
|
|
79
|
-
const duration = diff[durationUnit];
|
|
80
|
-
/** Ignore this edge case in coverage cause its for type guarding. */
|
|
81
|
-
/* c8 ignore next 5 */
|
|
82
|
-
if (duration == undefined) {
|
|
83
|
-
throw new Error(`Internal date-vir error: failed to find duration for '${durationUnit}'`);
|
|
84
|
-
}
|
|
85
|
-
return [
|
|
86
|
-
durationUnit,
|
|
87
|
-
duration,
|
|
88
|
-
];
|
|
89
|
-
});
|
|
90
|
-
const equivalentDiff = (0, common_1.typedObjectFromEntries)(allUnitDiffEntries);
|
|
91
|
-
return (0, duration_utils_1.roundDuration)(equivalentDiff, decimalCount);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
throw new Error(`Failed to diff dates: provided diffType is invalid: '${diffType}'`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
exports.diffDates = diffDates;
|
|
98
|
-
function isDateAfter({ relativeTo, fullDate, }) {
|
|
99
|
-
return (diffDates({
|
|
100
|
-
start: relativeTo,
|
|
101
|
-
end: fullDate,
|
|
102
|
-
unit: duration_unit_1.DurationUnit.Milliseconds,
|
|
103
|
-
}).milliseconds >= 0);
|
|
104
|
-
}
|
|
105
|
-
exports.isDateAfter = isDateAfter;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.orderedDurationUnits = exports.singularDurationUnitNames = exports.DurationUnit = void 0;
|
|
4
|
-
var DurationUnit;
|
|
5
|
-
(function (DurationUnit) {
|
|
6
|
-
DurationUnit["Years"] = "years";
|
|
7
|
-
DurationUnit["Quarters"] = "quarters";
|
|
8
|
-
DurationUnit["Months"] = "months";
|
|
9
|
-
DurationUnit["Weeks"] = "weeks";
|
|
10
|
-
DurationUnit["Days"] = "days";
|
|
11
|
-
DurationUnit["Hours"] = "hours";
|
|
12
|
-
DurationUnit["Minutes"] = "minutes";
|
|
13
|
-
DurationUnit["Seconds"] = "seconds";
|
|
14
|
-
DurationUnit["Milliseconds"] = "milliseconds";
|
|
15
|
-
})(DurationUnit || (exports.DurationUnit = DurationUnit = {}));
|
|
16
|
-
exports.singularDurationUnitNames = {
|
|
17
|
-
[DurationUnit.Milliseconds]: 'millisecond',
|
|
18
|
-
[DurationUnit.Seconds]: 'second',
|
|
19
|
-
[DurationUnit.Minutes]: 'minute',
|
|
20
|
-
[DurationUnit.Hours]: 'hour',
|
|
21
|
-
[DurationUnit.Days]: 'day',
|
|
22
|
-
[DurationUnit.Weeks]: 'week',
|
|
23
|
-
[DurationUnit.Months]: 'month',
|
|
24
|
-
[DurationUnit.Quarters]: 'quarter',
|
|
25
|
-
[DurationUnit.Years]: 'year',
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Array of DurationUnit values: from smallest unit (milliseconds at index 0) to longest unit
|
|
29
|
-
* (years).
|
|
30
|
-
*/
|
|
31
|
-
exports.orderedDurationUnits = [
|
|
32
|
-
DurationUnit.Milliseconds,
|
|
33
|
-
DurationUnit.Seconds,
|
|
34
|
-
DurationUnit.Minutes,
|
|
35
|
-
DurationUnit.Hours,
|
|
36
|
-
DurationUnit.Days,
|
|
37
|
-
DurationUnit.Weeks,
|
|
38
|
-
DurationUnit.Months,
|
|
39
|
-
DurationUnit.Quarters,
|
|
40
|
-
DurationUnit.Years,
|
|
41
|
-
];
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertDuration = exports.roundDuration = void 0;
|
|
4
|
-
const common_1 = require("@augment-vir/common");
|
|
5
|
-
const luxon_1 = require("luxon");
|
|
6
|
-
const run_time_assertions_1 = require("run-time-assertions");
|
|
7
|
-
/** Round every unit in a given duration to the given number of decimal points. */
|
|
8
|
-
function roundDuration(duration,
|
|
9
|
-
/**
|
|
10
|
-
* How many decimals to round to. Leave undefined to skip rounding. (Though if you skip
|
|
11
|
-
* rounding, why are you using this function?)
|
|
12
|
-
*/
|
|
13
|
-
decimalCount) {
|
|
14
|
-
return (0, common_1.mapObjectValues)(duration, (key, value) => {
|
|
15
|
-
if (decimalCount == undefined || !(0, run_time_assertions_1.isRunTimeType)(value, 'number')) {
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
return (0, common_1.round)({ number: value, digits: decimalCount });
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.roundDuration = roundDuration;
|
|
24
|
-
/** Convert a duration from any combination of units into a single unit. */
|
|
25
|
-
function convertDuration(inputDuration, requiredUnit) {
|
|
26
|
-
if (hasInfinity(inputDuration)) {
|
|
27
|
-
return { [requiredUnit]: Infinity };
|
|
28
|
-
}
|
|
29
|
-
else if (hasNegativeInfinity(inputDuration)) {
|
|
30
|
-
return { [requiredUnit]: -Infinity };
|
|
31
|
-
}
|
|
32
|
-
const luxonDuration = luxon_1.Duration.fromObject(inputDuration);
|
|
33
|
-
const newUnitValue = luxonDuration.as(requiredUnit);
|
|
34
|
-
return { [requiredUnit]: newUnitValue };
|
|
35
|
-
}
|
|
36
|
-
exports.convertDuration = convertDuration;
|
|
37
|
-
function hasInfinity(duration) {
|
|
38
|
-
return Object.values(duration).some((value) => value === Infinity);
|
|
39
|
-
}
|
|
40
|
-
function hasNegativeInfinity(duration) {
|
|
41
|
-
return Object.values(duration).some((value) => value === -Infinity);
|
|
42
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.overrideDateParts = void 0;
|
|
4
|
-
/** Override the initial provided FullDate with all subsequent FullDate parts. */
|
|
5
|
-
function overrideDateParts(date, ...overrides) {
|
|
6
|
-
return Object.assign({}, date, ...overrides);
|
|
7
|
-
}
|
|
8
|
-
exports.overrideDateParts = overrideDateParts;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertHasDateProps = exports.hasDateProps = void 0;
|
|
4
|
-
function hasDateProps(dateInput, keys) {
|
|
5
|
-
try {
|
|
6
|
-
assertHasDateProps(dateInput, keys);
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
catch (error) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.hasDateProps = hasDateProps;
|
|
14
|
-
function assertHasDateProps(dateInput, keys) {
|
|
15
|
-
const missingKeys = [];
|
|
16
|
-
keys.forEach((key) => {
|
|
17
|
-
if (dateInput[key] == undefined) {
|
|
18
|
-
missingKeys.push(key);
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
if (missingKeys.length) {
|
|
22
|
-
throw new Error(`Missing required FullDate key(s): ${missingKeys.join(', ')}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.assertHasDateProps = assertHasDateProps;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toJsDate = void 0;
|
|
4
|
-
const timestamp_1 = require("../formatting/timestamp");
|
|
5
|
-
function toJsDate(fullDate) {
|
|
6
|
-
return new Date((0, timestamp_1.toTimestamp)(fullDate));
|
|
7
|
-
}
|
|
8
|
-
exports.toJsDate = toJsDate;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNowInUtcTimezone = exports.getNowInUserTimezone = exports.getNowInIsoString = void 0;
|
|
4
|
-
const timestamp_1 = require("../formatting/timestamp");
|
|
5
|
-
const create_full_date_1 = require("../full-date/create-full-date");
|
|
6
|
-
const timezones_1 = require("../timezone/timezones");
|
|
7
|
-
function getNowInIsoString() {
|
|
8
|
-
/**
|
|
9
|
-
* The time zone doesn't matter here because the ISO string will be identical for a given date
|
|
10
|
-
* no matter what its timezone is.
|
|
11
|
-
*/
|
|
12
|
-
return (0, timestamp_1.toIsoString)((0, create_full_date_1.getNowFullDate)(timezones_1.utcTimezone));
|
|
13
|
-
}
|
|
14
|
-
exports.getNowInIsoString = getNowInIsoString;
|
|
15
|
-
function getNowInUserTimezone() {
|
|
16
|
-
return (0, create_full_date_1.getNowFullDate)(timezones_1.userTimezone);
|
|
17
|
-
}
|
|
18
|
-
exports.getNowInUserTimezone = getNowInUserTimezone;
|
|
19
|
-
function getNowInUtcTimezone() {
|
|
20
|
-
return (0, create_full_date_1.getNowFullDate)(timezones_1.utcTimezone);
|
|
21
|
-
}
|
|
22
|
-
exports.getNowInUtcTimezone = getNowInUtcTimezone;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.clearParts = exports.clearTime = exports.zeroTime = exports.emptyDate = exports.zeroDate = void 0;
|
|
4
|
-
const common_1 = require("@augment-vir/common");
|
|
5
|
-
const full_date_shape_1 = require("../full-date/full-date-shape");
|
|
6
|
-
const date_transforms_1 = require("./date-transforms");
|
|
7
|
-
exports.zeroDate = {
|
|
8
|
-
year: 0,
|
|
9
|
-
month: 1,
|
|
10
|
-
day: 1,
|
|
11
|
-
hour: 0,
|
|
12
|
-
minute: 0,
|
|
13
|
-
second: 0,
|
|
14
|
-
millisecond: 0,
|
|
15
|
-
};
|
|
16
|
-
exports.emptyDate = exports.zeroDate;
|
|
17
|
-
exports.zeroTime = (0, common_1.pickObjectKeys)(exports.zeroDate, full_date_shape_1.timeFullDateKeys);
|
|
18
|
-
function clearTime(inputFullDate) {
|
|
19
|
-
return clearParts(inputFullDate, full_date_shape_1.timeFullDateKeys);
|
|
20
|
-
}
|
|
21
|
-
exports.clearTime = clearTime;
|
|
22
|
-
function clearParts(inputFullDate, parts) {
|
|
23
|
-
const clearParts = (0, common_1.typedObjectFromEntries)(parts.map((keyName) => {
|
|
24
|
-
return [
|
|
25
|
-
keyName,
|
|
26
|
-
exports.zeroDate[keyName],
|
|
27
|
-
];
|
|
28
|
-
}));
|
|
29
|
-
return (0, date_transforms_1.overrideDateParts)(inputFullDate, clearParts);
|
|
30
|
-
}
|
|
31
|
-
exports.clearParts = clearParts;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toFormattedString = exports.toLocaleString = void 0;
|
|
4
|
-
const luxon_date_time_conversion_1 = require("../full-date/luxon-date-time-conversion");
|
|
5
|
-
const locales_1 = require("../locales");
|
|
6
|
-
/**
|
|
7
|
-
* Chromium has a weird behavior where the "NARROW NO-BREAK SPACE" character (code 8239) is used
|
|
8
|
-
* instead of a space (code 32) before AM/PM.
|
|
9
|
-
*/
|
|
10
|
-
function fixChromiumSpace(original) {
|
|
11
|
-
return original.replace(new RegExp(String.fromCharCode(8239), 'g'), ' ');
|
|
12
|
-
}
|
|
13
|
-
/** Converts the given FullDate into a string in the user's locale, or the given localeOverride. */
|
|
14
|
-
function toLocaleString(fullDate, formatOptions) {
|
|
15
|
-
const localeString = (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).toLocaleString({
|
|
16
|
-
...formatOptions,
|
|
17
|
-
}, {
|
|
18
|
-
locale: formatOptions?.locale ?? locales_1.userLocale,
|
|
19
|
-
});
|
|
20
|
-
return fixChromiumSpace(localeString);
|
|
21
|
-
}
|
|
22
|
-
exports.toLocaleString = toLocaleString;
|
|
23
|
-
/**
|
|
24
|
-
* Provides arbitrary date formatting using Luxon. For full details on the options for the format
|
|
25
|
-
* string input, see https://moment.github.io/luxon/#/formatting?id=table-of-tokens
|
|
26
|
-
*
|
|
27
|
-
* You probably should **prefer toLocaleString** so your users see the format they expect. It
|
|
28
|
-
* already has many formatting options.
|
|
29
|
-
*/
|
|
30
|
-
function toFormattedString(fullDate, format, localeOverride = locales_1.userLocale) {
|
|
31
|
-
const formattedString = (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).toFormat(format, { locale: localeOverride });
|
|
32
|
-
return fixChromiumSpace(formattedString);
|
|
33
|
-
}
|
|
34
|
-
exports.toFormattedString = toFormattedString;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toHtmlInputString = void 0;
|
|
4
|
-
const common_1 = require("@augment-vir/common");
|
|
5
|
-
const has_date_props_1 = require("../extra-utils/has-date-props");
|
|
6
|
-
const full_date_shape_1 = require("../full-date/full-date-shape");
|
|
7
|
-
const simple_strings_1 = require("./simple-strings");
|
|
8
|
-
function toHtmlInputString(fullDate, inputType, includeSeconds) {
|
|
9
|
-
const internalFullDate = fullDate;
|
|
10
|
-
if (inputType === full_date_shape_1.FullDatePartEnum.Date) {
|
|
11
|
-
(0, has_date_props_1.assertHasDateProps)(internalFullDate, [
|
|
12
|
-
'year',
|
|
13
|
-
'month',
|
|
14
|
-
'day',
|
|
15
|
-
]);
|
|
16
|
-
return (0, simple_strings_1.toSimpleDatePartString)(internalFullDate);
|
|
17
|
-
}
|
|
18
|
-
else if (inputType === full_date_shape_1.FullDatePartEnum.Time) {
|
|
19
|
-
if (includeSeconds && internalFullDate.second == undefined) {
|
|
20
|
-
throw new Error('Tried to include seconds in the time string but no seconds were provided.');
|
|
21
|
-
}
|
|
22
|
-
(0, has_date_props_1.assertHasDateProps)(internalFullDate, [
|
|
23
|
-
'hour',
|
|
24
|
-
'minute',
|
|
25
|
-
]);
|
|
26
|
-
return (0, simple_strings_1.toSimpleTimePartString)(internalFullDate, !!includeSeconds);
|
|
27
|
-
}
|
|
28
|
-
else if (inputType === full_date_shape_1.FullDatePartEnum.DateTime) {
|
|
29
|
-
const datePart = toHtmlInputString(fullDate, full_date_shape_1.FullDatePartEnum.Date);
|
|
30
|
-
const timePart = toHtmlInputString(fullDate, full_date_shape_1.FullDatePartEnum.Time, includeSeconds);
|
|
31
|
-
return `${datePart}T${timePart}`;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
throw new Error(`Unexpected inputTyped: '${inputType}'. Expected usage of FullDatePartEnum or one of ${(0, common_1.getEnumTypedValues)(full_date_shape_1.FullDatePartEnum).join(', ')}.`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.toHtmlInputString = toHtmlInputString;
|