@gobrand/tiempo 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/dist/chunk-5FRUAUH2.js +329 -0
- package/dist/chunk-5FRUAUH2.js.map +1 -0
- package/dist/format.d.ts +29 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +7 -0
- package/dist/format.js.map +1 -0
- package/dist/format.test.d.ts +2 -0
- package/dist/format.test.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/toUtc.test.d.ts +2 -0
- package/dist/toUtc.test.d.ts.map +1 -0
- package/dist/toUtcString.test.d.ts +2 -0
- package/dist/toUtcString.test.d.ts.map +1 -0
- package/dist/toZonedTime.test.d.ts +2 -0
- package/dist/toZonedTime.test.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,6 +116,57 @@ const iso2 = toUtcString(instant);
|
|
|
116
116
|
console.log(iso2); // "2025-01-20T20:00:00Z"
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
+
### `format(input, formatStr, options?)`
|
|
120
|
+
|
|
121
|
+
Format a Temporal.Instant or ZonedDateTime using date-fns-like format tokens.
|
|
122
|
+
|
|
123
|
+
**Parameters:**
|
|
124
|
+
- `input` (Temporal.Instant | Temporal.ZonedDateTime): A Temporal.Instant or Temporal.ZonedDateTime to format
|
|
125
|
+
- `formatStr` (string): Format string using date-fns tokens (e.g., "yyyy-MM-dd HH:mm:ss")
|
|
126
|
+
- `options` (FormatOptions, optional): Configuration for locale and timezone
|
|
127
|
+
- `locale` (string): BCP 47 language tag (default: "en-US")
|
|
128
|
+
- `timeZone` (string): IANA timezone identifier to convert to before formatting
|
|
129
|
+
|
|
130
|
+
**Returns:** `string` - Formatted date string
|
|
131
|
+
|
|
132
|
+
**Supported tokens:**
|
|
133
|
+
- **Year**: `yyyy` (2025), `yy` (25), `y` (2025)
|
|
134
|
+
- **Month**: `MMMM` (January), `MMM` (Jan), `MM` (01), `M` (1), `Mo` (1st)
|
|
135
|
+
- **Day**: `dd` (20), `d` (20), `do` (20th)
|
|
136
|
+
- **Weekday**: `EEEE` (Monday), `EEE` (Mon), `EEEEE` (M)
|
|
137
|
+
- **Hour**: `HH` (15, 24h), `H` (15), `hh` (03, 12h), `h` (3)
|
|
138
|
+
- **Minute**: `mm` (30), `m` (30)
|
|
139
|
+
- **Second**: `ss` (45), `s` (45)
|
|
140
|
+
- **AM/PM**: `a` (PM), `aa` (PM), `aaa` (pm), `aaaa` (p.m.), `aaaaa` (p)
|
|
141
|
+
- **Timezone**: `xxx` (-05:00), `xx` (-0500), `XXX` (Z or -05:00), `zzzz` (Eastern Standard Time)
|
|
142
|
+
- **Quarter**: `Q` (1), `QQQ` (Q1), `QQQQ` (1st quarter)
|
|
143
|
+
- **Milliseconds**: `SSS` (123)
|
|
144
|
+
- **Timestamp**: `T` (milliseconds), `t` (seconds)
|
|
145
|
+
- **Escape text**: Use single quotes `'...'`, double single quotes `''` for literal quote
|
|
146
|
+
|
|
147
|
+
**Example:**
|
|
148
|
+
```typescript
|
|
149
|
+
import { format, toZonedTime, toUtc } from '@gobrand/tiempo';
|
|
150
|
+
|
|
151
|
+
// From ISO string to ZonedDateTime, then format
|
|
152
|
+
const isoString = "2025-01-20T20:30:45.000Z";
|
|
153
|
+
const zoned = toZonedTime(isoString, "America/New_York");
|
|
154
|
+
|
|
155
|
+
format(zoned, "yyyy-MM-dd"); // "2025-01-20"
|
|
156
|
+
format(zoned, "MMMM d, yyyy"); // "January 20, 2025"
|
|
157
|
+
format(zoned, "h:mm a"); // "3:30 PM"
|
|
158
|
+
format(zoned, "EEEE, MMMM do, yyyy 'at' h:mm a"); // "Monday, January 20th, 2025 at 3:30 PM"
|
|
159
|
+
|
|
160
|
+
// With locale
|
|
161
|
+
format(zoned, "MMMM d, yyyy", { locale: "es-ES" }); // "enero 20, 2025"
|
|
162
|
+
format(zoned, "EEEE", { locale: "fr-FR" }); // "lundi"
|
|
163
|
+
|
|
164
|
+
// From ISO string to Instant (UTC), then format with timezone conversion
|
|
165
|
+
const instant = toUtc(isoString);
|
|
166
|
+
format(instant, "yyyy-MM-dd HH:mm", { timeZone: "America/New_York" }); // "2025-01-20 15:30"
|
|
167
|
+
format(instant, "yyyy-MM-dd HH:mm", { timeZone: "Asia/Tokyo" }); // "2025-01-21 05:30"
|
|
168
|
+
```
|
|
169
|
+
|
|
119
170
|
## Complete Workflow Example
|
|
120
171
|
|
|
121
172
|
```typescript
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
// src/format.ts
|
|
2
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
3
|
+
function format(input, formatStr, options = {}) {
|
|
4
|
+
const { locale = "en-US", timeZone } = options;
|
|
5
|
+
let zonedDateTime;
|
|
6
|
+
if (input instanceof Temporal.Instant) {
|
|
7
|
+
const tz = timeZone || "UTC";
|
|
8
|
+
zonedDateTime = input.toZonedDateTimeISO(tz);
|
|
9
|
+
} else {
|
|
10
|
+
zonedDateTime = timeZone ? input.toInstant().toZonedDateTimeISO(timeZone) : input;
|
|
11
|
+
}
|
|
12
|
+
let result = "";
|
|
13
|
+
let i = 0;
|
|
14
|
+
const len = formatStr.length;
|
|
15
|
+
while (i < len) {
|
|
16
|
+
const char = formatStr[i];
|
|
17
|
+
if (!char) break;
|
|
18
|
+
if (char === "'") {
|
|
19
|
+
if (i + 1 < len && formatStr[i + 1] === "'") {
|
|
20
|
+
result += "'";
|
|
21
|
+
i += 2;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
i++;
|
|
25
|
+
while (i < len) {
|
|
26
|
+
if (formatStr[i] === "'") {
|
|
27
|
+
if (i + 1 < len && formatStr[i + 1] === "'") {
|
|
28
|
+
result += "'";
|
|
29
|
+
i += 2;
|
|
30
|
+
} else {
|
|
31
|
+
i++;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
result += formatStr[i];
|
|
36
|
+
i++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const token = consumeToken(formatStr, i, char);
|
|
42
|
+
if (token !== null) {
|
|
43
|
+
result += formatToken(token, zonedDateTime, locale);
|
|
44
|
+
i += token.length;
|
|
45
|
+
} else {
|
|
46
|
+
result += char;
|
|
47
|
+
i++;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
function consumeToken(formatStr, start, char) {
|
|
53
|
+
if (char === "M" && start + 1 < formatStr.length && formatStr[start + 1] === "o") {
|
|
54
|
+
return "Mo";
|
|
55
|
+
}
|
|
56
|
+
if (char === "d" && start + 1 < formatStr.length && formatStr[start + 1] === "o") {
|
|
57
|
+
return "do";
|
|
58
|
+
}
|
|
59
|
+
let end = start;
|
|
60
|
+
while (end < formatStr.length && formatStr[end] === char) {
|
|
61
|
+
end++;
|
|
62
|
+
}
|
|
63
|
+
const count = end - start;
|
|
64
|
+
const validTokens = [
|
|
65
|
+
"GGGGG",
|
|
66
|
+
"GGGG",
|
|
67
|
+
"GGG",
|
|
68
|
+
"GG",
|
|
69
|
+
"G",
|
|
70
|
+
"yyyy",
|
|
71
|
+
"yyy",
|
|
72
|
+
"yy",
|
|
73
|
+
"y",
|
|
74
|
+
"QQQQQ",
|
|
75
|
+
"QQQQ",
|
|
76
|
+
"QQQ",
|
|
77
|
+
"QQ",
|
|
78
|
+
"Q",
|
|
79
|
+
"MMMMM",
|
|
80
|
+
"MMMM",
|
|
81
|
+
"MMM",
|
|
82
|
+
"MM",
|
|
83
|
+
"M",
|
|
84
|
+
"dd",
|
|
85
|
+
"d",
|
|
86
|
+
"EEEEEE",
|
|
87
|
+
"EEEEE",
|
|
88
|
+
"EEEE",
|
|
89
|
+
"EEE",
|
|
90
|
+
"EE",
|
|
91
|
+
"E",
|
|
92
|
+
"aaaaa",
|
|
93
|
+
"aaaa",
|
|
94
|
+
"aaa",
|
|
95
|
+
"aa",
|
|
96
|
+
"a",
|
|
97
|
+
"HH",
|
|
98
|
+
"H",
|
|
99
|
+
"hh",
|
|
100
|
+
"h",
|
|
101
|
+
"mm",
|
|
102
|
+
"m",
|
|
103
|
+
"ss",
|
|
104
|
+
"s",
|
|
105
|
+
"SSS",
|
|
106
|
+
"SS",
|
|
107
|
+
"S",
|
|
108
|
+
"XXXXX",
|
|
109
|
+
"XXXX",
|
|
110
|
+
"XXX",
|
|
111
|
+
"XX",
|
|
112
|
+
"X",
|
|
113
|
+
"xxxxx",
|
|
114
|
+
"xxxx",
|
|
115
|
+
"xxx",
|
|
116
|
+
"xx",
|
|
117
|
+
"x",
|
|
118
|
+
"zzzz",
|
|
119
|
+
"zzz",
|
|
120
|
+
"zz",
|
|
121
|
+
"z",
|
|
122
|
+
"T",
|
|
123
|
+
"t"
|
|
124
|
+
];
|
|
125
|
+
for (let len = Math.min(count, 6); len > 0; len--) {
|
|
126
|
+
const candidate = char.repeat(len);
|
|
127
|
+
if (validTokens.includes(candidate)) {
|
|
128
|
+
return candidate;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
function formatToken(token, zonedDateTime, locale) {
|
|
134
|
+
switch (token) {
|
|
135
|
+
// Era
|
|
136
|
+
case "GGGGG":
|
|
137
|
+
return formatPart(zonedDateTime, "era", "narrow", locale);
|
|
138
|
+
case "GGGG":
|
|
139
|
+
return formatPart(zonedDateTime, "era", "long", locale);
|
|
140
|
+
case "GGG":
|
|
141
|
+
case "GG":
|
|
142
|
+
case "G":
|
|
143
|
+
return formatPart(zonedDateTime, "era", "short", locale);
|
|
144
|
+
// Year
|
|
145
|
+
case "yyyy":
|
|
146
|
+
return zonedDateTime.year.toString().padStart(4, "0");
|
|
147
|
+
case "yyy":
|
|
148
|
+
return zonedDateTime.year.toString().padStart(3, "0");
|
|
149
|
+
case "yy":
|
|
150
|
+
return (zonedDateTime.year % 100).toString().padStart(2, "0");
|
|
151
|
+
case "y":
|
|
152
|
+
return zonedDateTime.year.toString();
|
|
153
|
+
// Quarter
|
|
154
|
+
case "QQQQQ":
|
|
155
|
+
return Math.ceil(zonedDateTime.month / 3).toString();
|
|
156
|
+
case "QQQQ": {
|
|
157
|
+
const quarter = Math.ceil(zonedDateTime.month / 3);
|
|
158
|
+
return `${quarter}${getOrdinalSuffix(quarter)} quarter`;
|
|
159
|
+
}
|
|
160
|
+
case "QQQ":
|
|
161
|
+
return `Q${Math.ceil(zonedDateTime.month / 3)}`;
|
|
162
|
+
case "QQ":
|
|
163
|
+
return Math.ceil(zonedDateTime.month / 3).toString().padStart(2, "0");
|
|
164
|
+
case "Q":
|
|
165
|
+
return Math.ceil(zonedDateTime.month / 3).toString();
|
|
166
|
+
// Month
|
|
167
|
+
case "MMMMM":
|
|
168
|
+
return formatPart(zonedDateTime, "month", "narrow", locale);
|
|
169
|
+
case "MMMM":
|
|
170
|
+
return formatPart(zonedDateTime, "month", "long", locale);
|
|
171
|
+
case "MMM":
|
|
172
|
+
return formatPart(zonedDateTime, "month", "short", locale);
|
|
173
|
+
case "MM":
|
|
174
|
+
return zonedDateTime.month.toString().padStart(2, "0");
|
|
175
|
+
case "Mo":
|
|
176
|
+
return `${zonedDateTime.month}${getOrdinalSuffix(zonedDateTime.month)}`;
|
|
177
|
+
case "M":
|
|
178
|
+
return zonedDateTime.month.toString();
|
|
179
|
+
// Day of month
|
|
180
|
+
case "do":
|
|
181
|
+
return `${zonedDateTime.day}${getOrdinalSuffix(zonedDateTime.day)}`;
|
|
182
|
+
case "dd":
|
|
183
|
+
return zonedDateTime.day.toString().padStart(2, "0");
|
|
184
|
+
case "d":
|
|
185
|
+
return zonedDateTime.day.toString();
|
|
186
|
+
// Day of week
|
|
187
|
+
case "EEEEEE":
|
|
188
|
+
return formatPart(zonedDateTime, "weekday", "short", locale).slice(0, 2);
|
|
189
|
+
case "EEEEE":
|
|
190
|
+
return formatPart(zonedDateTime, "weekday", "narrow", locale);
|
|
191
|
+
case "EEEE":
|
|
192
|
+
return formatPart(zonedDateTime, "weekday", "long", locale);
|
|
193
|
+
case "EEE":
|
|
194
|
+
case "EE":
|
|
195
|
+
case "E":
|
|
196
|
+
return formatPart(zonedDateTime, "weekday", "short", locale);
|
|
197
|
+
// AM/PM
|
|
198
|
+
case "aaaaa": {
|
|
199
|
+
const period = formatPart(zonedDateTime, "dayPeriod", "narrow", locale).toLowerCase();
|
|
200
|
+
return period.charAt(0);
|
|
201
|
+
}
|
|
202
|
+
case "aaaa": {
|
|
203
|
+
const period = formatPart(zonedDateTime, "dayPeriod", "short", locale);
|
|
204
|
+
return period === "AM" ? "a.m." : "p.m.";
|
|
205
|
+
}
|
|
206
|
+
case "aaa":
|
|
207
|
+
return formatPart(zonedDateTime, "dayPeriod", "short", locale).toLowerCase();
|
|
208
|
+
case "aa":
|
|
209
|
+
case "a":
|
|
210
|
+
return formatPart(zonedDateTime, "dayPeriod", "short", locale);
|
|
211
|
+
// Hour [0-23]
|
|
212
|
+
case "HH":
|
|
213
|
+
return zonedDateTime.hour.toString().padStart(2, "0");
|
|
214
|
+
case "H":
|
|
215
|
+
return zonedDateTime.hour.toString();
|
|
216
|
+
// Hour [1-12]
|
|
217
|
+
case "hh": {
|
|
218
|
+
const hour12 = zonedDateTime.hour % 12 || 12;
|
|
219
|
+
return hour12.toString().padStart(2, "0");
|
|
220
|
+
}
|
|
221
|
+
case "h": {
|
|
222
|
+
const hour12 = zonedDateTime.hour % 12 || 12;
|
|
223
|
+
return hour12.toString();
|
|
224
|
+
}
|
|
225
|
+
// Minute
|
|
226
|
+
case "mm":
|
|
227
|
+
return zonedDateTime.minute.toString().padStart(2, "0");
|
|
228
|
+
case "m":
|
|
229
|
+
return zonedDateTime.minute.toString();
|
|
230
|
+
// Second
|
|
231
|
+
case "ss":
|
|
232
|
+
return zonedDateTime.second.toString().padStart(2, "0");
|
|
233
|
+
case "s":
|
|
234
|
+
return zonedDateTime.second.toString();
|
|
235
|
+
// Fractional seconds
|
|
236
|
+
case "SSS":
|
|
237
|
+
return zonedDateTime.millisecond.toString().padStart(3, "0");
|
|
238
|
+
case "SS":
|
|
239
|
+
return Math.floor(zonedDateTime.millisecond / 10).toString().padStart(2, "0");
|
|
240
|
+
case "S":
|
|
241
|
+
return Math.floor(zonedDateTime.millisecond / 100).toString();
|
|
242
|
+
// Timezone
|
|
243
|
+
case "XXXXX": {
|
|
244
|
+
const offset = getTimezoneOffset(zonedDateTime);
|
|
245
|
+
return offset === "+00:00" ? "Z" : offset;
|
|
246
|
+
}
|
|
247
|
+
case "XXXX": {
|
|
248
|
+
const offset = getTimezoneOffset(zonedDateTime).replace(":", "");
|
|
249
|
+
return offset === "+0000" ? "Z" : offset;
|
|
250
|
+
}
|
|
251
|
+
case "XXX": {
|
|
252
|
+
const offset = getTimezoneOffset(zonedDateTime);
|
|
253
|
+
return offset === "+00:00" ? "Z" : offset;
|
|
254
|
+
}
|
|
255
|
+
case "XX": {
|
|
256
|
+
const offset = getTimezoneOffset(zonedDateTime).replace(":", "");
|
|
257
|
+
return offset === "+0000" ? "Z" : offset;
|
|
258
|
+
}
|
|
259
|
+
case "X": {
|
|
260
|
+
const offset = getTimezoneOffset(zonedDateTime);
|
|
261
|
+
if (offset === "+00:00") return "Z";
|
|
262
|
+
const [hours] = offset.split(":");
|
|
263
|
+
return hours || "+00";
|
|
264
|
+
}
|
|
265
|
+
case "xxxxx":
|
|
266
|
+
return getTimezoneOffset(zonedDateTime);
|
|
267
|
+
case "xxxx":
|
|
268
|
+
return getTimezoneOffset(zonedDateTime).replace(":", "");
|
|
269
|
+
case "xxx":
|
|
270
|
+
return getTimezoneOffset(zonedDateTime);
|
|
271
|
+
case "xx":
|
|
272
|
+
return getTimezoneOffset(zonedDateTime).replace(":", "");
|
|
273
|
+
case "x": {
|
|
274
|
+
const offset = getTimezoneOffset(zonedDateTime);
|
|
275
|
+
const [hours] = offset.split(":");
|
|
276
|
+
return hours || "+00";
|
|
277
|
+
}
|
|
278
|
+
case "zzzz":
|
|
279
|
+
return formatPart(zonedDateTime, "timeZoneName", "long", locale);
|
|
280
|
+
case "zzz":
|
|
281
|
+
case "zz":
|
|
282
|
+
case "z":
|
|
283
|
+
return formatPart(zonedDateTime, "timeZoneName", "short", locale);
|
|
284
|
+
// Timestamps
|
|
285
|
+
case "T":
|
|
286
|
+
return zonedDateTime.epochMilliseconds.toString();
|
|
287
|
+
case "t":
|
|
288
|
+
return Math.floor(zonedDateTime.epochMilliseconds / 1e3).toString();
|
|
289
|
+
default:
|
|
290
|
+
return token;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function formatPart(zonedDateTime, part, style, locale) {
|
|
294
|
+
const options = {};
|
|
295
|
+
if (part === "dayPeriod") {
|
|
296
|
+
options.hour = "numeric";
|
|
297
|
+
options.hour12 = true;
|
|
298
|
+
} else {
|
|
299
|
+
options[part] = style;
|
|
300
|
+
}
|
|
301
|
+
const formatted = zonedDateTime.toLocaleString(locale, options);
|
|
302
|
+
if (part === "dayPeriod") {
|
|
303
|
+
const match = formatted.match(/\b(AM|PM|am|pm|a\.m\.|p\.m\.)\b/);
|
|
304
|
+
return match ? match[0] : formatted.split(" ").pop() || "";
|
|
305
|
+
}
|
|
306
|
+
return formatted;
|
|
307
|
+
}
|
|
308
|
+
function getOrdinalSuffix(num) {
|
|
309
|
+
const j = num % 10;
|
|
310
|
+
const k = num % 100;
|
|
311
|
+
if (j === 1 && k !== 11) return "st";
|
|
312
|
+
if (j === 2 && k !== 12) return "nd";
|
|
313
|
+
if (j === 3 && k !== 13) return "rd";
|
|
314
|
+
return "th";
|
|
315
|
+
}
|
|
316
|
+
function getTimezoneOffset(zonedDateTime) {
|
|
317
|
+
const offsetNs = zonedDateTime.offsetNanoseconds;
|
|
318
|
+
const offsetMinutes = offsetNs / (60 * 1e9);
|
|
319
|
+
const sign = offsetMinutes >= 0 ? "+" : "-";
|
|
320
|
+
const absMinutes = Math.abs(offsetMinutes);
|
|
321
|
+
const hours = Math.floor(absMinutes / 60);
|
|
322
|
+
const minutes = absMinutes % 60;
|
|
323
|
+
return `${sign}${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}`;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export {
|
|
327
|
+
format
|
|
328
|
+
};
|
|
329
|
+
//# sourceMappingURL=chunk-5FRUAUH2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill';\n\nexport interface FormatOptions {\n locale?: string;\n timeZone?: string;\n}\n\n/**\n * Format a Temporal.Instant or ZonedDateTime using date-fns-like format tokens.\n * Uses Intl.DateTimeFormat under the hood via Temporal's toLocaleString() for zero dependencies.\n *\n * @param input - A Temporal.Instant or Temporal.ZonedDateTime to format\n * @param formatStr - Format string using date-fns tokens (e.g., \"yyyy-MM-dd HH:mm:ss\")\n * @param options - Optional configuration for locale and timezone\n * @returns Formatted date string\n *\n * @example\n * ```typescript\n * const zoned = Temporal.ZonedDateTime.from(\"2025-01-20T15:00:00-05:00[America/New_York]\");\n *\n * format(zoned, \"yyyy-MM-dd\"); // \"2025-01-20\"\n * format(zoned, \"MMMM d, yyyy\"); // \"January 20, 2025\"\n * format(zoned, \"h:mm a\"); // \"3:00 PM\"\n * format(zoned, \"EEEE, MMMM do, yyyy 'at' h:mm a\"); // \"Monday, January 20th, 2025 at 3:00 PM\"\n *\n * // With locale\n * format(zoned, \"MMMM d, yyyy\", { locale: \"es-ES\" }); // \"enero 20, 2025\"\n * ```\n */\nexport function format(\n input: Temporal.Instant | Temporal.ZonedDateTime,\n formatStr: string,\n options: FormatOptions = {}\n): string {\n const { locale = 'en-US', timeZone } = options;\n\n // Convert Instant to ZonedDateTime if needed\n let zonedDateTime: Temporal.ZonedDateTime;\n if (input instanceof Temporal.Instant) {\n const tz = timeZone || 'UTC';\n zonedDateTime = input.toZonedDateTimeISO(tz);\n } else {\n zonedDateTime = timeZone\n ? input.toInstant().toZonedDateTimeISO(timeZone)\n : input;\n }\n\n let result = '';\n let i = 0;\n const len = formatStr.length;\n\n while (i < len) {\n const char = formatStr[i];\n if (!char) break;\n\n // Handle escaped text\n if (char === \"'\") {\n // Check for double single quote (not inside a string, just '')\n if (i + 1 < len && formatStr[i + 1] === \"'\") {\n result += \"'\";\n i += 2;\n continue;\n }\n // Find closing quote, handling '' inside the string\n i++;\n while (i < len) {\n if (formatStr[i] === \"'\") {\n // Check if it's a doubled quote ''\n if (i + 1 < len && formatStr[i + 1] === \"'\") {\n result += \"'\";\n i += 2;\n } else {\n // End of quoted string\n i++;\n break;\n }\n } else {\n result += formatStr[i];\n i++;\n }\n }\n continue;\n }\n\n // Check for tokens by looking ahead\n const token = consumeToken(formatStr, i, char);\n if (token !== null) {\n result += formatToken(token, zonedDateTime, locale);\n i += token.length;\n } else {\n result += char;\n i++;\n }\n }\n\n return result;\n}\n\nfunction consumeToken(formatStr: string, start: number, char: string): string | null {\n // Special case for 'Mo' and 'do' - these end with 'o'\n if (char === 'M' && start + 1 < formatStr.length && formatStr[start + 1] === 'o') {\n return 'Mo';\n }\n if (char === 'd' && start + 1 < formatStr.length && formatStr[start + 1] === 'o') {\n return 'do';\n }\n\n // Count how many consecutive identical characters\n let end = start;\n while (end < formatStr.length && formatStr[end] === char) {\n end++;\n }\n const count = end - start;\n\n // Check if this is a valid token pattern\n const validTokens = [\n 'GGGGG',\n 'GGGG',\n 'GGG',\n 'GG',\n 'G',\n 'yyyy',\n 'yyy',\n 'yy',\n 'y',\n 'QQQQQ',\n 'QQQQ',\n 'QQQ',\n 'QQ',\n 'Q',\n 'MMMMM',\n 'MMMM',\n 'MMM',\n 'MM',\n 'M',\n 'dd',\n 'd',\n 'EEEEEE',\n 'EEEEE',\n 'EEEE',\n 'EEE',\n 'EE',\n 'E',\n 'aaaaa',\n 'aaaa',\n 'aaa',\n 'aa',\n 'a',\n 'HH',\n 'H',\n 'hh',\n 'h',\n 'mm',\n 'm',\n 'ss',\n 's',\n 'SSS',\n 'SS',\n 'S',\n 'XXXXX',\n 'XXXX',\n 'XXX',\n 'XX',\n 'X',\n 'xxxxx',\n 'xxxx',\n 'xxx',\n 'xx',\n 'x',\n 'zzzz',\n 'zzz',\n 'zz',\n 'z',\n 'T',\n 't',\n ];\n\n // Try to match from longest to shortest\n for (let len = Math.min(count, 6); len > 0; len--) {\n const candidate = char.repeat(len);\n if (validTokens.includes(candidate)) {\n return candidate;\n }\n }\n\n return null;\n}\n\nfunction formatToken(token: string, zonedDateTime: Temporal.ZonedDateTime, locale: string): string {\n switch (token) {\n // Era\n case 'GGGGG':\n return formatPart(zonedDateTime, 'era', 'narrow', locale);\n case 'GGGG':\n return formatPart(zonedDateTime, 'era', 'long', locale);\n case 'GGG':\n case 'GG':\n case 'G':\n return formatPart(zonedDateTime, 'era', 'short', locale);\n\n // Year\n case 'yyyy':\n return zonedDateTime.year.toString().padStart(4, '0');\n case 'yyy':\n return zonedDateTime.year.toString().padStart(3, '0');\n case 'yy':\n return (zonedDateTime.year % 100).toString().padStart(2, '0');\n case 'y':\n return zonedDateTime.year.toString();\n\n // Quarter\n case 'QQQQQ':\n return Math.ceil(zonedDateTime.month / 3).toString();\n case 'QQQQ': {\n const quarter = Math.ceil(zonedDateTime.month / 3);\n return `${quarter}${getOrdinalSuffix(quarter)} quarter`;\n }\n case 'QQQ':\n return `Q${Math.ceil(zonedDateTime.month / 3)}`;\n case 'QQ':\n return Math.ceil(zonedDateTime.month / 3)\n .toString()\n .padStart(2, '0');\n case 'Q':\n return Math.ceil(zonedDateTime.month / 3).toString();\n\n // Month\n case 'MMMMM':\n return formatPart(zonedDateTime, 'month', 'narrow', locale);\n case 'MMMM':\n return formatPart(zonedDateTime, 'month', 'long', locale);\n case 'MMM':\n return formatPart(zonedDateTime, 'month', 'short', locale);\n case 'MM':\n return zonedDateTime.month.toString().padStart(2, '0');\n case 'Mo':\n return `${zonedDateTime.month}${getOrdinalSuffix(zonedDateTime.month)}`;\n case 'M':\n return zonedDateTime.month.toString();\n\n // Day of month\n case 'do':\n return `${zonedDateTime.day}${getOrdinalSuffix(zonedDateTime.day)}`;\n case 'dd':\n return zonedDateTime.day.toString().padStart(2, '0');\n case 'd':\n return zonedDateTime.day.toString();\n\n // Day of week\n case 'EEEEEE':\n return formatPart(zonedDateTime, 'weekday', 'short', locale).slice(0, 2);\n case 'EEEEE':\n return formatPart(zonedDateTime, 'weekday', 'narrow', locale);\n case 'EEEE':\n return formatPart(zonedDateTime, 'weekday', 'long', locale);\n case 'EEE':\n case 'EE':\n case 'E':\n return formatPart(zonedDateTime, 'weekday', 'short', locale);\n\n // AM/PM\n case 'aaaaa': {\n const period = formatPart(zonedDateTime, 'dayPeriod', 'narrow', locale).toLowerCase();\n return period.charAt(0);\n }\n case 'aaaa': {\n const period = formatPart(zonedDateTime, 'dayPeriod', 'short', locale);\n return period === 'AM' ? 'a.m.' : 'p.m.';\n }\n case 'aaa':\n return formatPart(zonedDateTime, 'dayPeriod', 'short', locale).toLowerCase();\n case 'aa':\n case 'a':\n return formatPart(zonedDateTime, 'dayPeriod', 'short', locale);\n\n // Hour [0-23]\n case 'HH':\n return zonedDateTime.hour.toString().padStart(2, '0');\n case 'H':\n return zonedDateTime.hour.toString();\n\n // Hour [1-12]\n case 'hh': {\n const hour12 = zonedDateTime.hour % 12 || 12;\n return hour12.toString().padStart(2, '0');\n }\n case 'h': {\n const hour12 = zonedDateTime.hour % 12 || 12;\n return hour12.toString();\n }\n\n // Minute\n case 'mm':\n return zonedDateTime.minute.toString().padStart(2, '0');\n case 'm':\n return zonedDateTime.minute.toString();\n\n // Second\n case 'ss':\n return zonedDateTime.second.toString().padStart(2, '0');\n case 's':\n return zonedDateTime.second.toString();\n\n // Fractional seconds\n case 'SSS':\n return zonedDateTime.millisecond.toString().padStart(3, '0');\n case 'SS':\n return Math.floor(zonedDateTime.millisecond / 10)\n .toString()\n .padStart(2, '0');\n case 'S':\n return Math.floor(zonedDateTime.millisecond / 100).toString();\n\n // Timezone\n case 'XXXXX': {\n const offset = getTimezoneOffset(zonedDateTime);\n return offset === '+00:00' ? 'Z' : offset;\n }\n case 'XXXX': {\n const offset = getTimezoneOffset(zonedDateTime).replace(':', '');\n return offset === '+0000' ? 'Z' : offset;\n }\n case 'XXX': {\n const offset = getTimezoneOffset(zonedDateTime);\n return offset === '+00:00' ? 'Z' : offset;\n }\n case 'XX': {\n const offset = getTimezoneOffset(zonedDateTime).replace(':', '');\n return offset === '+0000' ? 'Z' : offset;\n }\n case 'X': {\n const offset = getTimezoneOffset(zonedDateTime);\n if (offset === '+00:00') return 'Z';\n const [hours] = offset.split(':');\n return hours || '+00';\n }\n case 'xxxxx':\n return getTimezoneOffset(zonedDateTime);\n case 'xxxx':\n return getTimezoneOffset(zonedDateTime).replace(':', '');\n case 'xxx':\n return getTimezoneOffset(zonedDateTime);\n case 'xx':\n return getTimezoneOffset(zonedDateTime).replace(':', '');\n case 'x': {\n const offset = getTimezoneOffset(zonedDateTime);\n const [hours] = offset.split(':');\n return hours || '+00';\n }\n case 'zzzz':\n return formatPart(zonedDateTime, 'timeZoneName', 'long', locale);\n case 'zzz':\n case 'zz':\n case 'z':\n return formatPart(zonedDateTime, 'timeZoneName', 'short', locale);\n\n // Timestamps\n case 'T':\n return zonedDateTime.epochMilliseconds.toString();\n case 't':\n return Math.floor(zonedDateTime.epochMilliseconds / 1000).toString();\n\n default:\n return token;\n }\n}\n\nfunction formatPart(\n zonedDateTime: Temporal.ZonedDateTime,\n part: 'era' | 'year' | 'month' | 'weekday' | 'day' | 'dayPeriod' | 'hour' | 'minute' | 'second' | 'timeZoneName',\n style: 'narrow' | 'short' | 'long' | 'numeric' | '2-digit',\n locale: string\n): string {\n const options: Intl.DateTimeFormatOptions = {};\n\n if (part === 'dayPeriod') {\n // dayPeriod needs hour to be present\n options.hour = 'numeric';\n options.hour12 = true;\n } else {\n options[part] = style as any;\n }\n\n const formatted = zonedDateTime.toLocaleString(locale, options);\n\n if (part === 'dayPeriod') {\n // Extract just the AM/PM part\n const match = formatted.match(/\\b(AM|PM|am|pm|a\\.m\\.|p\\.m\\.)\\b/);\n return match ? match[0] : formatted.split(' ').pop() || '';\n }\n\n return formatted;\n}\n\nfunction getOrdinalSuffix(num: number): string {\n const j = num % 10;\n const k = num % 100;\n if (j === 1 && k !== 11) return 'st';\n if (j === 2 && k !== 12) return 'nd';\n if (j === 3 && k !== 13) return 'rd';\n return 'th';\n}\n\nfunction getTimezoneOffset(zonedDateTime: Temporal.ZonedDateTime): string {\n const offsetNs = zonedDateTime.offsetNanoseconds;\n const offsetMinutes = offsetNs / (60 * 1e9);\n const sign = offsetMinutes >= 0 ? '+' : '-';\n const absMinutes = Math.abs(offsetMinutes);\n const hours = Math.floor(absMinutes / 60);\n const minutes = absMinutes % 60;\n return `${sign}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AA6BlB,SAAS,OACd,OACA,WACA,UAAyB,CAAC,GAClB;AACR,QAAM,EAAE,SAAS,SAAS,SAAS,IAAI;AAGvC,MAAI;AACJ,MAAI,iBAAiB,SAAS,SAAS;AACrC,UAAM,KAAK,YAAY;AACvB,oBAAgB,MAAM,mBAAmB,EAAE;AAAA,EAC7C,OAAO;AACL,oBAAgB,WACZ,MAAM,UAAU,EAAE,mBAAmB,QAAQ,IAC7C;AAAA,EACN;AAEA,MAAI,SAAS;AACb,MAAI,IAAI;AACR,QAAM,MAAM,UAAU;AAEtB,SAAO,IAAI,KAAK;AACd,UAAM,OAAO,UAAU,CAAC;AACxB,QAAI,CAAC,KAAM;AAGX,QAAI,SAAS,KAAK;AAEhB,UAAI,IAAI,IAAI,OAAO,UAAU,IAAI,CAAC,MAAM,KAAK;AAC3C,kBAAU;AACV,aAAK;AACL;AAAA,MACF;AAEA;AACA,aAAO,IAAI,KAAK;AACd,YAAI,UAAU,CAAC,MA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,YAAQ,OAAO;AACf,YAAQ,SAAS;AAAA,EACnB,OAAO;AACL,YAAQ,IAAI,IAAI;AAAA,EAClB;AAEA,QAAM,YAAY,cAAc,eAAe,QAAQ,OAAO;AAE9D,MAAI,SAAS,aAAa;AAExB,UAAM,QAAQ,UAAU,MAAM,iCAAiC;AAC/D,WAAO,QAAQ,MAAM,CAAC,IAAI,UAAU,MAAM,GAAG,EAAE,IAAI,KAAK;AAAA,EAC1D;AAEA,SAAO;AACT;AAEA,SAAS,iBAAiB,KAAqB;AAC7C,QAAM,IAAI,MAAM;AAChB,QAAM,IAAI,MAAM;AAChB,MAAI,MAAM,KAAK,MAAM,GAAI,QAAO;AAChC,MAAI,MAAM,KAAK,MAAM,GAAI,QAAO;AAChC,MAAI,MAAM,KAAK,MAAM,GAAI,QAAO;AAChC,SAAO;AACT;AAEA,SAAS,kBAAkB,eAA+C;AACxE,QAAM,WAAW,cAAc;AAC/B,QAAM,gBAAgB,YAAY,KAAK;AACvC,QAAM,OAAO,iBAAiB,IAAI,MAAM;AACxC,QAAM,aAAa,KAAK,IAAI,aAAa;AACzC,QAAM,QAAQ,KAAK,MAAM,aAAa,EAAE;AACxC,QAAM,UAAU,aAAa;AAC7B,SAAO,GAAG,IAAI,GAAG,MAAM,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,QAAQ,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;AAC3F;","names":[]}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Temporal } from '@js-temporal/polyfill';
|
|
2
|
+
export interface FormatOptions {
|
|
3
|
+
locale?: string;
|
|
4
|
+
timeZone?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Format a Temporal.Instant or ZonedDateTime using date-fns-like format tokens.
|
|
8
|
+
* Uses Intl.DateTimeFormat under the hood via Temporal's toLocaleString() for zero dependencies.
|
|
9
|
+
*
|
|
10
|
+
* @param input - A Temporal.Instant or Temporal.ZonedDateTime to format
|
|
11
|
+
* @param formatStr - Format string using date-fns tokens (e.g., "yyyy-MM-dd HH:mm:ss")
|
|
12
|
+
* @param options - Optional configuration for locale and timezone
|
|
13
|
+
* @returns Formatted date string
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const zoned = Temporal.ZonedDateTime.from("2025-01-20T15:00:00-05:00[America/New_York]");
|
|
18
|
+
*
|
|
19
|
+
* format(zoned, "yyyy-MM-dd"); // "2025-01-20"
|
|
20
|
+
* format(zoned, "MMMM d, yyyy"); // "January 20, 2025"
|
|
21
|
+
* format(zoned, "h:mm a"); // "3:00 PM"
|
|
22
|
+
* format(zoned, "EEEE, MMMM do, yyyy 'at' h:mm a"); // "Monday, January 20th, 2025 at 3:00 PM"
|
|
23
|
+
*
|
|
24
|
+
* // With locale
|
|
25
|
+
* format(zoned, "MMMM d, yyyy", { locale: "es-ES" }); // "enero 20, 2025"
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function format(input: Temporal.Instant | Temporal.ZonedDateTime, formatStr: string, options?: FormatOptions): string;
|
|
29
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,QAAQ,CAAC,OAAO,GAAG,QAAQ,CAAC,aAAa,EAChD,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,aAAkB,GAC1B,MAAM,CA+DR"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.test.d.ts","sourceRoot":"","sources":["../src/format.test.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toUtc.test.d.ts","sourceRoot":"","sources":["../src/toUtc.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toUtcString.test.d.ts","sourceRoot":"","sources":["../src/toUtcString.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toZonedTime.test.d.ts","sourceRoot":"","sources":["../src/toZonedTime.test.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED