Skip to content

Commit 01e60eb

Browse files
Merge pull request #114 from knowledgecode/develop
Update dependencies and improve code quality
2 parents 71dc760 + f179fd6 commit 01e60eb

File tree

145 files changed

+921
-1382
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+921
-1382
lines changed

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.DS_Store
2-
.claude/
3-
CLAUDE.md
2+
.vscode/
43
cache/
54
coverage/
65
dist/
7-
node_modules/
6+
node_modules/

docs/api/format.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ format(now, 'ddd, MMM DD YYYY');
3434
// => Sat, Aug 23 2025
3535

3636
format(now, 'hh:mm A [GMT]Z');
37-
// => 02:30 PM GMT+0900
37+
// => 02:30 PM GMT-0700
3838
```
3939

4040
## Format Tokens
@@ -255,6 +255,35 @@ format(midnight, 'H:mm', { hour24: 'h24' });
255255
// => 24:30
256256
```
257257

258+
### plugins
259+
260+
**Type**: `FormatterPlugin[]`
261+
**Default**: `undefined`
262+
263+
Enables additional format tokens provided by plugins. Plugins extend the formatter with special tokens that are not included in the core library.
264+
265+
```typescript
266+
import { format } from 'date-and-time';
267+
import { formatter as ordinal } from 'date-and-time/plugins/ordinal';
268+
import { formatter as zonename } from 'date-and-time/plugins/zonename';
269+
270+
const date = new Date();
271+
272+
// Use ordinal plugin
273+
format(date, 'MMMM DDD, YYYY', { plugins: [ordinal] });
274+
// => August 23rd, 2025
275+
276+
// Use zonename plugin
277+
format(date, 'YYYY-MM-DD HH:mm z', { plugins: [zonename] });
278+
// => 2025-08-23 14:30 PDT
279+
280+
// Use multiple plugins together
281+
format(date, 'MMMM DDD, YYYY h:mm A zz', { plugins: [ordinal, zonename] });
282+
// => August 23rd, 2025 2:30 PM Pacific Daylight Time
283+
```
284+
285+
For a complete list of available plugins, see [Plugins](../plugins).
286+
258287
## Advanced Usage
259288

260289
### Comments in Format Strings
@@ -290,9 +319,9 @@ import Tokyo from 'date-and-time/timezones/Asia/Tokyo';
290319
const date = new Date();
291320

292321
// Japanese with timezone
293-
format(date, 'YYYY年MMMM月D日dddd Ah:mm:ss [GMT]Z', {
294-
timeZone: Tokyo,
295-
locale: ja
322+
format(date, 'YYYY年MMMM月D日dddd Ah:mm:ss [GMT]Z', {
323+
timeZone: Tokyo,
324+
locale: ja
296325
});
297326
// => 2025年8月23日土曜日 午後11:30:45 GMT+0900
298327
```

docs/api/parse.md

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ import { parse } from 'date-and-time';
2727

2828
// Basic date parsing
2929
parse('2025-08-23', 'YYYY-MM-DD');
30-
// => Fri Aug 23 2025 00:00:00 GMT+0900
30+
// => Fri Aug 23 2025 00:00:00 GMT-0700
3131

32-
parse('08/23/2025', 'MM/DD/YYYY');
33-
// => Fri Aug 23 2025 00:00:00 GMT+0900
32+
parse('08/23/2025', 'MM/DD/YYYY');
33+
// => Fri Aug 23 2025 00:00:00 GMT-0700
3434

3535
parse('23.08.2025', 'DD.MM.YYYY');
36-
// => Fri Aug 23 2025 00:00:00 GMT+0900
36+
// => Fri Aug 23 2025 00:00:00 GMT-0700
3737

3838
// Time parsing
3939
parse('14:30:45', 'HH:mm:ss');
40-
// => Thu Jan 01 1970 14:30:45 GMT+0900
40+
// => Thu Jan 01 1970 14:30:45 GMT-0800
4141

4242
parse('2:30:45 PM', 'h:mm:ss A');
43-
// => Thu Jan 01 1970 14:30:45 GMT+0900
43+
// => Thu Jan 01 1970 14:30:45 GMT-0800
4444

4545
// Combined date and time
4646
parse('2025-08-23 14:30:45', 'YYYY-MM-DD HH:mm:ss');
47-
// => Fri Aug 23 2025 14:30:45 GMT+0900
47+
// => Fri Aug 23 2025 14:30:45 GMT-0700
4848
```
4949

5050
## Format Tokens
@@ -133,7 +133,7 @@ import es from 'date-and-time/locales/es';
133133

134134
// Spanish parsing
135135
parse('23 de agosto de 2025', 'D [de] MMMM [de] YYYY', { locale: es });
136-
// => Fri Aug 23 2025 00:00:00 GMT+0900
136+
// => Fri Aug 23 2025 00:00:00 GMT-0700
137137
```
138138

139139
For a complete list of all supported locales with import examples, see [Supported Locales](../locales).
@@ -186,11 +186,11 @@ import beng from 'date-and-time/numerals/beng';
186186

187187
// Arabic-Indic numerals
188188
parse('٠٨/٠٧/٢٠٢٥', 'DD/MM/YYYY', { numeral: arab });
189-
// => Fri Aug 08 2025 00:00:00 GMT+0900
189+
// => Fri Aug 08 2025 00:00:00 GMT-0700
190190

191-
// Bengali numerals
191+
// Bengali numerals
192192
parse('০৮/০৭/২০২৫', 'DD/MM/YYYY', { numeral: beng });
193-
// => Fri Aug 08 2025 00:00:00 GMT+0900
193+
// => Fri Aug 08 2025 00:00:00 GMT-0700
194194
```
195195

196196
**Available numeral systems:**
@@ -213,11 +213,11 @@ import { parse } from 'date-and-time';
213213

214214
// Gregorian calendar (default)
215215
parse('August 23, 2025', 'MMMM D, YYYY');
216-
// => Fri Aug 23 2025 00:00:00 GMT+0900
216+
// => Fri Aug 23 2025 00:00:00 GMT-0700
217217

218218
// Buddhist calendar (543 years behind)
219219
parse('August 23, 2568', 'MMMM D, YYYY', { calendar: 'buddhist' });
220-
// => Fri Aug 23 2025 00:00:00 GMT+0900
220+
// => Fri Aug 23 2025 00:00:00 GMT-0700
221221
```
222222

223223
### ignoreCase
@@ -236,10 +236,10 @@ parse('august 23, 2025', 'MMMM D, YYYY');
236236

237237
// Case-insensitive
238238
parse('AUGUST 23, 2025', 'MMMM D, YYYY', { ignoreCase: true });
239-
// => Fri Aug 23 2025 00:00:00 GMT+0900
239+
// => Fri Aug 23 2025 00:00:00 GMT-0700
240240

241241
parse('fri aug 23 2025', 'ddd MMM DD YYYY', { ignoreCase: true });
242-
// => Fri Aug 23 2025 00:00:00 GMT+0900
242+
// => Fri Aug 23 2025 00:00:00 GMT-0700
243243
```
244244

245245
### hour12
@@ -254,11 +254,11 @@ import { parse } from 'date-and-time';
254254

255255
// h12 format - midnight is 12 AM
256256
parse('12:30 AM', 'h:mm A', { hour12: 'h12' });
257-
// => Thu Jan 01 1970 00:30:00 GMT+0900
257+
// => Thu Jan 01 1970 00:30:00 GMT-0800
258258

259259
// h11 format - midnight is 0 AM
260260
parse('0:30 AM', 'h:mm A', { hour12: 'h11' });
261-
// => Thu Jan 01 1970 00:30:00 GMT+0900
261+
// => Thu Jan 01 1970 00:30:00 GMT-0800
262262
```
263263

264264
### hour24
@@ -273,13 +273,47 @@ import { parse } from 'date-and-time';
273273

274274
// h23 format - midnight is 0
275275
parse('0:30', 'H:mm', { hour24: 'h23' });
276-
// => Thu Jan 01 1970 00:30:00 GMT+0900
276+
// => Thu Jan 01 1970 00:30:00 GMT-0800
277277

278278
// h24 format - midnight is 24 (of previous day)
279279
parse('24:30', 'H:mm', { hour24: 'h24' });
280-
// => Thu Jan 01 1970 00:30:00 GMT+0900
280+
// => Thu Jan 01 1970 00:30:00 GMT-0800
281281
```
282282

283+
### plugins
284+
285+
**Type**: `ParserPlugin[]`
286+
**Default**: `undefined`
287+
288+
Enables additional parse tokens provided by plugins. Plugins extend the parser with special tokens that are not included in the core library.
289+
290+
```typescript
291+
import { parse } from 'date-and-time';
292+
import { parser as ordinal } from 'date-and-time/plugins/ordinal';
293+
import { parser as two_digit_year } from 'date-and-time/plugins/two-digit-year';
294+
import { parser as microsecond } from 'date-and-time/plugins/microsecond';
295+
296+
// Use ordinal plugin
297+
parse('January 1st, 2025', 'MMMM DDD, YYYY', { plugins: [ordinal] });
298+
// => Wed Jan 01 2025 00:00:00 GMT-0800
299+
300+
// Use two-digit-year plugin
301+
parse('12/25/99', 'MM/DD/YY', { plugins: [two_digit_year] });
302+
// => Sat Dec 25 1999 00:00:00 GMT-0800
303+
304+
// Use microsecond plugin
305+
parse('14:30:45.123456', 'HH:mm:ss.SSSSSS', { plugins: [microsecond] });
306+
// => Thu Jan 01 1970 14:30:45 GMT-0800
307+
308+
// Use multiple plugins together
309+
parse('January 1st, 99 14:30:45.123456', 'MMMM DDD, YY HH:mm:ss.SSSSSS', {
310+
plugins: [ordinal, two_digit_year, microsecond]
311+
});
312+
// => Fri Jan 01 1999 14:30:45 GMT-0800
313+
```
314+
315+
For a complete list of available plugins, see [Plugins](../plugins).
316+
283317
## Parsing Behavior and Limitations
284318

285319
### Default Date and Time Values
@@ -291,19 +325,19 @@ import { parse } from 'date-and-time';
291325

292326
// Only time - defaults to Jan 1, 1970
293327
parse('14:30:45', 'HH:mm:ss');
294-
// => Thu Jan 01 1970 14:30:45 GMT+0900
328+
// => Thu Jan 01 1970 14:30:45 GMT-0800
295329

296330
// Only date - defaults to 00:00:00
297331
parse('2025-08-23', 'YYYY-MM-DD');
298-
// => Fri Aug 23 2025 00:00:00 GMT+0900
332+
// => Fri Aug 23 2025 00:00:00 GMT-0700
299333

300334
// Year and month - defaults to 1st day
301335
parse('2025-08', 'YYYY-MM');
302-
// => Mon Aug 01 2025 00:00:00 GMT+0900
336+
// => Fri Aug 01 2025 00:00:00 GMT-0700
303337

304338
// Just year - defaults to Jan 1st, 00:00:00
305339
parse('2025', 'YYYY');
306-
// => Wed Jan 01 2025 00:00:00 GMT+0900
340+
// => Wed Jan 01 2025 00:00:00 GMT-0800
307341
```
308342

309343
### Date Range Limitations
@@ -315,15 +349,15 @@ import { parse } from 'date-and-time';
315349

316350
// Valid maximum date
317351
parse('Dec 31 9999', 'MMM D YYYY');
318-
// => Dec 31 9999 00:00:00 GMT+0900
352+
// => Fri Dec 31 9999 00:00:00 GMT-0800
319353

320354
// Invalid - exceeds maximum
321355
parse('Dec 31 10000', 'MMM D YYYY');
322356
// => Invalid Date
323357

324358
// Valid minimum date
325359
parse('Jan 1 0001', 'MMM D YYYY');
326-
// => Jan 1 0001 00:00:00 GMT+0900
360+
// => Mon Jan 1 0001 00:00:00 GMT-0800
327361

328362
// Invalid - below minimum
329363
parse('Jan 1 0000', 'MMM D YYYY');
@@ -339,7 +373,7 @@ import { parse } from 'date-and-time';
339373

340374
// Parsed as local timezone
341375
parse('14:30:45', 'HH:mm:ss');
342-
// => Thu Jan 01 1970 14:30:45 GMT+0900
376+
// => Thu Jan 01 1970 14:30:45 GMT-0800
343377

344378
// Timezone offset in input takes precedence
345379
parse('14:30:45 +0000', 'HH:mm:ss Z');
@@ -359,11 +393,11 @@ import { parse } from 'date-and-time';
359393

360394
// Without meridiem - ambiguous time
361395
parse('11:30:45', 'h:mm:ss');
362-
// => Thu Jan 01 1970 11:30:45 GMT+0900 (assumes AM)
396+
// => Thu Jan 01 1970 11:30:45 GMT-0800 (assumes AM)
363397

364398
// With meridiem - unambiguous time
365399
parse('11:30:45 PM', 'h:mm:ss A');
366-
// => Thu Jan 01 1970 23:30:45 GMT+0900
400+
// => Thu Jan 01 1970 23:30:45 GMT-0800
367401
```
368402

369403
## Advanced Usage
@@ -376,17 +410,17 @@ Parts of the format string enclosed in square brackets are treated as literal te
376410
import { parse } from 'date-and-time';
377411

378412
parse('Today is Saturday, August 23, 2025', '[Today is] dddd, MMMM D, YYYY');
379-
// => Fri Aug 23 2025 00:00:00 GMT+0900
413+
// => Sat Aug 23 2025 00:00:00 GMT-0700
380414

381415
parse('2025-08-23T14:30:45Z', 'YYYY-MM-DD[T]HH:mm:ss[Z]');
382-
// => Fri Aug 23 2025 14:30:45 GMT+0900
416+
// => Sat Aug 23 2025 14:30:45 GMT-0700
383417

384418
parse('Report generated on 2025/08/23 at 14:30', '[Report generated on] YYYY/MM/DD [at] HH:mm');
385-
// => Fri Aug 23 2025 14:30:00 GMT+0900
419+
// => Sat Aug 23 2025 14:30:00 GMT-0700
386420

387421
// Escape square brackets to parse them from input string
388422
parse('[2025-08-23 14:30:45]', '\\[YYYY-MM-DD HH:mm:ss\\]');
389-
// => Fri Aug 23 2025 14:30:45 GMT+0900
423+
// => Sat Aug 23 2025 14:30:45 GMT-0700
390424
```
391425

392426
### Wildcard Parsing
@@ -402,7 +436,7 @@ parse('2025/08/23 14:30:45', 'YYYY/MM/DD');
402436

403437
// Use whitespace as wildcard (9 spaces to match ' 14:30:45')
404438
parse('2025/08/23 14:30:45', 'YYYY/MM/DD ');
405-
// => Fri Aug 23 2025 00:00:00 GMT+0900
439+
// => Sat Aug 23 2025 00:00:00 GMT-0700
406440
```
407441

408442
### Ellipsis Token
@@ -414,11 +448,11 @@ import { parse } from 'date-and-time';
414448

415449
// Ignore everything after the date
416450
parse('2025/08/23 14:30:45', 'YYYY/MM/DD...');
417-
// => Fri Aug 23 2025 00:00:00 GMT+0900
451+
// => Sat Aug 23 2025 00:00:00 GMT-0700
418452

419453
// More complex example
420454
parse('Log entry: 2025-08-23 some extra data here', '[Log entry: ]YYYY-MM-DD...');
421-
// => Fri Aug 23 2025 00:00:00 GMT+0900
455+
// => Sat Aug 23 2025 00:00:00 GMT-0700
422456
```
423457

424458
### Complex Localized Parsing
@@ -445,13 +479,13 @@ import { parse } from 'date-and-time';
445479
parse('2025-08-23T14:30:45.123Z', 'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]', { timeZone: 'UTC' });
446480
// => Fri Aug 23 2025 14:30:45 GMT+0000
447481

448-
// RFC 2822 format
482+
// RFC 2822 format
449483
parse('Sat, 23 Aug 2025 14:30:45 +0900', 'ddd, DD MMM YYYY HH:mm:ss ZZ');
450-
// => Fri Aug 23 2025 14:30:45 GMT+0900
484+
// => Sat Aug 23 2025 14:30:45 GMT+0900
451485

452486
// File naming format
453487
parse('20250823_143045', 'YYYYMMDD_HHmmss');
454-
// => Fri Aug 23 2025 14:30:45 GMT+0900
488+
// => Sat Aug 23 2025 14:30:45 GMT-0700
455489
```
456490

457491
## Error Handling
@@ -508,12 +542,12 @@ import { parse } from 'date-and-time';
508542

509543
const logLine = '[2025-08-23 14:30:45.123] Application started';
510544
const timestamp = parse(logLine, ' YYYY-MM-DD HH:mm:ss.SSS ...');
511-
// => Fri Aug 23 2025 14:30:45 GMT+0900
545+
// => Sat Aug 23 2025 14:30:45 GMT-0700
512546

513547
// For different log formats
514548
const syslogLine = 'Aug 23 14:30:45 server: Process started';
515549
const syslogTimestamp = parse(syslogLine, 'MMM DD HH:mm:ss...');
516-
// => Fri Aug 23 1970 14:30:45 GMT+0900
550+
// => Sat Aug 23 1970 14:30:45 GMT-0700
517551
```
518552

519553
### API Responses

0 commit comments

Comments
 (0)