Skip to content

Commit 8ada97c

Browse files
authored
TAI initialization, improved i18n, improved sourcemaps, etc. (#16)
* Added option to initialize `DateTime` object with TAI. * Made timezone names case insensitive. * Added `DateTimeFormatOptions` options to Ixx format strings. * Improved i18n support for AM/PM time formats. * `newDateTimeFormat` function for creating DateTimeFormat instances with more flexible options. * TAI treated as named timezone or displayed with formatted UTC offsets.
1 parent fef0bf8 commit 8ada97c

14 files changed

Lines changed: 814 additions & 363 deletions

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/docs
88
/img
99
/.nyc_output
10+
/.vscode
1011
*.js.map
1112
!/dist/**/*.js.map
1213
*.spec.d.ts
@@ -17,3 +18,6 @@
1718
/test.html
1819
.travis.yml
1920
.coveralls.yml
21+
.markdownlint.json
22+
.nycrc
23+
rollup.config.js

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ While there are a wide range of functions and classes available from **@tubular/
149149
| `ttime('2017‑03‑02 14:45 Europe/Paris')` | From an ISO-8601 date/time (variant with space instead of `T`) and IANA timezone. | `DateTime<2017-03-02T14:45:00.000 +01:00>` |
150150
| `ttime('20:17:15')` | Dateless time from an ISO-8601 time string. | `DateTime<20:17:15.000>` |
151151
| `ttime(1200848400000)` | From a millisecond timestamp. | `DateTime<2008-01-20T12:00:00.000 -05:00>` |
152+
| `ttime({ tai: 1200848400000 })` | From a TAI millisecond timestamp. | `DateTime<2008-01-20T12:00:00.000 -05:00>` |
152153
| `ttime({ y: 2008, m: 1, d: 20, hrs: 12, min: 0 })` | From a `DateAndTime` object, short-style field names. | `DateTime<2008-01-20T12:00:00.000 -05:00>` |
153154
| `ttime({ year: 2008, month: 1, day: 20, hour: 12, minute: 0 })` | From a `DateAndTime` object, long-style field names. | `DateTime<2008-01-20T12:00:00.000 -05:00>` |
154155
| `ttime([2013, 12, 11, 10, 9, 8, 765])` | From a numeric array: year, month, day, (hour (0-23), minute, second, millisecond), in that order. | `DateTime<2013-12-11T10:09:08.765 -05:00>` |
@@ -247,7 +248,7 @@ Please note that, as most unaccented Latin letters are interpreted as special fo
247248
| | SSSS... | Additional zeros after milliseconds. |
248249
| Timezone | ZZZ | America/New_York, Europe/Paris, etc.<br><br>IANA timezone, if available. |
249250
| | zzz | Australian Central Standard Time, Pacific Daylight Time, etc.<br><br>_Long form names are only for output &mdash; cannot be parsed._ |
250-
| | ZZ | -0700 -0600 ... +0600 +0700
251+
| | ZZ | -0700 -0600 ... +0600 +0700<br><br>If used with a TAI time, the displayed offset will be the difference between TAI and UTC at a given moment in time. Outside of the well-defined span of officially-declared leap seconds, this offset might be displayed with millisecond precision.
251252
| | zz,&nbsp;z | EST, CDT, MST, PDT, AEST, etc.<br><br>Please note that timezones in this format are not internationalized, and are not unambiguous when parsed. |
252253
| | Z | -07:00 -06:00 ... +06:00 +07:00
253254
| Unix timestamp, UTC | X | 1360013296 |
@@ -295,6 +296,12 @@ The capital letters `F`, `L`, `M`, and `S` correspond to the option values `'ful
295296
| IS | `9/4/86` |
296297
| IxL | `8:30:00 PM EDT` |
297298

299+
You can also augment these formats with brace-enclosed `Intl.DateTimeFormatOptions`, such as:
300+
301+
`IMM{hourCycle:23h}`
302+
303+
...which will start with whatever the localized time formatting is and force it into 24-hour time, whether the standard localized form is a 12- or 24-hour format. Note that no quotes are placed around the option values, as they would be in JavaScript/TypeScript code.
304+
298305
## Pre-defined formats
299306

300307
```javascript
@@ -1598,6 +1605,18 @@ For a given UT1 Julian Date (Universal Time), return the Julian Date in ephemeri
15981605
ttime.utToTdt(timeJDU: number): number;
15991606
```
16001607
1608+
Create new `Intl.DateTimeFormat` instances with more flexibility for mixing options. For instance:
1609+
1610+
> `new DateTimeFormat('ja', { timeStyle: 'short' })`
1611+
1612+
... shows hours with no leading zero for single-digit hours. If you try to add the leading zero like this:
1613+
1614+
> `new DateTimeFormat('ja', { timeStyle: 'short', hour: '2-digit' })`
1615+
1616+
...an exception is thrown. By using `newDateTimeFormat`, however, `@tubular/time` will attempt to override `dateStyle` and `timeStyle` options with specific variations which are otherwise disallowed.
1617+
1618+
`ttime.newDateTimeFormat(locales?: string | string[], options?: DateTimeFormatOptions)`
1619+
16011620
## Constants available on `ttime`
16021621
16031622
```typescript

0 commit comments

Comments
 (0)