Skip to content

Commit 41911fb

Browse files
authored
utToTaiMillis(), taiToUtMillis(), DateTime.wallTimeSparse, etc. (#17)
* Exposed utToTaiMillis() and taiToUtMillis() functions to public API. * Added minimizeFields() functions, and corresponding DateTime.wallTimeSparse accessor. * Allow leap seconds to be parsed. * Fixed type signature of DateTime.format() to accept string[] for `localeOverride` * Added functions getMinDaysInWeek(), getStartOfWeek(), getWeekend(), and constants defaultLocale, hasDateTimeStyle, hasIntlDateTime.
1 parent 8ada97c commit 41911fb

11 files changed

Lines changed: 418 additions & 266 deletions

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ To remotely download the full code as an ES module:
114114
<script type="module">
115115
import('https://unpkg.com/@tubular/time/dist/fesm2015/index.mjs').then(pkg => {
116116
const { ttime, DateTime, Timezone} = pkg;
117-
117+
118118
// ...
119119
});
120120
</script>
@@ -536,7 +536,7 @@ As discussed earlier, concerning parsing time strings, ambiguous times due to Da
536536

537537
As an output from a `DateTime` instance, such as what you get from `ttime().wallTime`, all `DateAndTime` fields will be filled in with synchronized values. `ttime().wallTime.hour` provides the hour value, `ttime().wallTime.utcOffset` provides the UTC offset in seconds for the given time, etc.
538538

539-
`ttime().wallTimeShort` returns a `DateAndTime` object with all available short-form field names, and `ttime().wallTimeLong` only long-form field names.
539+
`ttime().wallTimeShort` returns a `DateAndTime` object with all available short-form field names, and `ttime().wallTimeLong` only long-form field names. `ttime().wallTimeSparse` returns a `DateAndTime` object with a minimal set of short-form field names: `y`, `m`, `d`, `hrs`, `min`, `sec`, `millis`.
540540

541541
## Modifying `DateTime` values
542542

@@ -1138,7 +1138,7 @@ wallTime: DateAndTime;
11381138
```typescript
11391139
computeUtcMillisFromWallTime(wallTime: DateAndTime): number;
11401140

1141-
format(fmt = fullIsoFormat, localeOverride?: string): string;
1141+
format(fmt = fullIsoFormat, localeOverride?: string | string[]): string;
11421142

11431143
// For questions like “What date is the second Tuesday of this month?”
11441144
// `dayOfTheWeek` 0-6 for Sun-Sat, index is 1-based. You can use the constant `ttime.LAST`
@@ -1557,6 +1557,24 @@ supportsCountry(country: string): boolean;
15571557
15581558
## Other functions available on `ttime`
15591559
1560+
Get the minimum number of days within a given calendar year needed for a week to be considered part of a locale’s week-based calendar for that year:
1561+
1562+
```typescript
1563+
ttime.getMinDaysInWeek(locale: string | string[]): number;
1564+
```
1565+
1566+
Day number (0-6 for Sunday-Saturday) considered the first day of a week for a locale:
1567+
1568+
```typescript
1569+
ttime.getStartOfWeek(locale: string | string[]): number;
1570+
```
1571+
1572+
Day numbers (0-6 for Sunday-Saturday) considered to comprise weekend days for a locale:
1573+
1574+
```typescript
1575+
ttime.getWeekend(locale: string | string[]): number[];
1576+
```
1577+
15601578
Determine if a value is an instance of the `Date` class:
15611579
15621580
```typescript
@@ -1593,12 +1611,24 @@ For a given TDT Julian Date (ephemeris time), return the number of seconds that
15931611
ttime.getDeltaTAtJulianDate(timeJDE: number): number;
15941612
```
15951613
1614+
For a given TAI millisecond value (1970 epoch), return the corresponding UT1 or UTC milliseconds:
1615+
1616+
```typescript
1617+
ttime.taiToUtMillis(millis: number, forUtc = false): number;
1618+
```
1619+
15961620
For a given TDT Julian Date (ephemeris time), return the Julian Date in Universal Time (UT1):
15971621
15981622
```typescript
15991623
ttime.tdtToUt(timeJDE: number): number;
16001624
```
16011625
1626+
For a given UT1 or UTC millisecond value (1970 epoch), return the corresponding TAI milliseconds:
1627+
1628+
```typescript
1629+
ttime.utToTaiMillis(millis: number, asUtc = false): number;
1630+
```
1631+
16021632
For a given UT1 Julian Date (Universal Time), return the Julian Date in ephemeris time (TDT):
16031633
16041634
```typescript
@@ -1620,6 +1650,13 @@ Create new `Intl.DateTimeFormat` instances with more flexibility for mixing opti
16201650
## Constants available on `ttime`
16211651
16221652
```typescript
1653+
// Locale
1654+
ttime.defaultLocale;
1655+
1656+
// Feature flags
1657+
ttime.hasDateTimeStyle: boolean;
1658+
ttime.hasIntlDateTime: boolean;
1659+
16231660
// Formats
16241661
ttime.DATETIME_LOCAL: string;
16251662
ttime.DATETIME_LOCAL_SECONDS: string;

0 commit comments

Comments
 (0)