-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.mjs
41 lines (34 loc) · 1.07 KB
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Temporal } from 'proposal-temporal/lib/index.mjs';
import tai from 't-a-i';
export default class TAI extends Temporal.TimeZone {
constructor() {
super('UTC');
}
toString() {
return 'Etc/TAI';
}
getOffsetNanosecondsFor() {
return 0;
};
getNextTransition() {
return null;
}
getPreviousTransition() {
return null;
}
getPossibleInstantsFor(pdt) {
const instant = Temporal.TimeZone.from('UTC').getInstantFor(pdt); // There's no DST in UTC
const nanos = instant.epochNanoseconds;
const millis = instant.epochMilliseconds;
const precision = nanos % 1_000_000n;
const tais = tai.oneToMany.unixToAtomicPicos(millis);
return tais.map(tai => new Temporal.Instant(tai / 1000n + precision));
}
getPlainDateTimeFor(instant) {
const nanos = instant.epochNanoseconds;
const millis = instant.epochMilliseconds;
const precision = nanos % 1_000_000n;
const utc = tai.oneToMany.atomicToUnix(millis);
return Temporal.TimeZone.from('UTC').getPlainDateTimeFor(new Temporal.Instant(BigInt(utc) + precision));
}
}