UNPKG

@everwhen/temporal

Version:
40 lines (39 loc) 1.14 kB
import { Temporal } from 'temporal-polyfill'; import { Duration } from "./duration.js"; import { ZonedDateTime } from "./zoned-date-time.js"; export class Instant extends Temporal.Instant { static now() { return Instant.from(Temporal.Now.instant()); } static from(...args) { const instant = Temporal.Instant.from(...args); return new Instant(instant.epochNanoseconds); } compare(other) { return Temporal.Instant.compare(this, other); } isBefore(other) { return this.compare(other) === -1; } isAfter(other) { return this.compare(other) === 1; } add(...args) { return Instant.from(super.add(...args)); } subtract(...args) { return Instant.from(super.subtract(...args)); } round(...args) { return Instant.from(super.round(...args)); } since(...args) { return Duration.from(super.since(...args)); } until(...args) { return Duration.from(super.until(...args)); } toZonedDateTimeISO(tzLike) { return ZonedDateTime.from(super.toZonedDateTimeISO(tzLike)); } }