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
@@ -0,0 +1,95 @@
1
+ import { type DurationBySelection, type DurationUnitSelection, type RoundOptions } from '@date-vir/duration';
2
+ import { FullDate } from '../full-date/full-date-shape.js';
3
+ /**
4
+ * Diffs two dates and returns the diff in the specified unit or units. When a multiple units are
5
+ * provided with the `units` input property, an array is returned with the full diff duration
6
+ * contained in each entry in the requested unit.
7
+ *
8
+ * Note: when years, quarters, or months are used for the unit, "long term" durations are used to
9
+ * calculate the diff. See more details here:
10
+ * https://moment.github.io/luxon/#/math?id=casual-vs-longterm-conversion-accuracy
11
+ *
12
+ * @category Calculation
13
+ * @example
14
+ *
15
+ * ```ts
16
+ * import {diffDates, DurationUnit} from 'date-vir';
17
+ *
18
+ * const exampleDate: FullDate = {
19
+ * year: 2024,
20
+ * month: 1,
21
+ * day: 5,
22
+ * hour: 1,
23
+ * minute: 1,
24
+ * second: 1,
25
+ * millisecond: 1,
26
+ * timezone: 'UTC',
27
+ * };
28
+ *
29
+ * // get the diff in days
30
+ * diffDates({start: exampleDate, end: {...exampleDate, day: 6}}, {days: true}); // {days: 1}
31
+ * // get the full diff separately in days and also years
32
+ * diffDates(
33
+ * {
34
+ * start: exampleDate,
35
+ * end: {
36
+ * ...exampleDate,
37
+ * day: exampleDate.day + 1,
38
+ * hour: exampleDate.hour + 3,
39
+ * },
40
+ * },
41
+ * {
42
+ * days: true,
43
+ * hours: true,
44
+ * },
45
+ * );
46
+ * // {days: 1, hours: 3}
47
+ * ```
48
+ */
49
+ export declare function diffDates<const SelectedUnits extends Readonly<DurationUnitSelection>>({ start, end, }: Readonly<{
50
+ start: Readonly<FullDate>;
51
+ end: Readonly<FullDate>;
52
+ }>,
53
+ /** Which units the output should contain. */
54
+ units: SelectedUnits, options?: Readonly<RoundOptions>): DurationBySelection<SelectedUnits>;
55
+ /**
56
+ * Checks if `fullDate` is after `relativeTo`.
57
+ *
58
+ * @category Calculation
59
+ * @example
60
+ *
61
+ * ```ts
62
+ * import {isDateAfter, type FullDate} from 'date-vir';
63
+ *
64
+ * const exampleDate: FullDate = {
65
+ * year: 2024,
66
+ * month: 1,
67
+ * day: 5,
68
+ * hour: 1,
69
+ * minute: 1,
70
+ * second: 1,
71
+ * millisecond: 1,
72
+ * timezone: 'UTC',
73
+ * };
74
+ *
75
+ * isDateAfter({
76
+ * fullDate: exampleDate,
77
+ * relativeTo: {
78
+ * ...exampleDate,
79
+ * year: 1900,
80
+ * },
81
+ * }); // `true`
82
+ *
83
+ * isDateAfter({
84
+ * fullDate: exampleDate,
85
+ * relativeTo: {
86
+ * ...exampleDate,
87
+ * year: 3000,
88
+ * },
89
+ * }); // `false`
90
+ * ```
91
+ */
92
+ export declare function isDateAfter({ relativeTo, fullDate, }: {
93
+ relativeTo: Readonly<FullDate>;
94
+ fullDate: Readonly<FullDate>;
95
+ }): boolean;
@@ -0,0 +1,124 @@
1
+ import { DurationUnit, flattenUnitSelection, roundDuration, } from '@date-vir/duration';
2
+ import { toLuxonDateTime } from '../full-date/luxon-date-time-conversion.js';
3
+ const conversionAccuracies = {
4
+ [DurationUnit.Years]: 'longterm',
5
+ [DurationUnit.Quarters]: 'longterm',
6
+ [DurationUnit.Months]: 'longterm',
7
+ [DurationUnit.Weeks]: 'casual',
8
+ [DurationUnit.Days]: 'casual',
9
+ [DurationUnit.Hours]: 'casual',
10
+ [DurationUnit.Minutes]: 'casual',
11
+ [DurationUnit.Seconds]: 'casual',
12
+ [DurationUnit.Milliseconds]: 'casual',
13
+ };
14
+ function getHighestPriorityConversionAccuracy(units) {
15
+ if (units.some((unit) => conversionAccuracies[unit] === 'longterm')) {
16
+ return 'longterm';
17
+ }
18
+ else {
19
+ return 'casual';
20
+ }
21
+ }
22
+ /**
23
+ * Diffs two dates and returns the diff in the specified unit or units. When a multiple units are
24
+ * provided with the `units` input property, an array is returned with the full diff duration
25
+ * contained in each entry in the requested unit.
26
+ *
27
+ * Note: when years, quarters, or months are used for the unit, "long term" durations are used to
28
+ * calculate the diff. See more details here:
29
+ * https://moment.github.io/luxon/#/math?id=casual-vs-longterm-conversion-accuracy
30
+ *
31
+ * @category Calculation
32
+ * @example
33
+ *
34
+ * ```ts
35
+ * import {diffDates, DurationUnit} from 'date-vir';
36
+ *
37
+ * const exampleDate: FullDate = {
38
+ * year: 2024,
39
+ * month: 1,
40
+ * day: 5,
41
+ * hour: 1,
42
+ * minute: 1,
43
+ * second: 1,
44
+ * millisecond: 1,
45
+ * timezone: 'UTC',
46
+ * };
47
+ *
48
+ * // get the diff in days
49
+ * diffDates({start: exampleDate, end: {...exampleDate, day: 6}}, {days: true}); // {days: 1}
50
+ * // get the full diff separately in days and also years
51
+ * diffDates(
52
+ * {
53
+ * start: exampleDate,
54
+ * end: {
55
+ * ...exampleDate,
56
+ * day: exampleDate.day + 1,
57
+ * hour: exampleDate.hour + 3,
58
+ * },
59
+ * },
60
+ * {
61
+ * days: true,
62
+ * hours: true,
63
+ * },
64
+ * );
65
+ * // {days: 1, hours: 3}
66
+ * ```
67
+ */
68
+ export function diffDates({ start, end, },
69
+ /** Which units the output should contain. */
70
+ units, options = {}) {
71
+ const luxonDateStart = toLuxonDateTime(start);
72
+ const luxonDateEnd = toLuxonDateTime(end);
73
+ const selectedUnits = flattenUnitSelection(units);
74
+ const conversionAccuracy = getHighestPriorityConversionAccuracy(selectedUnits);
75
+ const additiveDiff = luxonDateEnd
76
+ .diff(luxonDateStart, selectedUnits, {
77
+ conversionAccuracy,
78
+ })
79
+ .toObject();
80
+ return roundDuration(additiveDiff, options);
81
+ }
82
+ /**
83
+ * Checks if `fullDate` is after `relativeTo`.
84
+ *
85
+ * @category Calculation
86
+ * @example
87
+ *
88
+ * ```ts
89
+ * import {isDateAfter, type FullDate} from 'date-vir';
90
+ *
91
+ * const exampleDate: FullDate = {
92
+ * year: 2024,
93
+ * month: 1,
94
+ * day: 5,
95
+ * hour: 1,
96
+ * minute: 1,
97
+ * second: 1,
98
+ * millisecond: 1,
99
+ * timezone: 'UTC',
100
+ * };
101
+ *
102
+ * isDateAfter({
103
+ * fullDate: exampleDate,
104
+ * relativeTo: {
105
+ * ...exampleDate,
106
+ * year: 1900,
107
+ * },
108
+ * }); // `true`
109
+ *
110
+ * isDateAfter({
111
+ * fullDate: exampleDate,
112
+ * relativeTo: {
113
+ * ...exampleDate,
114
+ * year: 3000,
115
+ * },
116
+ * }); // `false`
117
+ * ```
118
+ */
119
+ export function isDateAfter({ relativeTo, fullDate, }) {
120
+ return (diffDates({
121
+ start: relativeTo,
122
+ end: fullDate,
123
+ }, { milliseconds: true }).milliseconds >= 0);
124
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A partial {@link FullDate} instance that has the highest value for each time property.
3
+ *
4
+ * @category Constants
5
+ */
6
+ export declare const endTime: {
7
+ readonly hour: 23;
8
+ readonly minute: 59;
9
+ readonly second: 59;
10
+ readonly millisecond: 999;
11
+ };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A partial {@link FullDate} instance that has the highest value for each time property.
3
+ *
4
+ * @category Constants
5
+ */
6
+ export const endTime = {
7
+ hour: 23,
8
+ minute: 59,
9
+ second: 59,
10
+ millisecond: 999,
11
+ };
@@ -0,0 +1,35 @@
1
+ import { type PartialWithUndefined, type SetRequiredAndNotNull } from '@augment-vir/common';
2
+ import { type FullDate } from '../full-date/full-date-shape.js';
3
+ import type { Timezone } from '../timezone/timezones.js';
4
+ /**
5
+ * Checks that the input has all the requested {@link FullDate} keys.
6
+ *
7
+ * @category Util
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * import {hasFullDateKeys} from 'date-vir';
12
+ *
13
+ * hasFullDateKeys({year: 2024}, ['year']); // `true`
14
+ * hasFullDateKeys({year: 2024}, ['day']); // `false`
15
+ * ```
16
+ */
17
+ export declare function hasFullDateKeys<SpecificTimezone extends Timezone, PartialFullDate extends PartialWithUndefined<FullDate<SpecificTimezone>>,
18
+ /** A union of strings. */
19
+ RequiredKeys extends keyof FullDate<SpecificTimezone>>(partialFullDate: PartialWithUndefined<FullDate<SpecificTimezone>>, keys: ReadonlyArray<RequiredKeys>): partialFullDate is SetRequiredAndNotNull<PartialFullDate, RequiredKeys>;
20
+ /**
21
+ * Asserts that the input has all the requested {@link FullDate} keys.
22
+ *
23
+ * @category Util
24
+ * @example
25
+ *
26
+ * ```ts
27
+ * import {assertHasFullDateKeys} from 'date-vir';
28
+ *
29
+ * assertHasFullDateKeys({year: 2024}, ['year']); // passes
30
+ * assertHasFullDateKeys({year: 2024}, ['day']); // fails
31
+ * ```
32
+ */
33
+ export declare function assertHasFullDateKeys<SpecificTimezone extends Timezone, PartialFullDate extends PartialWithUndefined<FullDate<SpecificTimezone>>,
34
+ /** A union of strings. */
35
+ RequiredKeys extends keyof FullDate<SpecificTimezone>>(partialFullDate: PartialWithUndefined<FullDate<SpecificTimezone>>, keys: ReadonlyArray<RequiredKeys>): asserts partialFullDate is SetRequiredAndNotNull<PartialFullDate, RequiredKeys>;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Checks that the input has all the requested {@link FullDate} keys.
3
+ *
4
+ * @category Util
5
+ * @example
6
+ *
7
+ * ```ts
8
+ * import {hasFullDateKeys} from 'date-vir';
9
+ *
10
+ * hasFullDateKeys({year: 2024}, ['year']); // `true`
11
+ * hasFullDateKeys({year: 2024}, ['day']); // `false`
12
+ * ```
13
+ */
14
+ export function hasFullDateKeys(partialFullDate, keys) {
15
+ try {
16
+ assertHasFullDateKeys(partialFullDate, keys);
17
+ return true;
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ }
23
+ /**
24
+ * Asserts that the input has all the requested {@link FullDate} keys.
25
+ *
26
+ * @category Util
27
+ * @example
28
+ *
29
+ * ```ts
30
+ * import {assertHasFullDateKeys} from 'date-vir';
31
+ *
32
+ * assertHasFullDateKeys({year: 2024}, ['year']); // passes
33
+ * assertHasFullDateKeys({year: 2024}, ['day']); // fails
34
+ * ```
35
+ */
36
+ export function assertHasFullDateKeys(partialFullDate, keys) {
37
+ const missingKeys = [];
38
+ keys.forEach((key) => {
39
+ if (partialFullDate[key] == undefined) {
40
+ missingKeys.push(key);
41
+ }
42
+ });
43
+ if (missingKeys.length) {
44
+ throw new Error(`Missing required FullDate key(s): ${missingKeys.join(', ')}`);
45
+ }
46
+ }
@@ -0,0 +1,26 @@
1
+ import { FullDate } from '../full-date/full-date-shape.js';
2
+ /**
3
+ * Convert a {@link FullDate} from a built-in JS
4
+ * [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date).
5
+ *
6
+ * @category Conversion
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {toJsDate, type FullDate} from 'date-vir';
11
+ *
12
+ * const exampleDate: Readonly<FullDate> = {
13
+ * year: 2024,
14
+ * month: 1,
15
+ * day: 5,
16
+ * hour: 1,
17
+ * minute: 1,
18
+ * second: 1,
19
+ * millisecond: 1,
20
+ * timezone: 'UTC',
21
+ * };
22
+ *
23
+ * toJsDate(exampleDate);
24
+ * ```
25
+ */
26
+ export declare function toJsDate(fullDate: Readonly<FullDate>): Date;
@@ -0,0 +1,28 @@
1
+ import { toTimestamp } from '../formatting/timestamp.js';
2
+ /**
3
+ * Convert a {@link FullDate} from a built-in JS
4
+ * [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date).
5
+ *
6
+ * @category Conversion
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {toJsDate, type FullDate} from 'date-vir';
11
+ *
12
+ * const exampleDate: Readonly<FullDate> = {
13
+ * year: 2024,
14
+ * month: 1,
15
+ * day: 5,
16
+ * hour: 1,
17
+ * minute: 1,
18
+ * second: 1,
19
+ * millisecond: 1,
20
+ * timezone: 'UTC',
21
+ * };
22
+ *
23
+ * toJsDate(exampleDate);
24
+ * ```
25
+ */
26
+ export function toJsDate(fullDate) {
27
+ return new Date(toTimestamp(fullDate));
28
+ }
@@ -0,0 +1,56 @@
1
+ import { UtcIsoString } from '../formatting/string-format-types.js';
2
+ import { FullDate } from '../full-date/full-date-shape.js';
3
+ import { Timezone, UtcTimezone } from '../timezone/timezones.js';
4
+ /**
5
+ * Get the time right now as a UTC ISO.
6
+ *
7
+ * @category Now
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * import {getNowInIsoString} from 'date-vir';
12
+ *
13
+ * getNowInIsoString();
14
+ * ```
15
+ */
16
+ export declare function getNowInIsoString(): UtcIsoString;
17
+ /**
18
+ * Get the time right now as a {@link FullDate} represented in the current user's timezone.
19
+ *
20
+ * @category Now
21
+ * @example
22
+ *
23
+ * ```ts
24
+ * import {getNowInUserTimezone} from 'date-vir';
25
+ *
26
+ * getNowInUserTimezone();
27
+ * ```
28
+ */
29
+ export declare function getNowInUserTimezone(): FullDate;
30
+ /**
31
+ * Get the time right now as a {@link FullDate} represented in the UTC timezone.
32
+ *
33
+ * @category Now
34
+ * @example
35
+ *
36
+ * ```ts
37
+ * import {getNowInUtcTimezone} from 'date-vir';
38
+ *
39
+ * getNowInUtcTimezone();
40
+ * ```
41
+ */
42
+ export declare function getNowInUtcTimezone(): FullDate<UtcTimezone>;
43
+ /**
44
+ * Get the time right now as a {@link FullDate} represented in the given timezone.
45
+ *
46
+ * @category Now
47
+ * @example
48
+ *
49
+ * ```ts
50
+ * import {getNowFullDate, utcTimezone, timezones} from 'date-vir';
51
+ *
52
+ * getNowFullDate(utcTimezone);
53
+ * getNowFullDate(timezones['Australia/Brisbane']);
54
+ * ```
55
+ */
56
+ export declare function getNowFullDate<const SpecificTimezone extends Timezone>(timezone: SpecificTimezone): FullDate<SpecificTimezone>;
@@ -0,0 +1,68 @@
1
+ import { toUtcIsoString } from '../formatting/timestamp.js';
2
+ import { createFullDate } from '../full-date/create-full-date.js';
3
+ import { userTimezone, utcTimezone } from '../timezone/timezones.js';
4
+ /**
5
+ * Get the time right now as a UTC ISO.
6
+ *
7
+ * @category Now
8
+ * @example
9
+ *
10
+ * ```ts
11
+ * import {getNowInIsoString} from 'date-vir';
12
+ *
13
+ * getNowInIsoString();
14
+ * ```
15
+ */
16
+ export function getNowInIsoString() {
17
+ /**
18
+ * The time zone doesn't matter here because the ISO string will be identical for a given date
19
+ * no matter what its timezone is.
20
+ */
21
+ return toUtcIsoString(getNowFullDate(utcTimezone));
22
+ }
23
+ /**
24
+ * Get the time right now as a {@link FullDate} represented in the current user's timezone.
25
+ *
26
+ * @category Now
27
+ * @example
28
+ *
29
+ * ```ts
30
+ * import {getNowInUserTimezone} from 'date-vir';
31
+ *
32
+ * getNowInUserTimezone();
33
+ * ```
34
+ */
35
+ export function getNowInUserTimezone() {
36
+ return getNowFullDate(userTimezone);
37
+ }
38
+ /**
39
+ * Get the time right now as a {@link FullDate} represented in the UTC timezone.
40
+ *
41
+ * @category Now
42
+ * @example
43
+ *
44
+ * ```ts
45
+ * import {getNowInUtcTimezone} from 'date-vir';
46
+ *
47
+ * getNowInUtcTimezone();
48
+ * ```
49
+ */
50
+ export function getNowInUtcTimezone() {
51
+ return getNowFullDate(utcTimezone);
52
+ }
53
+ /**
54
+ * Get the time right now as a {@link FullDate} represented in the given timezone.
55
+ *
56
+ * @category Now
57
+ * @example
58
+ *
59
+ * ```ts
60
+ * import {getNowFullDate, utcTimezone, timezones} from 'date-vir';
61
+ *
62
+ * getNowFullDate(utcTimezone);
63
+ * getNowFullDate(timezones['Australia/Brisbane']);
64
+ * ```
65
+ */
66
+ export function getNowFullDate(timezone) {
67
+ return createFullDate(Date.now(), timezone);
68
+ }
@@ -0,0 +1,27 @@
1
+ import { FullDate } from '../full-date/full-date-shape.js';
2
+ import { Timezone } from '../timezone/timezones.js';
3
+ /**
4
+ * Override the initial provided FullDate with all subsequent FullDate parts.
5
+ *
6
+ * @category Util
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * import {overrideDateParts, type FullDate} from 'date-vir';
11
+ *
12
+ * const exampleDate: Readonly<FullDate> = {
13
+ * year: 2024,
14
+ * month: 1,
15
+ * day: 5,
16
+ * hour: 1,
17
+ * minute: 1,
18
+ * second: 1,
19
+ * millisecond: 1,
20
+ * timezone: 'UTC',
21
+ * };
22
+ *
23
+ * overrideDateParts(exampleDate, {day: 20}, {second: 10});
24
+ * // `{year: 2024, month: 1, day: 20, hour: 1, minute: 1, second: 10, millisecond: 1, timezone: 'UTC'}`
25
+ * ```
26
+ */
27
+ export declare function overrideDateParts<const SpecificTimezone extends Timezone>(date: FullDate<SpecificTimezone>, ...overrides: Partial<FullDate<SpecificTimezone>>[]): FullDate<SpecificTimezone>;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Override the initial provided FullDate with all subsequent FullDate parts.
3
+ *
4
+ * @category Util
5
+ * @example
6
+ *
7
+ * ```ts
8
+ * import {overrideDateParts, type FullDate} from 'date-vir';
9
+ *
10
+ * const exampleDate: Readonly<FullDate> = {
11
+ * year: 2024,
12
+ * month: 1,
13
+ * day: 5,
14
+ * hour: 1,
15
+ * minute: 1,
16
+ * second: 1,
17
+ * millisecond: 1,
18
+ * timezone: 'UTC',
19
+ * };
20
+ *
21
+ * overrideDateParts(exampleDate, {day: 20}, {second: 10});
22
+ * // `{year: 2024, month: 1, day: 20, hour: 1, minute: 1, second: 10, millisecond: 1, timezone: 'UTC'}`
23
+ * ```
24
+ */
25
+ export function overrideDateParts(date, ...overrides) {
26
+ return Object.assign({}, date, ...overrides);
27
+ }
@@ -0,0 +1,109 @@
1
+ import { TimeKey } from '../full-date/full-date-parts.js';
2
+ import { FullDate } from '../full-date/full-date-shape.js';
3
+ import { Timezone } from '../timezone/timezones.js';
4
+ /**
5
+ * A {@link FullDate} instance that has the lowest, valid, non-negative, value for each property.
6
+ *
7
+ * @category Constants
8
+ */
9
+ export declare const zeroDate: {
10
+ readonly year: 0;
11
+ readonly month: 1;
12
+ readonly day: 1;
13
+ readonly hour: 0;
14
+ readonly minute: 0;
15
+ readonly second: 0;
16
+ readonly millisecond: 0;
17
+ };
18
+ /**
19
+ * A {@link FullDate} instance that has the lowest, valid, non-negative, value for each property.
20
+ * Alias for {@link zeroDate}.
21
+ *
22
+ * @category Constants
23
+ */
24
+ export declare const emptyDate: {
25
+ readonly year: 0;
26
+ readonly month: 1;
27
+ readonly day: 1;
28
+ readonly hour: 0;
29
+ readonly minute: 0;
30
+ readonly second: 0;
31
+ readonly millisecond: 0;
32
+ };
33
+ /**
34
+ * An object that contains the time parts of {@link FullDate} all set to `0`.
35
+ *
36
+ * @category Constants
37
+ */
38
+ export declare const zeroTime: Pick<{
39
+ year: 0;
40
+ month: 1;
41
+ day: 1;
42
+ hour: 0;
43
+ minute: 0;
44
+ second: 0;
45
+ millisecond: 0;
46
+ }, TimeKey>;
47
+ /**
48
+ * Clear the time parts of a {@link FullDate}, setting them all to `0`.
49
+ *
50
+ * @category Clear
51
+ * @example
52
+ *
53
+ * ```ts
54
+ * import {clearTime, type FullDate} from 'date-vir';
55
+ *
56
+ * const exampleDate: Readonly<FullDate> = {
57
+ * year: 2024,
58
+ * month: 1,
59
+ * day: 5,
60
+ * hour: 1,
61
+ * minute: 1,
62
+ * second: 1,
63
+ * millisecond: 1,
64
+ * timezone: 'UTC',
65
+ * };
66
+ *
67
+ * clearTime(exampleDate);
68
+ * // `{year: 2024, month: 1, day: 5, hour: 0, minute: 0, second: 0, millisecond: 0, timezone: 'UTC'}`
69
+ * ```
70
+ */
71
+ export declare function clearTime<const SpecificTimezone extends Timezone>(inputFullDate: Readonly<FullDate<SpecificTimezone>>): FullDate<SpecificTimezone>;
72
+ /**
73
+ * Clear all the selected parts of {@link FullDate} by setting them each to their lowest, valid
74
+ * value. See {@link zeroDate} for the lowest valid values for each property.
75
+ *
76
+ * @category Clear
77
+ * @example
78
+ *
79
+ * ```ts
80
+ * import {clearTime, type FullDate} from 'date-vir';
81
+ *
82
+ * const exampleDate: Readonly<FullDate> = {
83
+ * year: 2024,
84
+ * month: 1,
85
+ * day: 5,
86
+ * hour: 1,
87
+ * minute: 1,
88
+ * second: 1,
89
+ * millisecond: 1,
90
+ * timezone: 'UTC',
91
+ * };
92
+ *
93
+ * clearParts(exampleDate, [
94
+ * 'year',
95
+ * 'day',
96
+ * ]);
97
+ * // `{year: 0, month: 1, day: 1, hour: 1, minute: 1, second: 1, millisecond: 1, timezone: 'UTC'}`
98
+ * ```
99
+ */
100
+ export declare function clearParts<const SpecificTimezone extends Timezone>(inputFullDate: Readonly<FullDate<SpecificTimezone>>, parts: ReadonlyArray<Exclude<keyof FullDate, 'timezone'>>): {
101
+ hour: import("@date-vir/duration").Hour;
102
+ minute: import("@date-vir/duration").Minute;
103
+ second: import("@date-vir/duration").Minute;
104
+ millisecond: number;
105
+ year: number;
106
+ month: import("@date-vir/duration").MonthNumber;
107
+ day: import("@date-vir/duration").DayOfMonth;
108
+ timezone: SpecificTimezone;
109
+ };