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.
Files changed (147) hide show
  1. package/LICENSE-MIT +1 -1
  2. package/README.md +28 -28
  3. package/dist/date-operations/calculate-relative-date.d.ts +17 -0
  4. package/dist/{esm/date-operations → date-operations}/calculate-relative-date.js +10 -1
  5. package/dist/date-operations/combine-dates.d.ts +43 -0
  6. package/dist/{esm/date-operations → date-operations}/combine-dates.js +6 -4
  7. package/dist/date-operations/date-position.d.ts +149 -0
  8. package/dist/date-operations/date-position.js +175 -0
  9. package/dist/date-operations/diff-dates.d.ts +95 -0
  10. package/dist/date-operations/diff-dates.js +124 -0
  11. package/dist/extra-utils/end.d.ts +11 -0
  12. package/dist/extra-utils/end.js +11 -0
  13. package/dist/extra-utils/has-date-props.d.ts +35 -0
  14. package/dist/extra-utils/has-date-props.js +46 -0
  15. package/dist/extra-utils/js-date-conversion.d.ts +26 -0
  16. package/dist/extra-utils/js-date-conversion.js +28 -0
  17. package/dist/extra-utils/now.d.ts +56 -0
  18. package/dist/extra-utils/now.js +68 -0
  19. package/dist/extra-utils/override-date.d.ts +27 -0
  20. package/dist/extra-utils/override-date.js +27 -0
  21. package/dist/extra-utils/zero.d.ts +109 -0
  22. package/dist/extra-utils/zero.js +94 -0
  23. package/dist/formatting/formatted-string.d.ts +58 -0
  24. package/dist/formatting/formatted-string.js +73 -0
  25. package/dist/formatting/html-input.d.ts +30 -0
  26. package/dist/formatting/html-input.js +47 -0
  27. package/dist/formatting/relative-string.d.ts +53 -0
  28. package/dist/formatting/relative-string.js +93 -0
  29. package/dist/formatting/simple-strings.d.ts +187 -0
  30. package/dist/formatting/simple-strings.js +120 -0
  31. package/dist/formatting/string-format-types.d.ts +59 -0
  32. package/dist/formatting/string-format-types.js +19 -0
  33. package/dist/formatting/timestamp.d.ts +51 -0
  34. package/dist/formatting/timestamp.js +61 -0
  35. package/dist/full-date/create-full-date.d.ts +91 -0
  36. package/dist/full-date/create-full-date.js +142 -0
  37. package/dist/full-date/date-like.d.ts +9 -0
  38. package/dist/{esm/full-date → full-date}/format-presets.d.ts +4 -2
  39. package/dist/{esm/full-date → full-date}/format-presets.js +4 -2
  40. package/dist/full-date/full-date-parts.d.ts +44 -0
  41. package/dist/full-date/full-date-parts.js +47 -0
  42. package/dist/full-date/full-date-shape.d.ts +108 -0
  43. package/dist/full-date/full-date-shape.js +45 -0
  44. package/dist/full-date/is-valid-full-date.d.ts +21 -0
  45. package/dist/full-date/is-valid-full-date.js +38 -0
  46. package/dist/full-date/luxon-date-time-conversion.d.ts +19 -0
  47. package/dist/full-date/luxon-date-time-conversion.js +43 -0
  48. package/dist/full-date/parsing.d.ts +33 -0
  49. package/dist/full-date/parsing.js +47 -0
  50. package/dist/full-date/string-parsing.d.ts +9 -0
  51. package/dist/{esm/full-date → full-date}/string-parsing.js +6 -0
  52. package/dist/index.d.ts +29 -0
  53. package/dist/index.js +29 -0
  54. package/dist/locales.d.ts +6 -0
  55. package/dist/locales.js +7 -0
  56. package/dist/timezone/timezone-checks.d.ts +21 -0
  57. package/dist/timezone/timezone-checks.js +34 -0
  58. package/dist/{esm/timezone → timezone}/timezone-names.d.ts +11 -5
  59. package/dist/{esm/timezone → timezone}/timezone-names.js +11 -3
  60. package/dist/timezone/timezones.d.ts +42 -0
  61. package/dist/timezone/timezones.js +31 -0
  62. package/package.json +33 -51
  63. package/cspell.config.cjs +0 -13
  64. package/dist/cjs/date-operations/calculate-relative-date.js +0 -12
  65. package/dist/cjs/date-operations/combine-dates.js +0 -50
  66. package/dist/cjs/date-operations/diff-dates.js +0 -105
  67. package/dist/cjs/duration/duration-unit.js +0 -41
  68. package/dist/cjs/duration/duration-utils.js +0 -42
  69. package/dist/cjs/duration/duration.js +0 -2
  70. package/dist/cjs/extra-utils/date-transforms.js +0 -8
  71. package/dist/cjs/extra-utils/has-date-props.js +0 -25
  72. package/dist/cjs/extra-utils/js-date-conversion.js +0 -8
  73. package/dist/cjs/extra-utils/now.js +0 -22
  74. package/dist/cjs/extra-utils/zero.js +0 -31
  75. package/dist/cjs/formatting/formatted-string.js +0 -34
  76. package/dist/cjs/formatting/html-input.js +0 -37
  77. package/dist/cjs/formatting/relative-string.js +0 -77
  78. package/dist/cjs/formatting/simple-strings.js +0 -58
  79. package/dist/cjs/formatting/string-format-types.js +0 -9
  80. package/dist/cjs/formatting/timestamp.js +0 -21
  81. package/dist/cjs/full-date/create-full-date.js +0 -81
  82. package/dist/cjs/full-date/date-like.js +0 -2
  83. package/dist/cjs/full-date/format-presets.js +0 -32
  84. package/dist/cjs/full-date/full-date-shape.js +0 -54
  85. package/dist/cjs/full-date/is-valid-full-date.js +0 -28
  86. package/dist/cjs/full-date/luxon-date-time-conversion.js +0 -43
  87. package/dist/cjs/full-date/parsing.js +0 -48
  88. package/dist/cjs/full-date/string-parsing.js +0 -33
  89. package/dist/cjs/index.js +0 -44
  90. package/dist/cjs/locales.js +0 -5
  91. package/dist/cjs/timezone/timezone-checks.js +0 -34
  92. package/dist/cjs/timezone/timezone-names.js +0 -479
  93. package/dist/cjs/timezone/timezones.js +0 -14
  94. package/dist/esm/date-operations/calculate-relative-date.d.ts +0 -8
  95. package/dist/esm/date-operations/combine-dates.d.ts +0 -35
  96. package/dist/esm/date-operations/diff-dates.d.ts +0 -66
  97. package/dist/esm/date-operations/diff-dates.js +0 -100
  98. package/dist/esm/duration/duration-unit.d.ts +0 -27
  99. package/dist/esm/duration/duration-unit.js +0 -38
  100. package/dist/esm/duration/duration-utils.d.ts +0 -11
  101. package/dist/esm/duration/duration-utils.js +0 -37
  102. package/dist/esm/duration/duration.d.ts +0 -32
  103. package/dist/esm/duration/duration.js +0 -1
  104. package/dist/esm/extra-utils/date-transforms.d.ts +0 -4
  105. package/dist/esm/extra-utils/date-transforms.js +0 -4
  106. package/dist/esm/extra-utils/has-date-props.d.ts +0 -9
  107. package/dist/esm/extra-utils/has-date-props.js +0 -20
  108. package/dist/esm/extra-utils/js-date-conversion.d.ts +0 -2
  109. package/dist/esm/extra-utils/js-date-conversion.js +0 -4
  110. package/dist/esm/extra-utils/now.d.ts +0 -6
  111. package/dist/esm/extra-utils/now.js +0 -16
  112. package/dist/esm/extra-utils/zero.d.ts +0 -31
  113. package/dist/esm/extra-utils/zero.js +0 -26
  114. package/dist/esm/formatting/formatted-string.d.ts +0 -14
  115. package/dist/esm/formatting/formatted-string.js +0 -29
  116. package/dist/esm/formatting/html-input.d.ts +0 -19
  117. package/dist/esm/formatting/html-input.js +0 -33
  118. package/dist/esm/formatting/relative-string.d.ts +0 -31
  119. package/dist/esm/formatting/relative-string.js +0 -73
  120. package/dist/esm/formatting/simple-strings.d.ts +0 -71
  121. package/dist/esm/formatting/simple-strings.js +0 -51
  122. package/dist/esm/formatting/string-format-types.d.ts +0 -7
  123. package/dist/esm/formatting/string-format-types.js +0 -5
  124. package/dist/esm/formatting/timestamp.d.ts +0 -6
  125. package/dist/esm/formatting/timestamp.js +0 -16
  126. package/dist/esm/full-date/create-full-date.d.ts +0 -21
  127. package/dist/esm/full-date/create-full-date.js +0 -73
  128. package/dist/esm/full-date/date-like.d.ts +0 -5
  129. package/dist/esm/full-date/full-date-shape.d.ts +0 -80
  130. package/dist/esm/full-date/full-date-shape.js +0 -51
  131. package/dist/esm/full-date/is-valid-full-date.d.ts +0 -5
  132. package/dist/esm/full-date/is-valid-full-date.js +0 -22
  133. package/dist/esm/full-date/luxon-date-time-conversion.d.ts +0 -15
  134. package/dist/esm/full-date/luxon-date-time-conversion.js +0 -38
  135. package/dist/esm/full-date/parsing.d.ts +0 -27
  136. package/dist/esm/full-date/parsing.js +0 -43
  137. package/dist/esm/full-date/string-parsing.d.ts +0 -3
  138. package/dist/esm/index.d.ts +0 -28
  139. package/dist/esm/index.js +0 -28
  140. package/dist/esm/locales.d.ts +0 -1
  141. package/dist/esm/locales.js +0 -2
  142. package/dist/esm/timezone/timezone-checks.d.ts +0 -17
  143. package/dist/esm/timezone/timezone-checks.js +0 -29
  144. package/dist/esm/timezone/timezones.d.ts +0 -480
  145. package/dist/esm/timezone/timezones.js +0 -11
  146. package/public/index.css +0 -7
  147. /package/dist/{esm/full-date → full-date}/date-like.js +0 -0
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toRelativeString = void 0;
4
- const common_1 = require("@augment-vir/common");
5
- const run_time_assertions_1 = require("run-time-assertions");
6
- const diff_dates_1 = require("../date-operations/diff-dates");
7
- const duration_unit_1 = require("../duration/duration-unit");
8
- const maxDurations = {
9
- [duration_unit_1.DurationUnit.Milliseconds]: 1000,
10
- [duration_unit_1.DurationUnit.Seconds]: 60,
11
- [duration_unit_1.DurationUnit.Minutes]: 60,
12
- [duration_unit_1.DurationUnit.Hours]: 24,
13
- [duration_unit_1.DurationUnit.Days]: 30,
14
- [duration_unit_1.DurationUnit.Weeks]: 4,
15
- [duration_unit_1.DurationUnit.Months]: 12,
16
- [duration_unit_1.DurationUnit.Quarters]: 4,
17
- [duration_unit_1.DurationUnit.Years]: Infinity,
18
- };
19
- function toRelativeString({ fullDate, relativeTo, options = {}, }) {
20
- const roundingDigits = options.decimalDigitCount || 0;
21
- const allUnitDiffs = (0, diff_dates_1.diffDates)({
22
- start: fullDate,
23
- end: relativeTo,
24
- units: duration_unit_1.orderedDurationUnits,
25
- diffType: diff_dates_1.DiffType.EquivalentUnits,
26
- });
27
- const unitsWithinBounds = (0, common_1.mapObjectValues)(allUnitDiffs, (durationUnit, duration) => {
28
- const roundedDuration = Math.floor(Math.abs((0, common_1.round)({ digits: 1, number: duration })));
29
- const isAboveZero = roundedDuration > 0;
30
- const isBelowMax = options.limitUnitMax
31
- ? roundedDuration < maxDurations[durationUnit]
32
- : true;
33
- return isAboveZero && isBelowMax;
34
- });
35
- const unitToUse = duration_unit_1.orderedDurationUnits.reduce((chosenUnit, currentUnit) => {
36
- const isUnitAllowed = !options.blockedRelativeUnits?.includes(currentUnit);
37
- if (isUnitAllowed && unitsWithinBounds[currentUnit]) {
38
- return currentUnit;
39
- }
40
- else {
41
- return chosenUnit;
42
- }
43
- }, undefined);
44
- const shouldUseJustNow = options.blockJustNow
45
- ? false
46
- : (unitToUse == undefined && allUnitDiffs.minutes < 2) ||
47
- (0, run_time_assertions_1.isJsonEqual)(fullDate, relativeTo) ||
48
- (unitToUse === duration_unit_1.DurationUnit.Minutes &&
49
- options.blockedRelativeUnits?.includes(duration_unit_1.DurationUnit.Seconds) &&
50
- allUnitDiffs.minutes < 2) ||
51
- (unitToUse === duration_unit_1.DurationUnit.Seconds &&
52
- options.blockedRelativeUnits?.includes(duration_unit_1.DurationUnit.Milliseconds) &&
53
- allUnitDiffs.seconds < 11) ||
54
- (unitToUse === duration_unit_1.DurationUnit.Milliseconds && allUnitDiffs.milliseconds < 710);
55
- /** Some short circuits. */
56
- if (shouldUseJustNow) {
57
- return 'just now';
58
- }
59
- else if (unitToUse == undefined) {
60
- return undefined;
61
- }
62
- const duration = allUnitDiffs[unitToUse];
63
- const roundedAbsoluteDuration = Math.abs((0, common_1.round)({ digits: roundingDigits, number: duration }));
64
- const isDurationSingular = roundedAbsoluteDuration === 1;
65
- const unitName = [
66
- duration_unit_1.singularDurationUnitNames[unitToUse],
67
- isDurationSingular ? '' : 's',
68
- ].join('');
69
- const value = isDurationSingular ? 'a' : roundedAbsoluteDuration;
70
- if (duration < 0) {
71
- return `in ${value} ${unitName}`;
72
- }
73
- else {
74
- return `${value} ${unitName} ago`;
75
- }
76
- }
77
- exports.toRelativeString = toRelativeString;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toSimpleString = exports.toSimplePartStrings = exports.toSimpleTimePartString = exports.toSimpleDatePartString = void 0;
4
- const common_1 = require("@augment-vir/common");
5
- /**
6
- * Create a string based on just the date parts of a FullDate.
7
- *
8
- * CAUTION: this does not user locale setting and should therefore not be used for user-facing date
9
- * formatting. Prefer using `toLocaleString` instead for user-facing strings.
10
- *
11
- * Example output: `'2023-12-05'`
12
- */
13
- function toSimpleDatePartString(fullDate) {
14
- const dateParts = [
15
- String(Math.abs(fullDate.year)).padStart(4, '0'),
16
- String(Math.abs(fullDate.month)).padStart(2, '0'),
17
- String(Math.abs(fullDate.day)).padStart(2, '0'),
18
- ];
19
- const dateString = dateParts.join('-');
20
- return dateString;
21
- }
22
- exports.toSimpleDatePartString = toSimpleDatePartString;
23
- function toSimpleTimePartString(fullDate, includeSeconds) {
24
- const seconds = (0, common_1.typedHasProperty)(fullDate, 'second') && includeSeconds
25
- ? String(Math.abs(fullDate.second)).padStart(2, '0')
26
- : undefined;
27
- const timeParts = [
28
- String(Math.abs(fullDate.hour)).padStart(2, '0'),
29
- String(Math.abs(fullDate.minute)).padStart(2, '0'),
30
- seconds,
31
- ].filter(common_1.isTruthy);
32
- return timeParts.join(':');
33
- }
34
- exports.toSimpleTimePartString = toSimpleTimePartString;
35
- function toSimplePartStrings(fullDate, options) {
36
- return {
37
- date: toSimpleDatePartString(fullDate),
38
- time: toSimpleTimePartString(fullDate, options.includeSeconds),
39
- timezone: fullDate.timezone,
40
- };
41
- }
42
- exports.toSimplePartStrings = toSimplePartStrings;
43
- /**
44
- * Converts a date into a simple, unambiguous date string.
45
- *
46
- * CAUTION: this does not user locale setting and should therefore not be used for user-facing date
47
- * formatting. Prefer using `toLocaleString` instead for user-facing strings.
48
- */
49
- function toSimpleString(fullDate, options) {
50
- const parts = toSimplePartStrings(fullDate, options);
51
- const stringParts = [
52
- parts.date,
53
- parts.time,
54
- options.includeTimezone && `(${parts.timezone})`,
55
- ].filter(common_1.isTruthy);
56
- return stringParts.join(' ');
57
- }
58
- exports.toSimpleString = toSimpleString;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidIsoString = void 0;
4
- const luxon_1 = require("luxon");
5
- function isValidIsoString(input) {
6
- const datetime = luxon_1.DateTime.fromISO(input);
7
- return datetime.toISO() === input;
8
- }
9
- exports.isValidIsoString = isValidIsoString;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toIsoString = exports.toTimestamp = void 0;
4
- const luxon_date_time_conversion_1 = require("../full-date/luxon-date-time-conversion");
5
- const timezones_1 = require("../timezone/timezones");
6
- /** Convert a FullDate into a unix timestamp with milliseconds. */
7
- function toTimestamp(fullDate) {
8
- return (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).toMillis();
9
- }
10
- exports.toTimestamp = toTimestamp;
11
- /** Convert a FullDate into an ISO string in UTC; always ends in Z. */
12
- function toIsoString(fullDate) {
13
- const isoString = (0, luxon_date_time_conversion_1.toLuxonDateTime)(fullDate).setZone(timezones_1.utcTimezone).toISO();
14
- /** Ignore this edge case in the types and idk how to trigger it. */
15
- /* c8 ignore next 3 */
16
- if (!isoString) {
17
- throw new Error(`Unable to get ISO string for '${JSON.stringify(fullDate)}'`);
18
- }
19
- return isoString;
20
- }
21
- exports.toIsoString = toIsoString;
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getNowFullDate = exports.toNewTimezone = exports.createFullDate = exports.createUtcFullDate = exports.createFullDateInUserTimezone = void 0;
4
- const luxon_1 = require("luxon");
5
- const run_time_assertions_1 = require("run-time-assertions");
6
- const timezones_1 = require("../timezone/timezones");
7
- const is_valid_full_date_1 = require("./is-valid-full-date");
8
- const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
9
- const string_parsing_1 = require("./string-parsing");
10
- function createFullDateInUserTimezone(dateLike) {
11
- return createFullDate(dateLike, timezones_1.userTimezone);
12
- }
13
- exports.createFullDateInUserTimezone = createFullDateInUserTimezone;
14
- function createUtcFullDate(dateLike) {
15
- return createFullDate(dateLike, timezones_1.utcTimezone);
16
- }
17
- exports.createUtcFullDate = createUtcFullDate;
18
- /**
19
- * Parses the given dateLike and then reads the fullDate properties from that parsed value as if it
20
- * were in the given timezone.
21
- */
22
- function createFullDate(
23
- /** The original date representation to be converted into a FullDate. */
24
- dateLike,
25
- /** The timezone that this date/time is meant for / originated from. */
26
- timezone) {
27
- const dateTime = convertDateLikeToLuxonDateTime(dateLike, timezone);
28
- if (!dateTime || !dateTime.isValid) {
29
- throw new Error(`Failed to parse date input '${dateLike}'`);
30
- }
31
- return (0, luxon_date_time_conversion_1.parseLuxonDateTime)(dateTime, timezone);
32
- }
33
- exports.createFullDate = createFullDate;
34
- /**
35
- * Creates and returns a new FullDate object with its values shifted to be the same original time
36
- * but represented in a new timezone.
37
- */
38
- function toNewTimezone(fullDate, timezone) {
39
- if (fullDate.timezone === timezone) {
40
- return fullDate;
41
- }
42
- return createFullDate(fullDate, timezone);
43
- }
44
- exports.toNewTimezone = toNewTimezone;
45
- function lastDitchConversion(dateLike) {
46
- luxon_1.DateTime.fromFormat;
47
- /** As any cast for last ditch effort to convert the dateLike into a date. */
48
- const dateTime = luxon_1.DateTime.fromJSDate(new Date(dateLike));
49
- if (dateTime.isValid) {
50
- return dateTime;
51
- }
52
- else {
53
- return undefined;
54
- }
55
- }
56
- function convertDateLikeToLuxonDateTime(dateLike, timezone) {
57
- if ((0, is_valid_full_date_1.isValidFullDate)(dateLike)) {
58
- dateLike = (0, luxon_date_time_conversion_1.toLuxonDateTime)(dateLike).toMillis();
59
- }
60
- if (luxon_1.DateTime.isDateTime(dateLike)) {
61
- return dateLike.setZone(timezone);
62
- }
63
- else if ((0, run_time_assertions_1.isRunTimeType)(dateLike, 'number')) {
64
- return luxon_1.DateTime.fromMillis(dateLike, { zone: timezones_1.utcTimezone }).setZone(timezone);
65
- }
66
- else if ((0, run_time_assertions_1.isRunTimeType)(dateLike, 'string')) {
67
- const parsedStringDate = (0, string_parsing_1.parseDateString)(dateLike, timezone);
68
- if (parsedStringDate) {
69
- return parsedStringDate;
70
- }
71
- }
72
- else if (dateLike instanceof Date) {
73
- const dateTime = luxon_1.DateTime.fromJSDate(dateLike);
74
- return dateTime.setZone(timezone);
75
- }
76
- return lastDitchConversion(dateLike);
77
- }
78
- function getNowFullDate(timezone) {
79
- return createFullDate(Date.now(), timezone);
80
- }
81
- exports.getNowFullDate = getNowFullDate;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatPresets = void 0;
4
- const luxon_1 = require("luxon");
5
- /**
6
- * Format preset re-exported from luxon to be used with toLocaleString. To see examples of all
7
- * presets, go here: https://moment.github.io/luxon/#/formatting?id=presets
8
- */
9
- exports.formatPresets = {
10
- DateShort: luxon_1.DateTime.DATE_SHORT,
11
- DateMed: luxon_1.DateTime.DATE_MED,
12
- DateMedWithWeekday: luxon_1.DateTime.DATE_MED_WITH_WEEKDAY,
13
- DateFull: luxon_1.DateTime.DATE_FULL,
14
- DateHuge: luxon_1.DateTime.DATE_HUGE,
15
- TimeSimple: luxon_1.DateTime.TIME_SIMPLE,
16
- TimeWithSeconds: luxon_1.DateTime.TIME_WITH_SECONDS,
17
- TimeWithShortOffset: luxon_1.DateTime.TIME_WITH_SHORT_OFFSET,
18
- TimeWithLongOffset: luxon_1.DateTime.TIME_WITH_LONG_OFFSET,
19
- Time24Simple: luxon_1.DateTime.TIME_24_SIMPLE,
20
- Time24WithSeconds: luxon_1.DateTime.TIME_24_WITH_SECONDS,
21
- Time24WithShortOffset: luxon_1.DateTime.TIME_24_WITH_SHORT_OFFSET,
22
- Time24WithLongOffset: luxon_1.DateTime.TIME_24_WITH_LONG_OFFSET,
23
- DatetimeShort: luxon_1.DateTime.DATETIME_SHORT,
24
- DatetimeShortWithSeconds: luxon_1.DateTime.DATETIME_SHORT_WITH_SECONDS,
25
- DatetimeMed: luxon_1.DateTime.DATETIME_MED,
26
- DatetimeMedWithSeconds: luxon_1.DateTime.DATETIME_MED_WITH_SECONDS,
27
- DatetimeMedWithWeekday: luxon_1.DateTime.DATETIME_MED_WITH_WEEKDAY,
28
- DatetimeFull: luxon_1.DateTime.DATETIME_FULL,
29
- DatetimeFullWithSeconds: luxon_1.DateTime.DATETIME_FULL_WITH_SECONDS,
30
- DatetimeHuge: luxon_1.DateTime.DATETIME_HUGE,
31
- DatetimeHugeWithSeconds: luxon_1.DateTime.DATETIME_HUGE_WITH_SECONDS,
32
- };
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fullDateShape = exports.datePartShape = exports.timePartShape = exports.dateFullDateKeys = exports.timeFullDateKeys = exports.FullDatePartEnum = void 0;
4
- const object_shape_tester_1 = require("object-shape-tester");
5
- const timezones_1 = require("../timezone/timezones");
6
- /**
7
- * Represents various parts of a FullDate. Each value is also a valid "type" attribute for an
8
- * <input> HTML element.
9
- */
10
- var FullDatePartEnum;
11
- (function (FullDatePartEnum) {
12
- FullDatePartEnum["Date"] = "date";
13
- FullDatePartEnum["Time"] = "time";
14
- FullDatePartEnum["DateTime"] = "datetime-local";
15
- })(FullDatePartEnum || (exports.FullDatePartEnum = FullDatePartEnum = {}));
16
- exports.timeFullDateKeys = [
17
- 'hour',
18
- 'minute',
19
- 'second',
20
- 'millisecond',
21
- ];
22
- exports.dateFullDateKeys = [
23
- 'year',
24
- 'month',
25
- 'day',
26
- ];
27
- exports.timePartShape = (0, object_shape_tester_1.defineShape)({
28
- /** Hour of the day in 24 time: 0-23 */
29
- hour: 14,
30
- /** Minute of the hour: 0-59 */
31
- minute: 19,
32
- /** Second of the minute: 0-59 */
33
- second: 7,
34
- /** Millisecond of the second: 0-999 */
35
- millisecond: 877,
36
- /** The timezone that this date/time is meant for / originated from. */
37
- timezone: timezones_1.utcTimezone,
38
- });
39
- exports.datePartShape = (0, object_shape_tester_1.defineShape)({
40
- /**
41
- * The full, four digit year.
42
- *
43
- * @example
44
- * 2023;
45
- */
46
- year: 2023,
47
- /** A month of the year: 1-12 */
48
- month: 6,
49
- /** A day of the month: 1-31 depending on the month */
50
- day: 5,
51
- /** The timezone that this date/time is meant for / originated from. */
52
- timezone: timezones_1.utcTimezone,
53
- });
54
- exports.fullDateShape = (0, object_shape_tester_1.defineShape)((0, object_shape_tester_1.and)(exports.datePartShape, exports.timePartShape));
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasTimezone = exports.isValidFullDate = exports.assertIsValidFullDate = void 0;
4
- const object_shape_tester_1 = require("object-shape-tester");
5
- const timezone_checks_1 = require("../timezone/timezone-checks");
6
- const full_date_shape_1 = require("./full-date-shape");
7
- const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
8
- function assertIsValidFullDate(input) {
9
- (0, object_shape_tester_1.assertValidShape)(input, full_date_shape_1.fullDateShape);
10
- (0, timezone_checks_1.assertValidTimezone)(input.timezone);
11
- /** Check that the input can be converted to a luxon date correctly. */
12
- (0, luxon_date_time_conversion_1.toLuxonDateTime)(input);
13
- }
14
- exports.assertIsValidFullDate = assertIsValidFullDate;
15
- function isValidFullDate(input) {
16
- try {
17
- assertIsValidFullDate(input);
18
- return true;
19
- }
20
- catch (error) {
21
- return false;
22
- }
23
- }
24
- exports.isValidFullDate = isValidFullDate;
25
- function hasTimezone(input, timezone) {
26
- return input.timezone === timezone;
27
- }
28
- exports.hasTimezone = hasTimezone;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseLuxonDateTime = exports.toLuxonDateTime = void 0;
4
- const common_1 = require("@augment-vir/common");
5
- const luxon_1 = require("luxon");
6
- /**
7
- * Converts a FullDate object into a Luxon DateTime library. This is only needed if you need complex
8
- * operations on dates. It does, however, internally power a lot of the date-vir functionality as it
9
- * uses the Luxon library for conversions between timezones.
10
- */
11
- function toLuxonDateTime(fullDateInput) {
12
- const dateTime = luxon_1.DateTime.fromObject((0, common_1.omitObjectKeys)(fullDateInput, ['timezone']), {
13
- zone: fullDateInput.timezone,
14
- });
15
- /** Ignore this edge case in coverage cause idk how to trigger it. */
16
- /* c8 ignore next 3 */
17
- if (!dateTime.isValid) {
18
- throw new Error(dateTime.invalidExplanation ?? undefined);
19
- }
20
- return dateTime;
21
- }
22
- exports.toLuxonDateTime = toLuxonDateTime;
23
- /**
24
- * Convert a Luxon DateTime object into a DateTime object. Used internally inside of date-vir, but
25
- * could be helpful if you need it. Usually you should prefer using the createFullDate function
26
- * instead.
27
- */
28
- function parseLuxonDateTime(dateTimeInput, forcedTimezone) {
29
- if (!dateTimeInput.isValid) {
30
- throw new Error(`Invalid input: '${dateTimeInput.toISO()}'`);
31
- }
32
- return {
33
- day: dateTimeInput.day,
34
- month: dateTimeInput.month,
35
- year: dateTimeInput.year,
36
- hour: dateTimeInput.hour,
37
- minute: dateTimeInput.minute,
38
- second: dateTimeInput.second,
39
- millisecond: dateTimeInput.millisecond,
40
- timezone: forcedTimezone ?? dateTimeInput.zoneName,
41
- };
42
- }
43
- exports.parseLuxonDateTime = parseLuxonDateTime;
@@ -1,48 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseInputElementValue = exports.parseStrangeString = void 0;
4
- const luxon_1 = require("luxon");
5
- const run_time_assertions_1 = require("run-time-assertions");
6
- const create_full_date_1 = require("./create-full-date");
7
- const luxon_date_time_conversion_1 = require("./luxon-date-time-conversion");
8
- /**
9
- * Parses any strangely formatted dateString using the given formatString and timezone.
10
- *
11
- * This is much more flexible than createFullDate but createFullDate should be preferred in
12
- * situations where it works.
13
- *
14
- * The formatString input is passed to Luxon. All format options are listed here:
15
- * https://moment.github.io/luxon/#/parsing?id=table-of-tokens
16
- */
17
- function parseStrangeString({ dateString, formatString, timezone, }) {
18
- try {
19
- const dateTime = luxon_1.DateTime.fromFormat(dateString, formatString, {
20
- zone: timezone,
21
- setZone: true,
22
- });
23
- return (0, luxon_date_time_conversion_1.parseLuxonDateTime)(dateTime);
24
- }
25
- catch (error) {
26
- throw new Error(`Failed to parse string '${dateString}' with format '${formatString}'`);
27
- }
28
- }
29
- exports.parseStrangeString = parseStrangeString;
30
- /**
31
- * Read either an HTMLInputElement's value directly, or the value string retrieved from an
32
- * HTMLInputElement. Handles both type="date" and type="time" <input> elements.
33
- */
34
- function parseInputElementValue(elementOrValue, timezone) {
35
- if (!elementOrValue) {
36
- return undefined;
37
- }
38
- const value = (0, run_time_assertions_1.isRunTimeType)(elementOrValue, 'string')
39
- ? elementOrValue
40
- : elementOrValue.value;
41
- try {
42
- return (0, create_full_date_1.createFullDate)(value, timezone);
43
- }
44
- catch (error) {
45
- return undefined;
46
- }
47
- }
48
- exports.parseInputElementValue = parseInputElementValue;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseDateString = void 0;
4
- const luxon_1 = require("luxon");
5
- /**
6
- * These formats are for luxon, documented here:
7
- * https://moment.github.io/luxon/#/parsing?id=table-of-tokens
8
- */
9
- const knownStringFormats = [
10
- // 1-2024
11
- 'L-y',
12
- // jan-2021
13
- 'LLL-y',
14
- // january-2021
15
- 'LLLL-y',
16
- ];
17
- function parseDateString(dateString, timezone) {
18
- const isoAttempt = luxon_1.DateTime.fromISO(dateString, { zone: timezone });
19
- if (isoAttempt.isValid) {
20
- return isoAttempt;
21
- }
22
- let finalizedDateTime;
23
- knownStringFormats.some((format) => {
24
- const dateTimeAttempt = luxon_1.DateTime.fromFormat(dateString, format, { zone: timezone });
25
- if (!dateTimeAttempt.isValid) {
26
- return false;
27
- }
28
- finalizedDateTime = dateTimeAttempt;
29
- return true;
30
- });
31
- return finalizedDateTime;
32
- }
33
- exports.parseDateString = parseDateString;
package/dist/cjs/index.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./date-operations/calculate-relative-date"), exports);
18
- __exportStar(require("./date-operations/combine-dates"), exports);
19
- __exportStar(require("./date-operations/diff-dates"), exports);
20
- __exportStar(require("./duration/duration"), exports);
21
- __exportStar(require("./duration/duration-unit"), exports);
22
- __exportStar(require("./duration/duration-utils"), exports);
23
- __exportStar(require("./extra-utils/date-transforms"), exports);
24
- __exportStar(require("./extra-utils/has-date-props"), exports);
25
- __exportStar(require("./extra-utils/js-date-conversion"), exports);
26
- __exportStar(require("./extra-utils/now"), exports);
27
- __exportStar(require("./extra-utils/zero"), exports);
28
- __exportStar(require("./formatting/formatted-string"), exports);
29
- __exportStar(require("./formatting/html-input"), exports);
30
- __exportStar(require("./formatting/relative-string"), exports);
31
- __exportStar(require("./formatting/simple-strings"), exports);
32
- __exportStar(require("./formatting/string-format-types"), exports);
33
- __exportStar(require("./formatting/timestamp"), exports);
34
- __exportStar(require("./full-date/create-full-date"), exports);
35
- __exportStar(require("./full-date/date-like"), exports);
36
- __exportStar(require("./full-date/format-presets"), exports);
37
- __exportStar(require("./full-date/full-date-shape"), exports);
38
- __exportStar(require("./full-date/is-valid-full-date"), exports);
39
- __exportStar(require("./full-date/luxon-date-time-conversion"), exports);
40
- __exportStar(require("./full-date/parsing"), exports);
41
- __exportStar(require("./locales"), exports);
42
- __exportStar(require("./timezone/timezone-checks"), exports);
43
- __exportStar(require("./timezone/timezone-names"), exports);
44
- __exportStar(require("./timezone/timezones"), exports);
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.userLocale = void 0;
4
- const luxon_1 = require("luxon");
5
- exports.userLocale = luxon_1.Settings.defaultLocale;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidTimezone = exports.assertValidTimezone = void 0;
4
- const luxon_1 = require("luxon");
5
- /**
6
- * Asserts that the given timezoneName is a valid timezone name.
7
- *
8
- * Note that this may actually allow names beyond what is currently in the exact TimezoneName type,
9
- * because this function uses luxon to check that it is able to generate a date with the given
10
- * timezone, regardless of whether it's in our typed list or not.
11
- */
12
- function assertValidTimezone(potentialTimezoneName) {
13
- if (!luxon_1.Info.isValidIANAZone(potentialTimezoneName)) {
14
- throw new Error(`'${potentialTimezoneName}' is not a valid time zone`);
15
- }
16
- }
17
- exports.assertValidTimezone = assertValidTimezone;
18
- /**
19
- * Checks that the given timezoneName is a valid timezone name.
20
- *
21
- * Note that this may actually allow names beyond what is currently in the exact TimezoneName type,
22
- * because this function uses luxon to check that it is able to generate a date with the given
23
- * timezone, regardless of whether it's in our typed list or not.
24
- */
25
- function isValidTimezone(potentialTimezoneName) {
26
- try {
27
- assertValidTimezone(potentialTimezoneName);
28
- return true;
29
- }
30
- catch (error) {
31
- return false;
32
- }
33
- }
34
- exports.isValidTimezone = isValidTimezone;