date-vir 5.3.1 → 6.0.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/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/diff-dates.d.ts +95 -0
- package/dist/date-operations/diff-dates.js +124 -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 +99 -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 +48 -0
- package/dist/full-date/full-date-parts.js +45 -0
- package/dist/full-date/full-date-shape.d.ts +106 -0
- package/dist/{esm/full-date → full-date}/full-date-shape.js +15 -22
- 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/{esm/full-date → full-date}/luxon-date-time-conversion.js +10 -6
- 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 +27 -0
- package/dist/index.js +27 -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 +30 -48
- 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 -5
- 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/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/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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './date-operations/calculate-relative-date.js';
|
|
2
|
+
export * from './date-operations/combine-dates.js';
|
|
3
|
+
export * from './date-operations/diff-dates.js';
|
|
4
|
+
export * from './extra-utils/has-date-props.js';
|
|
5
|
+
export * from './extra-utils/js-date-conversion.js';
|
|
6
|
+
export * from './extra-utils/now.js';
|
|
7
|
+
export * from './extra-utils/override-date.js';
|
|
8
|
+
export * from './extra-utils/zero.js';
|
|
9
|
+
export * from './formatting/formatted-string.js';
|
|
10
|
+
export * from './formatting/html-input.js';
|
|
11
|
+
export * from './formatting/relative-string.js';
|
|
12
|
+
export * from './formatting/simple-strings.js';
|
|
13
|
+
export * from './formatting/string-format-types.js';
|
|
14
|
+
export * from './formatting/timestamp.js';
|
|
15
|
+
export * from './full-date/create-full-date.js';
|
|
16
|
+
export * from './full-date/date-like.js';
|
|
17
|
+
export * from './full-date/format-presets.js';
|
|
18
|
+
export * from './full-date/full-date-parts.js';
|
|
19
|
+
export * from './full-date/full-date-shape.js';
|
|
20
|
+
export * from './full-date/is-valid-full-date.js';
|
|
21
|
+
export * from './full-date/luxon-date-time-conversion.js';
|
|
22
|
+
export * from './full-date/parsing.js';
|
|
23
|
+
export * from './locales.js';
|
|
24
|
+
export * from './timezone/timezone-checks.js';
|
|
25
|
+
export * from './timezone/timezone-names.js';
|
|
26
|
+
export * from './timezone/timezones.js';
|
|
27
|
+
export * from '@date-vir/duration';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export * from './date-operations/calculate-relative-date.js';
|
|
2
|
+
export * from './date-operations/combine-dates.js';
|
|
3
|
+
export * from './date-operations/diff-dates.js';
|
|
4
|
+
export * from './extra-utils/has-date-props.js';
|
|
5
|
+
export * from './extra-utils/js-date-conversion.js';
|
|
6
|
+
export * from './extra-utils/now.js';
|
|
7
|
+
export * from './extra-utils/override-date.js';
|
|
8
|
+
export * from './extra-utils/zero.js';
|
|
9
|
+
export * from './formatting/formatted-string.js';
|
|
10
|
+
export * from './formatting/html-input.js';
|
|
11
|
+
export * from './formatting/relative-string.js';
|
|
12
|
+
export * from './formatting/simple-strings.js';
|
|
13
|
+
export * from './formatting/string-format-types.js';
|
|
14
|
+
export * from './formatting/timestamp.js';
|
|
15
|
+
export * from './full-date/create-full-date.js';
|
|
16
|
+
export * from './full-date/date-like.js';
|
|
17
|
+
export * from './full-date/format-presets.js';
|
|
18
|
+
export * from './full-date/full-date-parts.js';
|
|
19
|
+
export * from './full-date/full-date-shape.js';
|
|
20
|
+
export * from './full-date/is-valid-full-date.js';
|
|
21
|
+
export * from './full-date/luxon-date-time-conversion.js';
|
|
22
|
+
export * from './full-date/parsing.js';
|
|
23
|
+
export * from './locales.js';
|
|
24
|
+
export * from './timezone/timezone-checks.js';
|
|
25
|
+
export * from './timezone/timezone-names.js';
|
|
26
|
+
export * from './timezone/timezones.js';
|
|
27
|
+
export * from '@date-vir/duration';
|
package/dist/locales.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Timezone } from './timezones.js';
|
|
2
|
+
/**
|
|
3
|
+
* Asserts that the given input is a valid timezone name.
|
|
4
|
+
*
|
|
5
|
+
* Note that this may actually allow names beyond what is currently in the exact {@link Timezone}
|
|
6
|
+
* type, because this function checks to see if the given timezone can be used to construct a date,
|
|
7
|
+
* regardless of whether it's in our typed list or not.
|
|
8
|
+
*
|
|
9
|
+
* @category Assertion
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertValidTimezone(potentialTimezone: string, userMessage?: string | undefined): asserts potentialTimezone is Timezone;
|
|
12
|
+
/**
|
|
13
|
+
* Checks that the given timezone is valid.
|
|
14
|
+
*
|
|
15
|
+
* Note that this may actually allow names beyond what is currently in the exact {@link Timezone}
|
|
16
|
+
* type, because this function checks to see if the given timezone can be used to construct a date,
|
|
17
|
+
* regardless of whether it's in our typed list or not.
|
|
18
|
+
*
|
|
19
|
+
* @category Assertion
|
|
20
|
+
*/
|
|
21
|
+
export declare function isValidTimezone(potentialTimezone: string): potentialTimezone is Timezone;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AssertionError } from '@augment-vir/assert';
|
|
2
|
+
import { Info } from 'luxon';
|
|
3
|
+
/**
|
|
4
|
+
* Asserts that the given input is a valid timezone name.
|
|
5
|
+
*
|
|
6
|
+
* Note that this may actually allow names beyond what is currently in the exact {@link Timezone}
|
|
7
|
+
* type, because this function checks to see if the given timezone can be used to construct a date,
|
|
8
|
+
* regardless of whether it's in our typed list or not.
|
|
9
|
+
*
|
|
10
|
+
* @category Assertion
|
|
11
|
+
*/
|
|
12
|
+
export function assertValidTimezone(potentialTimezone, userMessage) {
|
|
13
|
+
if (!Info.isValidIANAZone(potentialTimezone)) {
|
|
14
|
+
throw new AssertionError(`'${potentialTimezone}' is not a valid time zone`, userMessage);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks that the given timezone is valid.
|
|
19
|
+
*
|
|
20
|
+
* Note that this may actually allow names beyond what is currently in the exact {@link Timezone}
|
|
21
|
+
* type, because this function checks to see if the given timezone can be used to construct a date,
|
|
22
|
+
* regardless of whether it's in our typed list or not.
|
|
23
|
+
*
|
|
24
|
+
* @category Assertion
|
|
25
|
+
*/
|
|
26
|
+
export function isValidTimezone(potentialTimezone) {
|
|
27
|
+
try {
|
|
28
|
+
assertValidTimezone(potentialTimezone);
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { ArrayElement } from '@augment-vir/common';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* browsers I had immediately available to me at the time) with the following code:
|
|
2
|
+
* All valid timezone names.
|
|
5
3
|
*
|
|
6
|
-
*
|
|
4
|
+
* The list of timezone names was generated from Firefox 106.0.2 (which gave me the longest list out
|
|
5
|
+
* of all the browsers I had available to me) with the following code:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* Intl.supportedValuesOf('timeZone')
|
|
9
|
+
* .map((zone) => `'${zone}'`)
|
|
10
|
+
* .join(',');
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @category Timezone
|
|
7
14
|
*/
|
|
8
15
|
export declare const allTimezoneNames: readonly ["Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", "Africa/Algiers", "Africa/Asmara", "Africa/Bamako", "Africa/Bangui", "Africa/Banjul", "Africa/Bissau", "Africa/Blantyre", "Africa/Brazzaville", "Africa/Bujumbura", "Africa/Cairo", "Africa/Casablanca", "Africa/Ceuta", "Africa/Conakry", "Africa/Dakar", "Africa/Dar_es_Salaam", "Africa/Djibouti", "Africa/Douala", "Africa/El_Aaiun", "Africa/Freetown", "Africa/Gaborone", "Africa/Harare", "Africa/Johannesburg", "Africa/Juba", "Africa/Kampala", "Africa/Khartoum", "Africa/Kigali", "Africa/Kinshasa", "Africa/Lagos", "Africa/Libreville", "Africa/Lome", "Africa/Luanda", "Africa/Lubumbashi", "Africa/Lusaka", "Africa/Malabo", "Africa/Maputo", "Africa/Maseru", "Africa/Mbabane", "Africa/Mogadishu", "Africa/Monrovia", "Africa/Nairobi", "Africa/Ndjamena", "Africa/Niamey", "Africa/Nouakchott", "Africa/Ouagadougou", "Africa/Porto-Novo", "Africa/Sao_Tome", "Africa/Timbuktu", "Africa/Tripoli", "Africa/Tunis", "Africa/Windhoek", "America/Adak", "America/Anchorage", "America/Anguilla", "America/Antigua", "America/Araguaina", "America/Argentina/Buenos_Aires", "America/Argentina/Catamarca", "America/Argentina/ComodRivadavia", "America/Argentina/Cordoba", "America/Argentina/Jujuy", "America/Argentina/La_Rioja", "America/Argentina/Mendoza", "America/Argentina/Rio_Gallegos", "America/Argentina/Salta", "America/Argentina/San_Juan", "America/Argentina/San_Luis", "America/Argentina/Tucuman", "America/Argentina/Ushuaia", "America/Aruba", "America/Asuncion", "America/Atikokan", "America/Bahia", "America/Bahia_Banderas", "America/Barbados", "America/Belem", "America/Belize", "America/Blanc-Sablon", "America/Boa_Vista", "America/Bogota", "America/Boise", "America/Cambridge_Bay", "America/Campo_Grande", "America/Cancun", "America/Caracas", "America/Cayenne", "America/Cayman", "America/Chicago", "America/Chihuahua", "America/Coral_Harbour", "America/Costa_Rica", "America/Creston", "America/Cuiaba", "America/Curacao", "America/Danmarkshavn", "America/Dawson", "America/Dawson_Creek", "America/Denver", "America/Detroit", "America/Dominica", "America/Edmonton", "America/Eirunepe", "America/El_Salvador", "America/Ensenada", "America/Fort_Nelson", "America/Fortaleza", "America/Glace_Bay", "America/Goose_Bay", "America/Grand_Turk", "America/Grenada", "America/Guadeloupe", "America/Guatemala", "America/Guayaquil", "America/Guyana", "America/Halifax", "America/Havana", "America/Hermosillo", "America/Indiana/Indianapolis", "America/Indiana/Knox", "America/Indiana/Marengo", "America/Indiana/Petersburg", "America/Indiana/Tell_City", "America/Indiana/Vevay", "America/Indiana/Vincennes", "America/Indiana/Winamac", "America/Inuvik", "America/Iqaluit", "America/Jamaica", "America/Juneau", "America/Kentucky/Louisville", "America/Kentucky/Monticello", "America/La_Paz", "America/Lima", "America/Los_Angeles", "America/Maceio", "America/Managua", "America/Manaus", "America/Martinique", "America/Matamoros", "America/Mazatlan", "America/Menominee", "America/Merida", "America/Metlakatla", "America/Mexico_City", "America/Miquelon", "America/Moncton", "America/Monterrey", "America/Montevideo", "America/Montreal", "America/Montserrat", "America/Nassau", "America/New_York", "America/Nipigon", "America/Nome", "America/Noronha", "America/North_Dakota/Beulah", "America/North_Dakota/Center", "America/North_Dakota/New_Salem", "America/Nuuk", "America/Ojinaga", "America/Panama", "America/Pangnirtung", "America/Paramaribo", "America/Phoenix", "America/Port-au-Prince", "America/Port_of_Spain", "America/Porto_Velho", "America/Puerto_Rico", "America/Punta_Arenas", "America/Rainy_River", "America/Rankin_Inlet", "America/Recife", "America/Regina", "America/Resolute", "America/Rio_Branco", "America/Rosario", "America/Santarem", "America/Santiago", "America/Santo_Domingo", "America/Sao_Paulo", "America/Scoresbysund", "America/Sitka", "America/St_Johns", "America/St_Kitts", "America/St_Lucia", "America/St_Thomas", "America/St_Vincent", "America/Swift_Current", "America/Tegucigalpa", "America/Thule", "America/Thunder_Bay", "America/Tijuana", "America/Toronto", "America/Tortola", "America/Vancouver", "America/Whitehorse", "America/Winnipeg", "America/Yakutat", "America/Yellowknife", "Antarctica/Casey", "Antarctica/Davis", "Antarctica/DumontDUrville", "Antarctica/Macquarie", "Antarctica/Mawson", "Antarctica/McMurdo", "Antarctica/Palmer", "Antarctica/Rothera", "Antarctica/Syowa", "Antarctica/Troll", "Antarctica/Vostok", "Asia/Aden", "Asia/Almaty", "Asia/Amman", "Asia/Anadyr", "Asia/Aqtau", "Asia/Aqtobe", "Asia/Ashgabat", "Asia/Atyrau", "Asia/Baghdad", "Asia/Bahrain", "Asia/Baku", "Asia/Bangkok", "Asia/Barnaul", "Asia/Beirut", "Asia/Bishkek", "Asia/Brunei", "Asia/Chita", "Asia/Choibalsan", "Asia/Chongqing", "Asia/Colombo", "Asia/Damascus", "Asia/Dhaka", "Asia/Dili", "Asia/Dubai", "Asia/Dushanbe", "Asia/Famagusta", "Asia/Gaza", "Asia/Harbin", "Asia/Hebron", "Asia/Ho_Chi_Minh", "Asia/Hong_Kong", "Asia/Hovd", "Asia/Irkutsk", "Asia/Jakarta", "Asia/Jayapura", "Asia/Jerusalem", "Asia/Kabul", "Asia/Kamchatka", "Asia/Karachi", "Asia/Kashgar", "Asia/Kathmandu", "Asia/Khandyga", "Asia/Kolkata", "Asia/Krasnoyarsk", "Asia/Kuala_Lumpur", "Asia/Kuching", "Asia/Kuwait", "Asia/Macau", "Asia/Magadan", "Asia/Makassar", "Asia/Manila", "Asia/Muscat", "Asia/Nicosia", "Asia/Novokuznetsk", "Asia/Novosibirsk", "Asia/Omsk", "Asia/Oral", "Asia/Phnom_Penh", "Asia/Pontianak", "Asia/Pyongyang", "Asia/Qatar", "Asia/Qostanay", "Asia/Qyzylorda", "Asia/Riyadh", "Asia/Sakhalin", "Asia/Samarkand", "Asia/Seoul", "Asia/Shanghai", "Asia/Singapore", "Asia/Srednekolymsk", "Asia/Taipei", "Asia/Tashkent", "Asia/Tbilisi", "Asia/Tehran", "Asia/Tel_Aviv", "Asia/Thimphu", "Asia/Tokyo", "Asia/Tomsk", "Asia/Ulaanbaatar", "Asia/Urumqi", "Asia/Ust-Nera", "Asia/Vientiane", "Asia/Vladivostok", "Asia/Yakutsk", "Asia/Yangon", "Asia/Yekaterinburg", "Asia/Yerevan", "Atlantic/Azores", "Atlantic/Bermuda", "Atlantic/Canary", "Atlantic/Cape_Verde", "Atlantic/Faroe", "Atlantic/Jan_Mayen", "Atlantic/Madeira", "Atlantic/Reykjavik", "Atlantic/South_Georgia", "Atlantic/St_Helena", "Atlantic/Stanley", "Australia/Adelaide", "Australia/Brisbane", "Australia/Broken_Hill", "Australia/Currie", "Australia/Darwin", "Australia/Eucla", "Australia/Hobart", "Australia/Lindeman", "Australia/Lord_Howe", "Australia/Melbourne", "Australia/Perth", "Australia/Sydney", "CET", "CST6CDT", "EET", "EST", "EST5EDT", "Etc/GMT+1", "Etc/GMT+10", "Etc/GMT+11", "Etc/GMT+12", "Etc/GMT+2", "Etc/GMT+3", "Etc/GMT+4", "Etc/GMT+5", "Etc/GMT+6", "Etc/GMT+7", "Etc/GMT+8", "Etc/GMT+9", "Etc/GMT-1", "Etc/GMT-10", "Etc/GMT-11", "Etc/GMT-12", "Etc/GMT-13", "Etc/GMT-14", "Etc/GMT-2", "Etc/GMT-3", "Etc/GMT-4", "Etc/GMT-5", "Etc/GMT-6", "Etc/GMT-7", "Etc/GMT-8", "Etc/GMT-9", "Europe/Amsterdam", "Europe/Andorra", "Europe/Astrakhan", "Europe/Athens", "Europe/Belfast", "Europe/Belgrade", "Europe/Berlin", "Europe/Brussels", "Europe/Bucharest", "Europe/Budapest", "Europe/Chisinau", "Europe/Copenhagen", "Europe/Dublin", "Europe/Gibraltar", "Europe/Guernsey", "Europe/Helsinki", "Europe/Isle_of_Man", "Europe/Istanbul", "Europe/Jersey", "Europe/Kaliningrad", "Europe/Kirov", "Europe/Kyiv", "Europe/Lisbon", "Europe/Ljubljana", "Europe/London", "Europe/Luxembourg", "Europe/Madrid", "Europe/Malta", "Europe/Minsk", "Europe/Monaco", "Europe/Moscow", "Europe/Oslo", "Europe/Paris", "Europe/Prague", "Europe/Riga", "Europe/Rome", "Europe/Samara", "Europe/Sarajevo", "Europe/Saratov", "Europe/Simferopol", "Europe/Skopje", "Europe/Sofia", "Europe/Stockholm", "Europe/Tallinn", "Europe/Tirane", "Europe/Tiraspol", "Europe/Ulyanovsk", "Europe/Uzhgorod", "Europe/Vaduz", "Europe/Vienna", "Europe/Vilnius", "Europe/Volgograd", "Europe/Warsaw", "Europe/Zagreb", "Europe/Zaporozhye", "Europe/Zurich", "Factory", "HST", "Indian/Antananarivo", "Indian/Chagos", "Indian/Christmas", "Indian/Cocos", "Indian/Comoro", "Indian/Kerguelen", "Indian/Mahe", "Indian/Maldives", "Indian/Mauritius", "Indian/Mayotte", "Indian/Reunion", "MET", "MST", "MST7MDT", "PST8PDT", "Pacific/Apia", "Pacific/Auckland", "Pacific/Bougainville", "Pacific/Chatham", "Pacific/Chuuk", "Pacific/Easter", "Pacific/Efate", "Pacific/Enderbury", "Pacific/Fakaofo", "Pacific/Fiji", "Pacific/Funafuti", "Pacific/Galapagos", "Pacific/Gambier", "Pacific/Guadalcanal", "Pacific/Guam", "Pacific/Honolulu", "Pacific/Johnston", "Pacific/Kanton", "Pacific/Kiritimati", "Pacific/Kosrae", "Pacific/Kwajalein", "Pacific/Majuro", "Pacific/Marquesas", "Pacific/Midway", "Pacific/Nauru", "Pacific/Niue", "Pacific/Norfolk", "Pacific/Noumea", "Pacific/Pago_Pago", "Pacific/Palau", "Pacific/Pitcairn", "Pacific/Pohnpei", "Pacific/Port_Moresby", "Pacific/Rarotonga", "Pacific/Saipan", "Pacific/Tahiti", "Pacific/Tarawa", "Pacific/Tongatapu", "Pacific/Wake", "Pacific/Wallis", "UTC", "WET"];
|
|
9
|
-
export type Timezone = ArrayElement<typeof allTimezoneNames>;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* browsers I had immediately available to me at the time) with the following code:
|
|
2
|
+
* All valid timezone names.
|
|
4
3
|
*
|
|
5
|
-
*
|
|
4
|
+
* The list of timezone names was generated from Firefox 106.0.2 (which gave me the longest list out
|
|
5
|
+
* of all the browsers I had available to me) with the following code:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* Intl.supportedValuesOf('timeZone')
|
|
9
|
+
* .map((zone) => `'${zone}'`)
|
|
10
|
+
* .join(',');
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @category Timezone
|
|
6
14
|
*/
|
|
7
15
|
export const allTimezoneNames = [
|
|
8
16
|
'Africa/Abidjan',
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ArrayElement } from '@augment-vir/common';
|
|
2
|
+
import { allTimezoneNames } from './timezone-names.js';
|
|
3
|
+
/**
|
|
4
|
+
* All possible timezone names.
|
|
5
|
+
*
|
|
6
|
+
* @category Timezone
|
|
7
|
+
* @see {@link allTimezoneNames}
|
|
8
|
+
*/
|
|
9
|
+
export type Timezone = ArrayElement<typeof allTimezoneNames>;
|
|
10
|
+
/**
|
|
11
|
+
* An enum of all possible timezone names.
|
|
12
|
+
*
|
|
13
|
+
* @category Timezone
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import {Timezone} from 'date-vir';
|
|
18
|
+
*
|
|
19
|
+
* Timezone['Africa/Bamako'];
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const Timezone: Readonly<{
|
|
23
|
+
[SpecificTimezoneName in Timezone]: SpecificTimezoneName;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* The timezone of the current user's environment.
|
|
27
|
+
*
|
|
28
|
+
* @category Timezone
|
|
29
|
+
*/
|
|
30
|
+
export declare const userTimezone: Timezone;
|
|
31
|
+
/**
|
|
32
|
+
* The UTC timezone.
|
|
33
|
+
*
|
|
34
|
+
* @category Timezone
|
|
35
|
+
*/
|
|
36
|
+
export declare const utcTimezone: "UTC";
|
|
37
|
+
/**
|
|
38
|
+
* The UTC timezone as a type.
|
|
39
|
+
*
|
|
40
|
+
* @category Timezone
|
|
41
|
+
*/
|
|
42
|
+
export type UtcTimezone = typeof utcTimezone;
|
|
@@ -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": "6.0.1",
|
|
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.1.0",
|
|
38
|
+
"@augment-vir/common": "^30.1.0",
|
|
39
|
+
"@date-vir/duration": "^6.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.0.0",
|
|
43
|
+
"type-fest": "^4.26.1"
|
|
49
44
|
},
|
|
50
45
|
"devDependencies": {
|
|
51
|
-
"@augment-vir/
|
|
52
|
-
"@augment-vir/browser-testing": "^28.0.2",
|
|
53
|
-
"@open-wc/testing": "^4.0.0",
|
|
54
|
-
"@types/chai": "^4.3.16",
|
|
55
|
-
"@types/mocha": "^10.0.6",
|
|
46
|
+
"@augment-vir/test": "^30.1.0",
|
|
56
47
|
"@web/dev-server-esbuild": "^1.0.2",
|
|
57
|
-
"@web/test-runner": "^0.
|
|
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
|
-
"cspell": "^8.8.3",
|
|
62
|
-
"dependency-cruiser": "^16.3.2",
|
|
51
|
+
"@web/test-runner-visual-regression": "^0.10.0",
|
|
63
52
|
"element-vir": "^22.2.2",
|
|
64
|
-
"esbuild": "^0.21.4",
|
|
65
53
|
"istanbul-smart-text-reporter": "^1.1.4",
|
|
66
|
-
"markdown-code-example-inserter": "^
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"
|
|
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"
|
|
54
|
+
"markdown-code-example-inserter": "^3.0.0",
|
|
55
|
+
"typedoc": "^0.26.7"
|
|
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
|
-
];
|