@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,223 +0,0 @@
1
- ---
2
- name: format-relative-time
3
- description: >
4
- Produce human-friendly relative time strings ("yesterday", "in 2 hours", "3
5
- days ago") for any gmt value type. Use formatRelativeDate, formatRelativeTime,
6
- formatRelativeDateTime for plain values; formatRelativeZoned for IANA zoned
7
- values; formatRelativeUnix for epoch ms/seconds; formatRelativeUtc for UTC ISO
8
- strings. All accept a reference anchor and Intl.RelativeTimeFormat options
9
- (numeric, style).
10
- sources:
11
- - 'northguild/gmt:packages/gmt/src/plain/format/formatRelativeDate.ts'
12
- - 'northguild/gmt:packages/gmt/src/plain/format/formatRelativeTime.ts'
13
- - 'northguild/gmt:packages/gmt/src/plain/format/formatRelativeDateTime.ts'
14
- - 'northguild/gmt:packages/gmt/src/zoned/format/formatRelativeZoned.ts'
15
- - 'northguild/gmt:packages/gmt/src/unix/format/formatRelativeUnix.ts'
16
- - 'northguild/gmt:packages/gmt/src/utc/format/formatRelativeUtc.ts'
17
- metadata:
18
- type: core
19
- library: '@northguild/gmt'
20
- library_version: '1.14.2'
21
- ---
22
-
23
- # Format Relative Time
24
-
25
- Use this skill when you need a human-friendly relative time label — "yesterday", "in 5 minutes", "2 weeks ago" — instead of an absolute timestamp. There is one relative formatter per value type; pick the one matching the input.
26
-
27
- ## Picking the right formatter
28
-
29
- | Input shape | Formatter | Module |
30
- |---|---|---|
31
- | ISO date `"2024-03-15"` | `formatRelativeDate` | `@northguild/gmt` |
32
- | ISO time `"14:30:45"` | `formatRelativeTime` | `@northguild/gmt` |
33
- | ISO datetime `"2024-03-15T14:30:45"` | `formatRelativeDateTime` | `@northguild/gmt` |
34
- | Zoned `"2024-03-15T14:30:45-05:00[America/New_York]"` | `formatRelativeZoned` | `@northguild/gmt/zoned` |
35
- | Unix epoch (ms or seconds) | `formatRelativeUnix` | `@northguild/gmt/unix` |
36
- | UTC ISO `"2024-03-15T14:30:45Z"` | `formatRelativeUtc` | `@northguild/gmt/utc` |
37
-
38
- ## Core Patterns
39
-
40
- ### Plain date relative
41
-
42
- ```ts
43
- import { formatRelativeDate } from "@northguild/gmt";
44
-
45
- const ref = "2024-03-15";
46
- formatRelativeDate("2024-03-14", "en-US", { reference: ref }); // "yesterday"
47
- formatRelativeDate("2024-03-16", "en-US", { reference: ref }); // "tomorrow"
48
- formatRelativeDate("2024-03-12", "en-US", { reference: ref }); // "3 days ago"
49
- formatRelativeDate("2024-02-23", "en-US", {
50
- reference: ref,
51
- largestUnit: "week",
52
- numeric: "always",
53
- }); // "3 weeks ago"
54
- ```
55
-
56
- ### Plain time relative
57
-
58
- ```ts
59
- import { formatRelativeTime } from "@northguild/gmt";
60
-
61
- const ref = "12:00:00";
62
- formatRelativeTime("11:30:00", "en-US", { reference: ref }); // "30 minutes ago"
63
- formatRelativeTime("12:00:30", "en-US", { reference: ref }); // "in 30 seconds"
64
- ```
65
-
66
- ### Plain datetime relative
67
-
68
- ```ts
69
- import { formatRelativeDateTime } from "@northguild/gmt";
70
-
71
- const ref = "2024-03-15T12:00:00";
72
- formatRelativeDateTime("2024-03-15T10:00:00", "en-US", { reference: ref });
73
- // "2 hours ago"
74
- ```
75
-
76
- ### Zoned relative (DST-safe)
77
-
78
- ```ts
79
- import { formatRelativeZoned } from "@northguild/gmt/zoned";
80
-
81
- const ref = "2024-03-15T12:00:00-04:00[America/New_York]";
82
- formatRelativeZoned(
83
- "2024-03-15T10:00:00-04:00[America/New_York]",
84
- "en-US",
85
- { reference: ref },
86
- ); // "2 hours ago"
87
- ```
88
-
89
- Zoned arithmetic uses `Temporal.ZonedDateTime`, so spans that cross DST transitions ("fall back" / "spring forward") are still wall-clock-correct.
90
-
91
- ### Unix relative
92
-
93
- ```ts
94
- import { formatRelativeUnix } from "@northguild/gmt/unix";
95
-
96
- // Default epoch unit is milliseconds.
97
- formatRelativeUnix(1710507600000, "en-US", { reference: 1710511200000 });
98
- // "1 hour ago"
99
-
100
- // Switch to seconds via epochUnit.
101
- formatRelativeUnix(1710507600, "en-US", {
102
- reference: 1710511200,
103
- epochUnit: "seconds",
104
- }); // "1 hour ago"
105
- ```
106
-
107
- ### UTC relative
108
-
109
- ```ts
110
- import { formatRelativeUtc } from "@northguild/gmt/utc";
111
-
112
- formatRelativeUtc("2024-03-15T11:00:00Z", "en-US", {
113
- reference: "2024-03-15T12:00:00Z",
114
- }); // "1 hour ago"
115
- ```
116
-
117
- ## Shared options
118
-
119
- All relative formatters accept the same option shape (besides their type-specific `reference`):
120
-
121
- - `reference` — **required** anchor of the same input shape (e.g. an ISO date for `formatRelativeDate`).
122
- - `numeric: "auto" | "always"` — default `"auto"`.
123
- - `"auto"` produces phrases like `"yesterday"`, `"tomorrow"`, `"last week"`.
124
- - `"always"` forces numeric form: `"1 day ago"`, `"in 1 day"`.
125
- - `style: "long" | "short" | "narrow"` — default `"long"`.
126
- - `"long"`: `"3 minutes ago"`
127
- - `"short"`: `"3 min. ago"`
128
- - `"narrow"`: `"3m ago"`
129
- - `largestUnit` — pick a specific bucket (`"second" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year"`). Useful when you want `"3 weeks ago"` even though the difference would auto-bucket to `"last month"`.
130
- - `roundingMethod: "floor" | "ceil" | "round"` — default `"round"`. Controls how the fractional distance rounds to the display unit; `"floor"`/`"ceil"` apply directly to the signed value (not its absolute value), so they respect whether the distance is past or future.
131
-
132
- ## Runtime ICU data
133
-
134
- These formatters delegate locale rendering to the host runtime's `Intl.RelativeTimeFormat`. Output therefore depends on the ICU data shipped with the running Node (or browser):
135
-
136
- - **Full ICU** runtimes (official Node binaries from nodejs.org, all modern browsers) return fully localized strings — e.g. `formatRelativeDate("2023-03-15", "sv-SE", { reference: "2024-03-15" })` returns `"i fjol"`.
137
- - **Small/partial ICU** runtimes (some Node builds compiled with `--with-intl=small-icu` or repackaged distributions) fall back to a longer/different form — the same call may return `"förra året"`. Some locales (e.g. he-IL) also tack on a fallback numeric suffix like `"לפני שעתיים (2)"` instead of the full-ICU dual form `"לפני שעתיים"`.
138
-
139
- This is a property of the runtime, not gmt. For consistent non-English output, deploy on a full-ICU Node build or polyfill `Intl` with a package that bundles locale data.
140
-
141
- ## Common Mistakes
142
-
143
- ### HIGH Forgetting `reference`
144
-
145
- Wrong:
146
-
147
- ```ts
148
- formatRelativeDate("2024-03-12"); // "" — no anchor to diff against
149
- ```
150
-
151
- Correct:
152
-
153
- ```ts
154
- formatRelativeDate("2024-03-12", "en-US", { reference: "2024-03-15" });
155
- // "3 days ago"
156
- ```
157
-
158
- Source: `packages/gmt/src/plain/format/formatRelativeDate.ts` — `reference` is required.
159
-
160
- ### HIGH Mismatched input shape between value and reference
161
-
162
- Wrong:
163
-
164
- ```ts
165
- formatRelativeDate("2024-03-15T10:00:00", "en-US", {
166
- reference: "2024-03-15", // datetime as value, date as reference
167
- }); // ""
168
- ```
169
-
170
- Correct: match shapes — use `formatRelativeDateTime` for datetimes, `formatRelativeDate` for dates, etc.
171
-
172
- Source: each relative formatter validates its input shape and returns `""` on mismatch.
173
-
174
- ### HIGH Hand-rolling diff math with `Date`
175
-
176
- Wrong:
177
-
178
- ```ts
179
- const diffMs = new Date(value).getTime() - new Date(ref).getTime();
180
- const label = `${Math.round(diffMs / 60000)} minutes ago`; // ignores locale, DST
181
- ```
182
-
183
- Correct:
184
-
185
- ```ts
186
- import { formatRelativeDateTime } from "@northguild/gmt";
187
-
188
- formatRelativeDateTime(value, locale, { reference: ref });
189
- ```
190
-
191
- Source: AGENTS.md — Never use JavaScript Date APIs.
192
-
193
- ### MEDIUM Picking the wrong formatter for a Unix value
194
-
195
- Wrong:
196
-
197
- ```ts
198
- import { formatRelativeUtc } from "@northguild/gmt/utc";
199
-
200
- formatRelativeUtc(1710507600000, "en-US", { reference: 1710511200000 });
201
- // "" — formatRelativeUtc expects ISO strings, not numbers
202
- ```
203
-
204
- Correct:
205
-
206
- ```ts
207
- import { formatRelativeUnix } from "@northguild/gmt/unix";
208
-
209
- formatRelativeUnix(1710507600000, "en-US", { reference: 1710511200000 });
210
- // "1 hour ago"
211
- ```
212
-
213
- Source: `packages/gmt/src/unix/format/formatRelativeUnix.ts`.
214
-
215
- ### LOW Relying on `"auto"` numeric for tomorrow/yesterday wording
216
-
217
- `numeric: "auto"` produces the locale's natural words ("yesterday", "ayer", "gestern") only when the diff is exactly ±1 of the largest unit. Past that boundary it falls back to numeric ("2 days ago"). If you need a consistent word-form output, pair `numeric: "auto"` with `largestUnit` to force a specific bucket.
218
-
219
- ## References
220
-
221
- - [Intl.RelativeTimeFormat documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat)
222
- - [Format Date/Time skill](../format-date-time/SKILL.md) — for absolute formatting
223
- - [Zoned date operations skill](../zoned-date-ops/SKILL.md) — for timezone-aware operations
@@ -1,229 +0,0 @@
1
- ---
2
- name: get-current
3
- description: >
4
- Get the current date, time, or datetime as ISO 8601 strings. Use getNow(),
5
- getToday(), getSystemTimeZone(), or getTimeZones() for current temporal
6
- values. String output for logging; use Temporal for manipulation.
7
- sources:
8
- - 'northguild/gmt:packages/gmt/src/plain/get/getNow.ts'
9
- - 'northguild/gmt:packages/gmt/src/plain/get/getToday.ts'
10
- - 'northguild/gmt:packages/gmt/src/zoned/get/getSystemTimeZone.ts'
11
- - 'northguild/gmt:packages/gmt/src/zoned/get/getTimeZones.ts'
12
- - 'northguild/gmt:packages/gmt/src/utc/get/index.ts'
13
- - 'northguild/gmt:packages/gmt/src/unix/get/index.ts'
14
- metadata:
15
- type: core
16
- library: '@northguild/gmt'
17
- library_version: '1.14.2'
18
- ---
19
-
20
- # Get Current Date/Time
21
-
22
- Use this skill when you need to get the current date, time, or datetime.
23
-
24
- ## Setup
25
-
26
- ```ts
27
- import { getNow, getToday } from "@northguild/gmt";
28
- import { getSystemTimeZone, getTimeZones } from "@northguild/gmt/zoned";
29
- import { getUtcNow, getUtcToday } from "@northguild/gmt/utc";
30
- import { getUnixNow, getUnixTimeMs } from "@northguild/gmt/unix";
31
- ```
32
-
33
- ## Core Patterns
34
-
35
- ### Get current local date
36
-
37
- ```ts
38
- // Returns current date as ISO string in system timezone
39
- const today = getToday(); // "2024-03-15"
40
- ```
41
-
42
- ### Get current local datetime
43
-
44
- ```ts
45
- // Returns current datetime as ISO string in system timezone
46
- const now = getNow(); // "2024-03-15T14:30:45"
47
- ```
48
-
49
- ### Get current UTC date
50
-
51
- ```ts
52
- import { getUtcToday } from "@northguild/gmt/utc";
53
-
54
- const utcToday = getUtcToday(); // "2024-03-15"
55
- ```
56
-
57
- ### Get current UTC datetime
58
-
59
- ```ts
60
- import { getUtcNow } from "@northguild/gmt/utc";
61
-
62
- const utcNow = getUtcNow(); // "2024-03-15T14:30:45"
63
- ```
64
-
65
- ### Get current Unix timestamp (seconds)
66
-
67
- ```ts
68
- import { getUnixNow } from "@northguild/gmt/unix";
69
-
70
- const unixNow = getUnixNow(); // 1710504645
71
- ```
72
-
73
- ### Get current Unix timestamp (milliseconds)
74
-
75
- ```ts
76
- import { getUnixTimeMs } from "@northguild/gmt/unix";
77
-
78
- const unixMs = getUnixTimeMs(); // 1710504645000
79
- ```
80
-
81
- ### Get the system timezone
82
-
83
- ```ts
84
- import { getSystemTimeZone } from "@northguild/gmt/zoned";
85
-
86
- const tz = getSystemTimeZone(); // "America/New_York"
87
- ```
88
-
89
- ### Get all available IANA timezones
90
-
91
- ```ts
92
- import { getTimeZones } from "@northguild/gmt/zoned";
93
-
94
- const timeZones = getTimeZones(); // ["America/New_York", "Europe/London", ...]
95
- timeZones.length; // ~422 (varies by runtime/ICU)
96
- ```
97
-
98
- ### Using Temporal directly for manipulation
99
-
100
- ```ts
101
- import { Temporal } from "@js-temporal/polyfill";
102
-
103
- // Current instant for precise timing
104
- const instant = Temporal.Now.instant(); // Temporal.Instant
105
-
106
- // Current plain date in system timezone
107
- const plainDate = Temporal.Now.plainDateISO(); // Temporal.PlainDate
108
-
109
- // Current plain datetime in system timezone
110
- const plainDateTime = Temporal.Now.plainDateTimeISO(); // Temporal.PlainDateTime
111
-
112
- // Current zoned datetime in system timezone
113
- const zonedDateTime = Temporal.Now.zonedDateTimeISO("America/New_York"); // Temporal.ZonedDateTime
114
- ```
115
-
116
- ## Common Mistakes
117
-
118
- ### CRITICAL Using Date.now() instead of Temporal
119
-
120
- Wrong:
121
-
122
- ```ts
123
- const now = Date.now(); // returns milliseconds number
124
- ```
125
-
126
- Correct:
127
-
128
- ```ts
129
- import { getUnixNow } from "@northguild/gmt/unix";
130
-
131
- const now = getUnixNow(); // returns number in seconds
132
- ```
133
-
134
- Source: AGENTS.md — Never use JavaScript Date APIs
135
-
136
- ### HIGH Using new Date() for current time
137
-
138
- Wrong:
139
-
140
- ```ts
141
- const now = new Date(); // mutable Date object
142
- ```
143
-
144
- Correct:
145
-
146
- ```ts
147
- import { getNow } from "@northguild/gmt";
148
-
149
- const now = getNow(); // immutable ISO string
150
- ```
151
-
152
- Source: AGENTS.md — String-only inputs/outputs
153
-
154
- ### MEDIUM Not handling empty string on error
155
-
156
- Wrong:
157
-
158
- ```ts
159
- const now = getToday();
160
- // Assume now is always valid
161
- process(now);
162
- ```
163
-
164
- Correct:
165
-
166
- ```ts
167
- const now = getToday();
168
- if (!now) {
169
- throw new Error("Failed to get current date");
170
- }
171
- process(now);
172
- ```
173
-
174
- Source: packages/gmt/src/plain/get/getNow.ts — Returns "" on error
175
-
176
- ### MEDIUM Looking for value-taking `get*` functions here
177
-
178
- `getDaysInMonth`, `getDaysInYear`, `getDayOfYear`, `getWeeksInYear`,
179
- `getWeeksInMonth`, `getWeekOfMonth`, `getWeekYear`, `getLocaleWeekYear`,
180
- and `getWeeksInLocaleWeekYear` take a date value, so despite the
181
- `get` prefix they live in `calculate/`, not `get/`. GMT's `get/` namespaces
182
- are current-moment accessors only (no argument, or timezone only) — see
183
- `context/coding-standards.md`'s API Contract section.
184
-
185
- Wrong:
186
-
187
- ```ts
188
- import { getDaysInMonth } from "@northguild/gmt/plain/get"; // not exported here
189
- ```
190
-
191
- ### MEDIUM Bucketing by week number without its week-year
192
-
193
- `weekOfYearForDate`/`getWeekNumber` return a week number alone (1-53),
194
- which is ambiguous across a year boundary: 2024-12-30 is a Monday in ISO
195
- week 1, but of **2025**, not 2024. A date-only week number will silently
196
- land December dates in the wrong bucket. Pair it with `getWeekYear`
197
- (ISO) or `getLocaleWeekYear` (locale-relative) whenever you bucket or key
198
- by week.
199
-
200
- Wrong:
201
-
202
- ```ts
203
- const bucketKey = weekOfYearForDate(value); // "1" — but which year's week 1?
204
- ```
205
-
206
- Correct:
207
-
208
- ```ts
209
- import { getWeekYear, weekOfYearForDate } from "@northguild/gmt";
210
-
211
- const bucketKey = `${getWeekYear(value)}-W${weekOfYearForDate(value)}`;
212
- ```
213
-
214
- Source: packages/gmt/src/plain/calculate/getWeekYear.ts, getLocaleWeekYear.ts, getWeeksInLocaleWeekYear.ts
215
-
216
- Correct:
217
-
218
- ```ts
219
- import { getDaysInMonth } from "@northguild/gmt"; // or "@northguild/gmt/plain/calculate"
220
-
221
- getDaysInMonth("2024-02-15"); // 29
222
- ```
223
-
224
- Source: context/coding-standards.md — `get/` namespaces hold current-moment accessors only
225
-
226
- ## References
227
-
228
- - [Full get API](references/get-api.md)
229
- - [Temporal.Now documentation](https://tc39.es/proposal-temporal/docs/now.html)