Skip to content

Commit 31131af

Browse files
Merge pull request #89 from knowledgecode/develop
Develop
2 parents 8a548e6 + 3ded8d2 commit 31131af

26 files changed

Lines changed: 1868 additions & 449 deletions

PLUGINS.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,45 @@ In the first example above, if you want `parseTZ()` to parse the time as PST, yo
380380
date.parse('Nov 7 2021 1:59:59 -0800', 'MMM D YYYY H:mm:ss Z'); // => 2021-11-07T09:59:59Z
381381
```
382382

383+
#### Token Extension
384+
385+
This plugin also adds tokens for time zone name to the formatter.
386+
387+
**formatter:**
388+
389+
| token | meaning | output examples |
390+
|:------|:----------------------------|:----------------------|
391+
| z | time zone name abbreviation | PST, EST |
392+
| zz | time zone name | Pacific Standard Time |
393+
394+
The `z` and `zz` are lowercase. Also, currently it does not support output other than English.
395+
396+
**parser:**
397+
398+
There is no change.
399+
400+
```javascript
401+
const date = require('date-and-time');
402+
// Import "timezone" plugin.
403+
const timezone = require('date-and-time/plugin/timezone');
404+
405+
// Apply "timezone" plugin to the library.
406+
date.plugin(timezone);
407+
408+
const d1 = new Date(Date.UTC(2021, 2, 14, 9, 59, 59, 999));
409+
date.format(d1, 'MMMM DD YYYY H:mm:ss.SSS zz');
410+
// March 14 2021 1:59:59.999 Pacific Standard Time
411+
412+
date.format(d1, 'MMMM DD YYYY H:mm:ss.SSS zz', true);
413+
// March 14 2021 9:59:59.999 Coordinated Universal Time
414+
415+
date.formatTZ(d1, 'MMMM DD YYYY H:mm:ss.SSS z', 'Asia/Tokyo');
416+
// March 14 2021 18:59:59.999 JST
417+
418+
// Transforms the date string from EST (Eastern Standard Time) to PDT (Pacific Daylight Time).
419+
date.transform('2021-11-07T03:59:59 UTC-0500', 'YYYY-MM-DD[T]HH:mm:ss [UTC]Z', 'MMMM D YYYY H:mm:ss z');
420+
// November 7 2021 1:59:59 PDT
421+
```
383422
---
384423

385424
### two-digit-year

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ npm i date-and-time
2525

2626
## Recent Changes
2727

28+
- 3.4.0
29+
- Added `zz` (time zone name) and `z` (time zone name abbreviation) tokens to the `timezone` plugin.
30+
- Fixed an issue where token extensions by other plugins were not reflected in functions provided by the `timezone` plugin.
31+
2832
- 3.3.0
2933
- Refactored `format()`, `isValid()`, and `preparse()`, further improved performance.
3034

3135
- 3.2.0
3236
- Refactored `compile()`, `format()`, and `preparse()`, slightly improved performance.
3337

34-
- 3.1.1
35-
- Fixed an issue where `format()` could output incorrect UTC times in locales with daylight savings time.
36-
- Refactored `formatTZ()` of `timezone` plugin.
37-
3838
## Usage
3939

4040
- ES Modules:
@@ -179,12 +179,14 @@ Available tokens and their meanings are as follows:
179179

180180
You can also use the following tokens by importing plugins. See [PLUGINS.md](./PLUGINS.md) for details.
181181

182-
| token | meaning | examples of output |
183-
|:------|:-------------------------------------|:-------------------|
184-
| DDD | ordinal notation of date | 1st, 2nd, 3rd |
185-
| AA | meridiem (uppercase with ellipsis) | A.M., P.M. |
186-
| a | meridiem (lowercase) | am, pm |
187-
| aa | meridiem (lowercase with ellipsis) | a.m., p.m. |
182+
| token | meaning | examples of output |
183+
|:------|:-------------------------------------|:----------------------|
184+
| DDD | ordinal notation of date | 1st, 2nd, 3rd |
185+
| AA | meridiem (uppercase with ellipsis) | A.M., P.M. |
186+
| a | meridiem (lowercase) | am, pm |
187+
| aa | meridiem (lowercase with ellipsis) | a.m., p.m. |
188+
| z | time zone name abbreviation | PST, EST |
189+
| zz | time zone name | Pacific Standard Time |
188190

189191
#### Note 1. Comments
190192

date-and-time.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export type Extension = {
296296
export function extend(extension: Extension): void;
297297

298298
/** Plugin installer */
299-
export type Plugin = (proto: unknown, localized_proto?: unknown) => string;
299+
export type Plugin = (proto: unknown, date?: unknown) => string;
300300

301301
/**
302302
* Importing plugins

date-and-time.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@
142142
_formatter: _formatter,
143143
_parser: _parser
144144
},
145-
localized_proto,
146145
date;
147146

148147
/**
@@ -177,6 +176,7 @@
177176
u.getMilliseconds = u.getUTCMilliseconds;
178177
u.getDay = u.getUTCDay;
179178
u.getTimezoneOffset = function () { return 0; };
179+
u.getTimezoneName = function () { return 'UTC'; };
180180
return u;
181181
}
182182
return dateObj;
@@ -453,7 +453,6 @@
453453
}
454454
};
455455

456-
localized_proto = extend(proto);
457456
date = extend(proto);
458457

459458
/**
@@ -474,8 +473,8 @@
474473
var formatter = extend(_formatter, extension.formatter, true, res);
475474
var parser = extend(_parser, extension.parser, true, res);
476475

477-
date._formatter = localized_proto._formatter = formatter;
478-
date._parser = localized_proto._parser = parser;
476+
date._formatter = formatter;
477+
date._parser = parser;
479478

480479
for (var plugin in plugins) {
481480
date.extend(plugins[plugin]);
@@ -512,7 +511,7 @@
512511
var install = typeof plugin === 'function' ? plugin : date.plugin[plugin];
513512

514513
if (install) {
515-
date.extend(plugins[install(proto, localized_proto)] || {});
514+
date.extend(plugins[install(proto, date)] || {});
516515
}
517516
};
518517

date-and-time.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)