@everwhen/temporal
Version:
82 lines • 2.67 kB
JavaScript
import { Temporal } from 'temporal-polyfill';
import { Duration } from './duration.js';
import { PlainDateTime } from './plain-date-time.js';
import { PlainDate } from './plain-date.js';
import { PlainTime } from './plain-time.js';
export class ZonedDateTime extends Temporal.ZonedDateTime {
static now(tzLike) {
return ZonedDateTime.from(Temporal.Now.zonedDateTimeISO(tzLike));
}
static from(...args) {
const date = Temporal.ZonedDateTime.from(...args);
return new ZonedDateTime(date.epochNanoseconds, date.timeZoneId, date.calendarId);
}
compare(other) {
return ZonedDateTime.compare(this, other);
}
isBefore(other) {
return ZonedDateTime.compare(this, other) === -1;
}
isAfter(other) {
return this.compare(other) === 1;
}
startOfDay() {
return ZonedDateTime.from(super.startOfDay());
}
startOfYear() {
return ZonedDateTime.from(this.with({ month: 1, day: 1 }));
}
startOfMonth() {
return ZonedDateTime.from(this.with({ day: 1 }));
}
startOfWeek() {
const daysToSubtract = this.dayOfWeek === this.daysInWeek ? 0 : this.dayOfWeek;
return ZonedDateTime.from(this.subtract({ days: daysToSubtract }));
}
endOfYear() {
return ZonedDateTime.from(this.with({ month: this.monthsInYear, day: 1 }));
}
endOfMonth() {
return ZonedDateTime.from(this.with({ day: this.daysInMonth }));
}
endOfWeek() {
return ZonedDateTime.from(this.startOfWeek().add({ days: this.daysInWeek - 1 }));
}
add(...args) {
return ZonedDateTime.from(super.add(...args));
}
subtract(...args) {
return ZonedDateTime.from(super.subtract(...args));
}
with(...args) {
return ZonedDateTime.from(super.with(...args));
}
withCalendar(calendar) {
return ZonedDateTime.from(super.withCalendar(calendar));
}
withPlainTime(...args) {
return ZonedDateTime.from(super.withPlainTime(...args));
}
withTimeZone(timeZone) {
return ZonedDateTime.from(super.withTimeZone(timeZone));
}
round(...args) {
return ZonedDateTime.from(super.round(...args));
}
since(...args) {
return Duration.from(super.since(...args));
}
until(...args) {
return Duration.from(super.until(...args));
}
toPlainDate() {
return PlainDate.from(super.toPlainDate());
}
toPlainDateTime() {
return PlainDateTime.from(super.toPlainDateTime());
}
toPlainTime() {
return PlainTime.from(super.toPlainTime());
}
}
//# sourceMappingURL=zoned-date-time.js.map