@northguild/gmt 1.14.2 → 1.15.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 (137) hide show
  1. package/README.md +43 -13
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +1 -0
  4. package/dist/plain/calculate/diffDateAsDuration.js +1 -1
  5. package/dist/plain/calculate/index.d.ts +2 -1
  6. package/dist/plain/calculate/index.js +2 -1
  7. package/dist/plain/calculate/{weekOfYear.d.ts → weekOfYearForDate.d.ts} +0 -14
  8. package/dist/plain/calculate/weekOfYearForDate.js +28 -0
  9. package/dist/plain/calculate/weekOfYearForDateTime.d.ts +14 -0
  10. package/dist/plain/calculate/{weekOfYear.js → weekOfYearForDateTime.js} +1 -27
  11. package/dist/plain/format/formatCalendar.d.ts +2 -2
  12. package/dist/plain/format/formatDate.d.ts +3 -2
  13. package/dist/plain/format/formatDate.js +1 -1
  14. package/dist/plain/format/formatDateRange.d.ts +3 -2
  15. package/dist/plain/format/formatDateRange.js +1 -1
  16. package/dist/plain/format/formatDateTime.d.ts +3 -2
  17. package/dist/plain/format/formatDateTime.js +1 -1
  18. package/dist/plain/format/formatDateTimeRange.d.ts +3 -2
  19. package/dist/plain/format/formatDateTimeRange.js +1 -1
  20. package/dist/plain/format/formatDateTimeToParts.d.ts +3 -2
  21. package/dist/plain/format/formatDateTimeToParts.js +1 -1
  22. package/dist/plain/format/formatDateToParts.d.ts +3 -2
  23. package/dist/plain/format/formatDateToParts.js +1 -1
  24. package/dist/plain/format/formatRelativeDate.d.ts +3 -14
  25. package/dist/plain/format/formatRelativeDateTime.d.ts +3 -14
  26. package/dist/plain/format/formatRelativeTime.d.ts +3 -14
  27. package/dist/plain/format/formatTime.d.ts +2 -1
  28. package/dist/plain/get/getNowUnit.d.ts +2 -3
  29. package/dist/plain/interval/splitIntervalByUnitDate.js +1 -1
  30. package/dist/regex/calendar-date.d.ts +19 -0
  31. package/dist/regex/calendar-date.js +19 -10
  32. package/dist/regex/calendar-zoned-date-time.d.ts +45 -0
  33. package/dist/regex/calendar-zoned-date-time.js +45 -40
  34. package/dist/regex/date-time.d.ts +18 -0
  35. package/dist/regex/date-time.js +18 -1
  36. package/dist/regex/date.d.ts +16 -0
  37. package/dist/regex/date.js +16 -1
  38. package/dist/regex/http-date.d.ts +15 -0
  39. package/dist/regex/http-date.js +15 -6
  40. package/dist/regex/leap-second.d.ts +12 -0
  41. package/dist/regex/leap-second.js +12 -1
  42. package/dist/regex/rfc-2822.d.ts +18 -0
  43. package/dist/regex/rfc-2822.js +18 -8
  44. package/dist/regex/rfc-3339.d.ts +19 -0
  45. package/dist/regex/rfc-3339.js +19 -6
  46. package/dist/regex/sql-date-time.d.ts +14 -0
  47. package/dist/regex/sql-date-time.js +14 -6
  48. package/dist/regex/time-zone-like.d.ts +21 -0
  49. package/dist/regex/time-zone-like.js +21 -0
  50. package/dist/regex/time.d.ts +59 -0
  51. package/dist/regex/time.js +59 -3
  52. package/dist/regex/unix.d.ts +21 -0
  53. package/dist/regex/unix.js +21 -0
  54. package/dist/regex/utc-date-time.d.ts +20 -0
  55. package/dist/regex/utc-date-time.js +20 -1
  56. package/dist/types/calendar-options.d.ts +11 -0
  57. package/dist/types/calendar-options.js +0 -0
  58. package/dist/types/datetime-format-options.d.ts +6 -0
  59. package/dist/types/datetime-format-options.js +0 -0
  60. package/dist/types/duration-unit.d.ts +5 -0
  61. package/dist/types/duration-unit.js +0 -0
  62. package/dist/types/index.d.ts +11 -0
  63. package/dist/types/index.js +11 -0
  64. package/dist/types/now-unit.d.ts +5 -0
  65. package/dist/types/now-unit.js +0 -0
  66. package/dist/types/relative-date-time-unit.d.ts +6 -0
  67. package/dist/types/relative-date-time-unit.js +0 -0
  68. package/dist/types/relative-date-unit.d.ts +5 -0
  69. package/dist/types/relative-date-unit.js +0 -0
  70. package/dist/types/relative-time-options.d.ts +18 -0
  71. package/dist/types/relative-time-options.js +0 -0
  72. package/dist/types/relative-time-unit.d.ts +5 -0
  73. package/dist/types/relative-time-unit.js +0 -0
  74. package/dist/types/relative-unit.d.ts +6 -0
  75. package/dist/types/relative-unit.js +0 -0
  76. package/dist/types/unix-now-unit.d.ts +5 -0
  77. package/dist/types/unix-now-unit.js +0 -0
  78. package/dist/types/utc-now-unit.d.ts +5 -0
  79. package/dist/types/utc-now-unit.js +0 -0
  80. package/dist/unix/calculate/startOrEndOfUnix.d.ts +18 -0
  81. package/dist/unix/calculate/startOrEndOfUnix.js +18 -0
  82. package/dist/unix/format/formatCalendarUnix.d.ts +27 -1
  83. package/dist/unix/format/formatRelativeUnix.d.ts +1 -8
  84. package/dist/unix/format/formatUnix.d.ts +19 -0
  85. package/dist/unix/format/formatUnix.js +19 -0
  86. package/dist/unix/get/getUnixNowUnit.d.ts +2 -3
  87. package/dist/unix/parse/parseUnitFromUnix.d.ts +24 -0
  88. package/dist/unix/validate/isValidUnixUnit.d.ts +15 -0
  89. package/dist/utc/calculate/startOrEndOfUtc.d.ts +17 -0
  90. package/dist/utc/calculate/startOrEndOfUtc.js +17 -0
  91. package/dist/utc/format/formatCalendarUtc.d.ts +2 -2
  92. package/dist/utc/format/formatRelativeUtc.d.ts +2 -12
  93. package/dist/utc/format/formatUtc.d.ts +33 -0
  94. package/dist/utc/format/formatUtc.js +17 -0
  95. package/dist/utc/get/getUtcNowUnit.d.ts +2 -3
  96. package/dist/utc/parse/parseUnitFromUtc.d.ts +23 -0
  97. package/dist/zoned/format/formatRelativeZoned.d.ts +1 -8
  98. package/dist/zoned/format/formatTimeZoneName.d.ts +15 -0
  99. package/dist/zoned/format/formatZonedDateTime.d.ts +2 -1
  100. package/dist/zoned/format/formatZonedRange.d.ts +2 -1
  101. package/dist/zoned/format/formatZonedToParts.d.ts +2 -1
  102. package/dist/zoned/get/getDstTransitions.d.ts +18 -2
  103. package/dist/zoned/get/getZonedNowUnit.d.ts +24 -0
  104. package/dist/zoned/interval/intervalDifferenceZoned.d.ts +3 -3
  105. package/dist/zoned/interval/intervalDifferenceZoned.js +3 -3
  106. package/dist/zoned/interval/intervalXorZoned.d.ts +6 -4
  107. package/dist/zoned/interval/intervalXorZoned.js +6 -4
  108. package/dist/zoned/parse/getZonedOffsetAs.d.ts +11 -0
  109. package/dist/zoned/parse/parseUnitFromZoned.d.ts +24 -0
  110. package/package.json +25 -7
  111. package/skills/gmt-arithmetic/SKILL.md +83 -0
  112. package/skills/gmt-basics/SKILL.md +80 -0
  113. package/skills/gmt-integration/SKILL.md +73 -0
  114. package/skills/gmt-timezone/SKILL.md +80 -0
  115. package/skills/_artifacts/domain_map.yaml +0 -547
  116. package/skills/_artifacts/skill_spec.md +0 -67
  117. package/skills/_artifacts/skill_tree.yaml +0 -278
  118. package/skills/api-expansion-workflow/SKILL.md +0 -52
  119. package/skills/app-integration/SKILL.md +0 -38
  120. package/skills/calculate-dates/SKILL.md +0 -432
  121. package/skills/compare-dates/SKILL.md +0 -412
  122. package/skills/convert-types/SKILL.md +0 -305
  123. package/skills/durations/SKILL.md +0 -418
  124. package/skills/format-date-time/SKILL.md +0 -486
  125. package/skills/format-date-time/references/format-api.md +0 -34
  126. package/skills/format-relative-time/SKILL.md +0 -223
  127. package/skills/get-current/SKILL.md +0 -229
  128. package/skills/interval-ops/SKILL.md +0 -432
  129. package/skills/issue-creation/SKILL.md +0 -118
  130. package/skills/lint-package-suggestion/SKILL.md +0 -37
  131. package/skills/new-method-implementation/SKILL.md +0 -71
  132. package/skills/parse-date-time/SKILL.md +0 -349
  133. package/skills/pr-contribution/SKILL.md +0 -180
  134. package/skills/unit-test-generation/SKILL.md +0 -56
  135. package/skills/validate-dates/SKILL.md +0 -438
  136. package/skills/zoned-date-ops/SKILL.md +0 -422
  137. package/skills/zoned-date-ops/references/timezones.md +0 -13
@@ -1,9 +1,65 @@
1
- // regex patterns exported for usage
1
+ /**
2
+ * RegExp matching an ISO 8601 hour in extended format: `00`–`23`.
3
+ *
4
+ * @example hour.test("00") // true
5
+ * @example hour.test("12") // true
6
+ * @example hour.test("23") // true
7
+ * @example hour.test("24") // false (out of range)
8
+ * @example hour.test("9") // false (not zero-padded)
9
+ */
2
10
  export const hour = /^(0[0-9]|1[0-9]|2[0-3])$/;
11
+ /**
12
+ * RegExp matching an ISO 8601 minute: `00`–`59`.
13
+ *
14
+ * @example minute.test("00") // true
15
+ * @example minute.test("30") // true
16
+ * @example minute.test("59") // true
17
+ * @example minute.test("60") // false (out of range)
18
+ */
3
19
  export const minute = /^[0-5][0-9]$/;
20
+ /**
21
+ * RegExp matching an ISO 8601 second: `00`–`59`.
22
+ *
23
+ * @example second.test("00") // true
24
+ * @example second.test("30") // true
25
+ * @example second.test("59") // true
26
+ * @example second.test("60") // false (out of range; leap seconds use a different pattern)
27
+ */
4
28
  export const second = /^[0-5][0-9]$/;
29
+ /**
30
+ * RegExp matching 1–9 fractional-second digits (nanosecond precision).
31
+ *
32
+ * - Used for the fractional portion after `.` or `,` in time strings.
33
+ * - Backward-compatible alias `millisecond` points to this same pattern.
34
+ *
35
+ * @example fractionalSecond.test("123") // true (milliseconds)
36
+ * @example fractionalSecond.test("123456789") // true (nanoseconds)
37
+ * @example fractionalSecond.test("0") // false (must be 1–9 digits)
38
+ * @example fractionalSecond.test("") // false (empty)
39
+ */
5
40
  export const fractionalSecond = /^[0-9]{1,9}$/;
6
- // Backward-compatible alias; prefer fractionalSecond for new usage.
41
+ /**
42
+ * Backward-compatible alias for `fractionalSecond`. Prefer `fractionalSecond` for new
43
+ * usage — the pattern matches 1–9 digits of fractional seconds, not just milliseconds.
44
+ */
7
45
  export const millisecond = fractionalSecond;
8
- // ISO 8601 local time (extended): HH:mm[:ss[.fffffffff]]
46
+ /**
47
+ * RegExp matching ISO 8601 local time (extended): `HH:mm[:ss[.fffffffff]]`.
48
+ *
49
+ * - Hours: `00`–`23`, zero-padded.
50
+ * - Minutes and seconds: `00`–`59`, zero-padded.
51
+ * - Seconds are optional; fractional seconds use `.` or `,` followed by 1–9 digits.
52
+ * - No timezone designator — this is a plain/local time only.
53
+ * - Shape-only validation; real field validation is delegated to
54
+ * `Temporal.PlainTime.from` in `parseTime`.
55
+ *
56
+ * Capture groups: 1 hour, 2 minute, 3 second (optional), 4 fractional (optional).
57
+ *
58
+ * @example plainTime.test("14:30") // true
59
+ * @example plainTime.test("14:30:00") // true
60
+ * @example plainTime.test("14:30:00.123") // true (fractional seconds)
61
+ * @example plainTime.test("14:30:00,123") // true (comma separator)
62
+ * @example plainTime.test("24:00:00") // false (hour out of range)
63
+ * @example plainTime.test("14:30:60") // false (second out of range)
64
+ */
9
65
  export const plainTime = /^(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9](?:[.,][0-9]{1,9})?)?$/;
@@ -1,2 +1,23 @@
1
+ /**
2
+ * RegExp matching a Unix timestamp in seconds: exactly 10 digits.
3
+ *
4
+ * - Covers the range from `0000000000` (1970-01-01T00:00:00Z) through
5
+ * `3999999999` (2096-10-11T03:33:19Z), which is the practical range for
6
+ * 10-digit Unix-second timestamps.
7
+ *
8
+ * @example unixSeconds.test("1710511800") // true
9
+ * @example unixSeconds.test("0000000000") // true (epoch)
10
+ * @example unixSeconds.test("17105118001") // false (11 digits)
11
+ */
1
12
  export declare const unixSeconds: RegExp;
13
+ /**
14
+ * RegExp matching a Unix timestamp in milliseconds: exactly 13 digits.
15
+ *
16
+ * - Covers the range from `0000000000000` (1970-01-01T00:00:00Z) through
17
+ * `3999999999999` (2096-10-11T03:33:19.999Z).
18
+ *
19
+ * @example unixMilliseconds.test("1710511800123") // true
20
+ * @example unixMilliseconds.test("0000000000000") // true (epoch)
21
+ * @example unixMilliseconds.test("17105118001") // false (11 digits)
22
+ */
2
23
  export declare const unixMilliseconds: RegExp;
@@ -1,2 +1,23 @@
1
+ /**
2
+ * RegExp matching a Unix timestamp in seconds: exactly 10 digits.
3
+ *
4
+ * - Covers the range from `0000000000` (1970-01-01T00:00:00Z) through
5
+ * `3999999999` (2096-10-11T03:33:19Z), which is the practical range for
6
+ * 10-digit Unix-second timestamps.
7
+ *
8
+ * @example unixSeconds.test("1710511800") // true
9
+ * @example unixSeconds.test("0000000000") // true (epoch)
10
+ * @example unixSeconds.test("17105118001") // false (11 digits)
11
+ */
1
12
  export const unixSeconds = /^\d{10}$/;
13
+ /**
14
+ * RegExp matching a Unix timestamp in milliseconds: exactly 13 digits.
15
+ *
16
+ * - Covers the range from `0000000000000` (1970-01-01T00:00:00Z) through
17
+ * `3999999999999` (2096-10-11T03:33:19.999Z).
18
+ *
19
+ * @example unixMilliseconds.test("1710511800123") // true
20
+ * @example unixMilliseconds.test("0000000000000") // true (epoch)
21
+ * @example unixMilliseconds.test("17105118001") // false (11 digits)
22
+ */
2
23
  export const unixMilliseconds = /^\d{13}$/;
@@ -1 +1,21 @@
1
+ /**
2
+ * RegExp matching ISO 8601 UTC datetime: `<date>T<time>Z` with optional fractional
3
+ * seconds. The timezone designator accepts `Z` or `z` (lowercase is accepted for
4
+ * leniency, though GMT's own formatter always emits uppercase).
5
+ *
6
+ * - Date half: `YYYY-MM-DD` or `±YYYYYY-MM-DD` (6-digit year with sign).
7
+ * - Time half: `HH:mm` with optional `:ss[.fffffffff]` (fractional seconds use `.` or `,`).
8
+ * - No numeric offset — only the `Z`/`z` UTC designator is accepted.
9
+ * - Shape-only validation; real calendar validation is delegated to
10
+ * `Temporal.PlainDateTime.from` in `parseUtcDateTime`.
11
+ *
12
+ * Capture groups: 1 year, 2 month, 3 day, 4 hour, 5 minute, 6 second (optional),
13
+ * 7 fractional (optional).
14
+ *
15
+ * @example utcDateTime.test("2024-03-15T14:30:00Z") // true
16
+ * @example utcDateTime.test("2024-03-15T14:30z") // true (lowercase z)
17
+ * @example utcDateTime.test("2024-03-15T14:30:00.123Z") // true (fractional seconds)
18
+ * @example utcDateTime.test("2024-03-15T14:30:00+00:00") // false (numeric offset)
19
+ * @example utcDateTime.test("2024-03-15T14:30:00") // false (no timezone)
20
+ */
1
21
  export declare const utcDateTime: RegExp;
@@ -1,2 +1,21 @@
1
- // ISO 8601 UTC datetime: <date>T<time>Z with optional fractional seconds
1
+ /**
2
+ * RegExp matching ISO 8601 UTC datetime: `<date>T<time>Z` with optional fractional
3
+ * seconds. The timezone designator accepts `Z` or `z` (lowercase is accepted for
4
+ * leniency, though GMT's own formatter always emits uppercase).
5
+ *
6
+ * - Date half: `YYYY-MM-DD` or `±YYYYYY-MM-DD` (6-digit year with sign).
7
+ * - Time half: `HH:mm` with optional `:ss[.fffffffff]` (fractional seconds use `.` or `,`).
8
+ * - No numeric offset — only the `Z`/`z` UTC designator is accepted.
9
+ * - Shape-only validation; real calendar validation is delegated to
10
+ * `Temporal.PlainDateTime.from` in `parseUtcDateTime`.
11
+ *
12
+ * Capture groups: 1 year, 2 month, 3 day, 4 hour, 5 minute, 6 second (optional),
13
+ * 7 fractional (optional).
14
+ *
15
+ * @example utcDateTime.test("2024-03-15T14:30:00Z") // true
16
+ * @example utcDateTime.test("2024-03-15T14:30z") // true (lowercase z)
17
+ * @example utcDateTime.test("2024-03-15T14:30:00.123Z") // true (fractional seconds)
18
+ * @example utcDateTime.test("2024-03-15T14:30:00+00:00") // false (numeric offset)
19
+ * @example utcDateTime.test("2024-03-15T14:30:00") // false (no timezone)
20
+ */
2
21
  export const utcDateTime = /^(?:\d{4}|[+-]\d{6})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9](?:[.,]\d{1,9})?)?[Zz]$/;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Core fields shared by all calendar-formatting interfaces.
3
+ * Each domain variant (plain, unix, utc, zoned) extends this and may
4
+ * add domain-specific fields like `timeZone` or `epochUnit`.
5
+ */
6
+ export interface CalendarOptions {
7
+ /** Anchor point for the relative day comparison. */
8
+ reference?: string;
9
+ /** `Intl.DateTimeFormatOptions` `timeStyle` for the time-of-day half. */
10
+ timeStyle?: "short" | "medium" | "full";
11
+ }
File without changes
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Options accepted by date/time formatting functions that delegate to
3
+ * `Intl.DateTimeFormat` (via Temporal's `.toLocaleString()` or
4
+ * `TemporalIntl.DateTimeFormat`).
5
+ */
6
+ export type DateTimeFormatOptions = Intl.DateTimeFormatOptions;
File without changes
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Plural unit keys accepted by `formatDuration` for `UNIT_TO_INTL` lookup. Maps to
3
+ * singular `Intl.NumberFormat` unit labels (e.g. `"years"` → `"year"`).
4
+ */
5
+ export type DurationUnit = "years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds";
File without changes
@@ -1,3 +1,4 @@
1
+ export * from "./calendar-options.js";
1
2
  export * from "./calendar-system.js";
2
3
  export * from "./date-cycle-field.js";
3
4
  export * from "./date-duration-unit.js";
@@ -5,14 +6,24 @@ export * from "./date-time-cycle-field.js";
5
6
  export * from "./date-time-duration-units.js";
6
7
  export * from "./date-time-unit.js";
7
8
  export * from "./date-unit.js";
9
+ export * from "./datetime-format-options.js";
8
10
  export * from "./disambiguation.js";
9
11
  export * from "./duration-relative-to.js";
10
12
  export * from "./duration-string-options.js";
13
+ export * from "./duration-unit.js";
11
14
  export * from "./fractional-digit.js";
15
+ export * from "./now-unit.js";
12
16
  export * from "./offset.js";
13
17
  export * from "./overflow.js";
18
+ export * from "./relative-date-time-unit.js";
19
+ export * from "./relative-date-unit.js";
14
20
  export * from "./relative-rounding-method.js";
21
+ export * from "./relative-time-options.js";
22
+ export * from "./relative-time-unit.js";
23
+ export * from "./relative-unit.js";
15
24
  export * from "./rounding-options.js";
16
25
  export * from "./time-cycle-field.js";
17
26
  export * from "./time-duration-unit.js";
18
27
  export * from "./time-unit.js";
28
+ export * from "./unix-now-unit.js";
29
+ export * from "./utc-now-unit.js";
@@ -1,3 +1,4 @@
1
+ export * from "./calendar-options.js";
1
2
  export * from "./calendar-system.js";
2
3
  export * from "./date-cycle-field.js";
3
4
  export * from "./date-duration-unit.js";
@@ -5,14 +6,24 @@ export * from "./date-time-cycle-field.js";
5
6
  export * from "./date-time-duration-units.js";
6
7
  export * from "./date-time-unit.js";
7
8
  export * from "./date-unit.js";
9
+ export * from "./datetime-format-options.js";
8
10
  export * from "./disambiguation.js";
9
11
  export * from "./duration-relative-to.js";
10
12
  export * from "./duration-string-options.js";
13
+ export * from "./duration-unit.js";
11
14
  export * from "./fractional-digit.js";
15
+ export * from "./now-unit.js";
12
16
  export * from "./offset.js";
13
17
  export * from "./overflow.js";
18
+ export * from "./relative-date-time-unit.js";
19
+ export * from "./relative-date-unit.js";
14
20
  export * from "./relative-rounding-method.js";
21
+ export * from "./relative-time-options.js";
22
+ export * from "./relative-time-unit.js";
23
+ export * from "./relative-unit.js";
15
24
  export * from "./rounding-options.js";
16
25
  export * from "./time-cycle-field.js";
17
26
  export * from "./time-duration-unit.js";
18
27
  export * from "./time-unit.js";
28
+ export * from "./unix-now-unit.js";
29
+ export * from "./utc-now-unit.js";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Units extractable from the current system local time via `getNowUnit`.
3
+ * Defined as `DateTimeUnit | "dayOfWeek"`.
4
+ */
5
+ export type NowUnit = import("./date-time-unit.js").DateTimeUnit | "dayOfWeek";
File without changes
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Full 7-member `RelativeUnit` for `PlainDateTime`-based formatting. Covers the
3
+ * complete set of `Intl.RelativeTimeFormat` units supported by Temporal, excluding
4
+ * `quarter`.
5
+ */
6
+ export type RelativeDateTimeUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second";
File without changes
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Narrow `RelativeUnit` for `PlainDate`-based formatting. Excludes `hour`,
3
+ * `minute`, and `second` because `PlainDate` has no time component.
4
+ */
5
+ export type RelativeDateUnit = "year" | "month" | "week" | "day";
File without changes
@@ -0,0 +1,18 @@
1
+ import type { RelativeRoundingMethod } from "./relative-rounding-method.js";
2
+ /**
3
+ * Core fields shared by all relative-time formatting interfaces.
4
+ * Each domain variant (plain, unix, utc, zoned) extends this and may
5
+ * restrict `largestUnit` or add domain-specific fields.
6
+ */
7
+ export interface RelativeTimeFormatOptions {
8
+ /** Name style: "long" (default), "short", or "narrow". */
9
+ style?: "long" | "short" | "narrow";
10
+ /** Whether to use relative time words ("in 2 days") or numeric ("2 days"). */
11
+ numeric?: "always" | "auto";
12
+ /** The largest unit to display. Each domain restricts the allowed values. */
13
+ largestUnit?: string;
14
+ /** How the computed distance rounds to the display unit. */
15
+ roundingMethod?: RelativeRoundingMethod;
16
+ /** Anchor point for the relative diff. */
17
+ reference?: string;
18
+ }
File without changes
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Narrow `RelativeUnit` for `PlainTime`-based formatting. Excludes date units
3
+ * (`year`, `month`, `week`, `day`) because `PlainTime` has no date component.
4
+ */
5
+ export type RelativeTimeUnit = "hour" | "minute" | "second";
File without changes
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Canonical 7-member unit for `Intl.RelativeTimeFormat` and Temporal `since`/`until`
3
+ * totals, excluding `quarter`. Shared by `formatRelativeUnix`, `formatRelativeUtc`,
4
+ * and `formatRelativeZoned` after importing from this barrel.
5
+ */
6
+ export type RelativeUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second";
File without changes
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Units extractable from the current Unix timestamp in UTC via `getUnixNowUnit`.
3
+ * Defined as `DateTimeUnit | "dayOfWeek"`.
4
+ */
5
+ export type UnixNowUnit = import("./date-time-unit.js").DateTimeUnit | "dayOfWeek";
File without changes
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Units extractable from the current UTC instant via `getUtcNowUnit`.
3
+ * Defined as `DateTimeUnit | "dayOfWeek"`.
4
+ */
5
+ export type UtcNowUnit = import("./date-time-unit.js").DateTimeUnit | "dayOfWeek";
File without changes
@@ -1,5 +1,23 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import type { Disambiguation, Offset } from "../../types/index.js";
3
+ /**
4
+ * Internal shared implementation for `startOfUnix` / `endOfUnix`.
5
+ *
6
+ * - Converts the epoch to a ZonedDateTime, snaps to the start or end of the
7
+ * requested unit, then converts back to an epoch number.
8
+ * - Supports every Temporal `DateUnit` and `TimeUnit`.
9
+ * - `epochUnit` controls whether the input/output is interpreted as `"milliseconds"` (default) or `"seconds"`.
10
+ * - `timeZone` defaults to the system time zone via `getSystemTimeZone()`.
11
+ * - `disambiguation` and `offset` are forwarded to Temporal's `.with()` for
12
+ * DST-gap/overlap boundaries; see `startOfUnix`'s JSDoc for the full
13
+ * semantics — they behave identically here.
14
+ *
15
+ * @param value Unix epoch number
16
+ * @param unit Temporal.DateUnit | Temporal.TimeUnit to snap to
17
+ * @param options optional: epochUnit, timeZone, weekStartsOn, disambiguation, offset
18
+ * @param isEnd false for start-of-unit, true for end-of-unit
19
+ * @returns Unix epoch number, or null on invalid input
20
+ */
3
21
  export declare function startOrEndOfUnix(value: number, unit: Temporal.DateUnit | Temporal.TimeUnit, options: {
4
22
  epochUnit?: "seconds" | "milliseconds";
5
23
  timeZone?: string;
@@ -3,6 +3,24 @@ import { isValidDateTimeUnit } from "../../plain/index.js";
3
3
  import { isValidUnixUnit } from "../../unix/validate/isValidUnixUnit.js";
4
4
  import { getSystemTimeZone } from "../../zoned/get/index.js";
5
5
  import { isValidTimeZone } from "../../zoned/validate/index.js";
6
+ /**
7
+ * Internal shared implementation for `startOfUnix` / `endOfUnix`.
8
+ *
9
+ * - Converts the epoch to a ZonedDateTime, snaps to the start or end of the
10
+ * requested unit, then converts back to an epoch number.
11
+ * - Supports every Temporal `DateUnit` and `TimeUnit`.
12
+ * - `epochUnit` controls whether the input/output is interpreted as `"milliseconds"` (default) or `"seconds"`.
13
+ * - `timeZone` defaults to the system time zone via `getSystemTimeZone()`.
14
+ * - `disambiguation` and `offset` are forwarded to Temporal's `.with()` for
15
+ * DST-gap/overlap boundaries; see `startOfUnix`'s JSDoc for the full
16
+ * semantics — they behave identically here.
17
+ *
18
+ * @param value Unix epoch number
19
+ * @param unit Temporal.DateUnit | Temporal.TimeUnit to snap to
20
+ * @param options optional: epochUnit, timeZone, weekStartsOn, disambiguation, offset
21
+ * @param isEnd false for start-of-unit, true for end-of-unit
22
+ * @returns Unix epoch number, or null on invalid input
23
+ */
6
24
  export function startOrEndOfUnix(value, unit, options, isEnd) {
7
25
  const epochUnit = options.epochUnit ?? "milliseconds";
8
26
  const timeZone = options.timeZone ?? getSystemTimeZone();
@@ -1,6 +1,32 @@
1
+ /**
2
+ * Options for `formatCalendarUnix`. Mirrors the option shape of
3
+ * `formatCalendar` but targets the unix domain, adding `epochUnit`.
4
+ *
5
+ * @remarks Members:
6
+ *
7
+ * | Member | Type | Default | Description |
8
+ * | --- | --- | --- | --- |
9
+ * | `style` | `"long"\|"short"\|"narrow"` | `"long"` | `RelativeTimeFormat` style for the day label. |
10
+ * | `numeric` | `"always"\|"auto"` | `"auto"` | Numeric formatting of the relative day label. |
11
+ * | `largestUnit` | `"year"\|"month"\|"week"\|"day"` | auto | Largest unit for the relative diff. |
12
+ * | `roundingMethod` | `"expand"\|"trunc"\|"floor"\|"ceil"` | — | Rounding for the computed distance. |
13
+ * | `reference` | `string\|number` | now (UTC) | Anchor epoch/ISO for the "today/tomorrow" comparison. |
14
+ * | `epochUnit` | `"milliseconds"\|"seconds"` | `"milliseconds"` | Interpretation of numeric `value`/`reference`. |
15
+ * | `timeZone` | `string` | `"UTC"` | IANA zone for both day-comparison and clock-time rendering. |
16
+ * | `timeStyle` | `"short"\|"medium"\|"full"` | `"short"` | `Intl` `timeStyle` for the time-of-day portion. |
17
+ *
18
+ * @example
19
+ * import { FormatCalendarUnixOptions } from "@northguild/gmt/unix";
20
+ * const opts: FormatCalendarUnixOptions = { timeZone: "America/New_York" };
21
+ */
1
22
  export interface FormatCalendarUnixOptions {
2
- epochUnit?: "milliseconds" | "seconds";
23
+ style?: "long" | "short" | "narrow";
24
+ numeric?: "always" | "auto";
25
+ largestUnit?: "year" | "month" | "week" | "day";
26
+ roundingMethod?: "expand" | "trunc" | "floor" | "ceil";
27
+ /** Anchor point for the relative day comparison. Accepts ISO strings or numeric epochs. */
3
28
  reference?: string | number;
29
+ epochUnit?: "milliseconds" | "seconds";
4
30
  /**
5
31
  * IANA timezone used for both the calendar-day comparison and the
6
32
  * rendered clock time. Resolved via `normalizeTimeZone` — `"local"` for
@@ -1,14 +1,8 @@
1
- import type { RelativeRoundingMethod } from "../../types/index.js";
2
- type RelativeUnit = "year" | "month" | "week" | "day" | "hour" | "minute" | "second";
1
+ import type { RelativeRoundingMethod, RelativeUnit } from "../../types/index.js";
3
2
  export interface FormatRelativeUnixOptions {
4
3
  style?: "long" | "short" | "narrow";
5
4
  numeric?: "always" | "auto";
6
5
  largestUnit?: RelativeUnit;
7
- /**
8
- * How the computed distance rounds to the display unit: "floor" rounds toward the
9
- * earlier boundary, "ceil" toward the later boundary, "round" (default) to the nearest —
10
- * matches current behavior when omitted.
11
- */
12
6
  roundingMethod?: RelativeRoundingMethod;
13
7
  epochUnit?: "milliseconds" | "seconds";
14
8
  reference?: string | number;
@@ -31,4 +25,3 @@ export interface FormatRelativeUnixOptions {
31
25
  * @example formatRelativeUnix("not-a-number") // ""
32
26
  */
33
27
  export declare function formatRelativeUnix(value: string | number, locale?: string, options?: FormatRelativeUnixOptions): string;
34
- export {};
@@ -3,4 +3,23 @@ export interface FormatUnixOptions extends Intl.DateTimeFormatOptions {
3
3
  timeZone?: string;
4
4
  includeTimeZoneName?: boolean;
5
5
  }
6
+ /**
7
+ * Format a unix epoch value (string or number) as a localized date/time string.
8
+ *
9
+ * - Returns `""` if the input is not a valid unix epoch value for the given `epochUnit`.
10
+ * - `epochUnit` controls whether the input is interpreted as `"milliseconds"` or `"seconds"`; defaults to `"milliseconds"`.
11
+ * - `timeZone` controls the IANA zone used for rendering; defaults to `"UTC"`.
12
+ * - `includeTimeZoneName` appends the localized timezone name when true.
13
+ *
14
+ * @param value unix epoch value to format (string or number, per `epochUnit`)
15
+ * @param locale optional: BCP 47 locale tag
16
+ * @param options optional: { epochUnit, timeZone, includeTimeZoneName }
17
+ * @returns the formatted date/time string, or "" on invalid input
18
+ *
19
+ * @example formatUnix("1710685845000", "en-US", { epochUnit: "milliseconds" }) // "3/17/2024, 2:30:45 PM"
20
+ * @example formatUnix(1710685845000, "en-US", { epochUnit: "milliseconds" }) // "3/17/2024, 2:30:45 PM"
21
+ * @example formatUnix("1710685845", "en-US", { epochUnit: "seconds" }) // "3/17/2024, 2:30:45 PM"
22
+ * @example formatUnix("1710685845000", "en-US", { epochUnit: "milliseconds", includeTimeZoneName: true }) // "3/17/2024, 2:30:45 PM UTC"
23
+ * @example formatUnix("not-a-number") // ""
24
+ */
6
25
  export declare function formatUnix(value: string | number, locale?: string, options?: FormatUnixOptions): string;
@@ -20,6 +20,25 @@ function parseEpochMs(value, epochUnit) {
20
20
  return null;
21
21
  return epochUnit === "seconds" ? n * 1000 : n;
22
22
  }
23
+ /**
24
+ * Format a unix epoch value (string or number) as a localized date/time string.
25
+ *
26
+ * - Returns `""` if the input is not a valid unix epoch value for the given `epochUnit`.
27
+ * - `epochUnit` controls whether the input is interpreted as `"milliseconds"` or `"seconds"`; defaults to `"milliseconds"`.
28
+ * - `timeZone` controls the IANA zone used for rendering; defaults to `"UTC"`.
29
+ * - `includeTimeZoneName` appends the localized timezone name when true.
30
+ *
31
+ * @param value unix epoch value to format (string or number, per `epochUnit`)
32
+ * @param locale optional: BCP 47 locale tag
33
+ * @param options optional: { epochUnit, timeZone, includeTimeZoneName }
34
+ * @returns the formatted date/time string, or "" on invalid input
35
+ *
36
+ * @example formatUnix("1710685845000", "en-US", { epochUnit: "milliseconds" }) // "3/17/2024, 2:30:45 PM"
37
+ * @example formatUnix(1710685845000, "en-US", { epochUnit: "milliseconds" }) // "3/17/2024, 2:30:45 PM"
38
+ * @example formatUnix("1710685845", "en-US", { epochUnit: "seconds" }) // "3/17/2024, 2:30:45 PM"
39
+ * @example formatUnix("1710685845000", "en-US", { epochUnit: "milliseconds", includeTimeZoneName: true }) // "3/17/2024, 2:30:45 PM UTC"
40
+ * @example formatUnix("not-a-number") // ""
41
+ */
23
42
  export function formatUnix(value, locale, options) {
24
43
  const { epochUnit = "milliseconds", timeZone, includeTimeZoneName = false, ...intlOptions } = options ?? {};
25
44
  if (!isValidUnixUnit(epochUnit))
@@ -1,5 +1,5 @@
1
- import type { DateTimeUnit } from "../../types/index.js";
2
- type UnixNowUnit = DateTimeUnit | "dayOfWeek";
1
+ import type { UnixNowUnit } from "../../types/index.js";
2
+ export type { UnixNowUnit };
3
3
  /**
4
4
  * Return the requested unit value from the current Unix timestamp in UTC.
5
5
  *
@@ -15,4 +15,3 @@ type UnixNowUnit = DateTimeUnit | "dayOfWeek";
15
15
  * @example getUnixNowUnit("invalid") // ""
16
16
  */
17
17
  export declare function getUnixNowUnit(unit: UnixNowUnit): string;
18
- export {};
@@ -1,4 +1,28 @@
1
1
  import { type UnixUnit } from "../validate/index.js";
2
+ /**
3
+ * Units extractable from a unix epoch value via `parseUnitFromUnix`. Covers the
4
+ * full set of date/time units plus sub-millisecond precision.
5
+ *
6
+ * @remarks Members:
7
+ *
8
+ * | Member | Description |
9
+ * | --- | --- |
10
+ * | `year` | Full year, no padding (e.g. `2024`). |
11
+ * | `month` | Zero-padded 2 (e.g. `03`). |
12
+ * | `week` | Week-of-year, 1–53 (`weekStartsOn`-controlled). |
13
+ * | `day` | Zero-padded 2. |
14
+ * | `dayOfWeek` | 1 (Mon)–7 (Sun). |
15
+ * | `hour` | Zero-padded 2. |
16
+ * | `minute` | Zero-padded 2. |
17
+ * | `second` | Zero-padded 2. |
18
+ * | `millisecond` | Zero-padded 3. |
19
+ * | `microsecond` | Zero-padded 3. |
20
+ * | `nanosecond` | Zero-padded 9. |
21
+ *
22
+ * @example
23
+ * import { PlainNowUnit } from "@northguild/gmt/unix";
24
+ * const u: PlainNowUnit = "month";
25
+ */
2
26
  export type PlainNowUnit = "year" | "month" | "week" | "day" | "dayOfWeek" | "hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond";
3
27
  /**
4
28
  * Extract a unit from a unix epoch value.
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Unit accepted by `epochUnit` in unix-epoch functions. Determines whether a
3
+ * numeric value is interpreted as milliseconds or seconds.
4
+ *
5
+ * @remarks Members:
6
+ *
7
+ * | Member | Description |
8
+ * | --- | --- |
9
+ * | `seconds` | Value is Unix epoch seconds (e.g. `1700000000`). |
10
+ * | `milliseconds` | Value is Unix epoch milliseconds (e.g. `1700000000000`). |
11
+ *
12
+ * @example
13
+ * import { isValidUnixUnit } from "@northguild/gmt/unix";
14
+ * isValidUnixUnit("milliseconds"); // true
15
+ */
1
16
  export type UnixUnit = "seconds" | "milliseconds";
2
17
  /**
3
18
  * Return true when `unit` is a valid UnixUnit.
@@ -1,5 +1,22 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import type { FractionalDigit } from "../../types/index.js";
3
+ /**
4
+ * Internal shared implementation for `startOfUtc` / `endOfUtc`.
5
+ *
6
+ * - Converts the UTC Instant to a ZonedDateTime, snaps to the start or end of
7
+ * the requested unit, then converts back to an Instant string.
8
+ * - Supports every Temporal `DateUnit` and `TimeUnit`.
9
+ * - `weekStartsOn` shifts the week boundary: `"monday"` (default) or `"sunday"`.
10
+ * - `fractionalSecondDigits` overrides the default sub-second precision for the
11
+ * returned Instant string; defaults to 3 for millisecond, 6 for microsecond,
12
+ * 9 for nanosecond, and 0 for all coarser units.
13
+ *
14
+ * @param value ISO UTC datetime string
15
+ * @param unit Temporal.DateUnit | Temporal.TimeUnit to snap to
16
+ * @param options optional: weekStartsOn, fractionalSecondDigits
17
+ * @param isEnd false for start-of-unit, true for end-of-unit
18
+ * @returns UTC Instant string, or "" on invalid input
19
+ */
3
20
  export declare function startOrEndOfUtc(value: string, unit: Temporal.DateUnit | Temporal.TimeUnit, options: {
4
21
  weekStartsOn?: "monday" | "sunday";
5
22
  fractionalSecondDigits?: FractionalDigit;
@@ -1,6 +1,23 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { isValidDateTimeUnit } from "../../plain/index.js";
3
3
  import { isValidUtc } from "../validate/isValidUtc.js";
4
+ /**
5
+ * Internal shared implementation for `startOfUtc` / `endOfUtc`.
6
+ *
7
+ * - Converts the UTC Instant to a ZonedDateTime, snaps to the start or end of
8
+ * the requested unit, then converts back to an Instant string.
9
+ * - Supports every Temporal `DateUnit` and `TimeUnit`.
10
+ * - `weekStartsOn` shifts the week boundary: `"monday"` (default) or `"sunday"`.
11
+ * - `fractionalSecondDigits` overrides the default sub-second precision for the
12
+ * returned Instant string; defaults to 3 for millisecond, 6 for microsecond,
13
+ * 9 for nanosecond, and 0 for all coarser units.
14
+ *
15
+ * @param value ISO UTC datetime string
16
+ * @param unit Temporal.DateUnit | Temporal.TimeUnit to snap to
17
+ * @param options optional: weekStartsOn, fractionalSecondDigits
18
+ * @param isEnd false for start-of-unit, true for end-of-unit
19
+ * @returns UTC Instant string, or "" on invalid input
20
+ */
4
21
  export function startOrEndOfUtc(value, unit, options, isEnd) {
5
22
  const weekStartsOn = options.weekStartsOn ?? "monday";
6
23
  const fractionalSecondDigits = options.fractionalSecondDigits;
@@ -1,5 +1,5 @@
1
- export interface FormatCalendarUtcOptions {
2
- reference?: string;
1
+ import type { CalendarOptions } from "../../types/index.js";
2
+ export interface FormatCalendarUtcOptions extends CalendarOptions {
3
3
  /**
4
4
  * IANA timezone used for both the calendar-day comparison and the
5
5
  * rendered clock time. Resolved via `normalizeTimeZone` — `"local"` for