@everwhen/temporal
Version:
80 lines • 2.57 kB
JavaScript
import { Temporal } from 'temporal-polyfill';
import { Duration } from './duration.js';
import { PlainDate } from './plain-date.js';
import { PlainTime } from './plain-time.js';
import { PlainYearMonth } from './plain-year-month.js';
import { ZonedDateTime } from './zoned-date-time.js';
export class PlainDateTime extends Temporal.PlainDateTime {
static now(tzLike) {
return PlainDateTime.from(Temporal.Now.plainDateTimeISO(tzLike));
}
static from(...args) {
const date = Temporal.PlainDateTime.from(...args);
return new PlainDateTime(date.year, date.month, date.day, date.hour, date.minute, date.second, date.millisecond, date.microsecond, date.nanosecond, date.calendarId);
}
compare(other) {
return PlainDateTime.compare(this, other);
}
isBefore(other) {
return PlainDateTime.compare(this, other) === -1;
}
isAfter(other) {
return PlainDateTime.compare(this, other) === 1;
}
startOfYear() {
return this.with({ month: 1, day: 1 });
}
startOfMonth() {
return this.with({ day: 1 });
}
startOfWeek() {
const daysToSubtract = this.dayOfWeek === this.daysInWeek ? 0 : this.dayOfWeek;
return this.subtract({ days: daysToSubtract });
}
endOfYear() {
return this.with({ day: this.daysInYear });
}
endOfMonth() {
return this.with({ day: this.daysInMonth });
}
endOfWeek() {
return this.startOfWeek().add({ days: this.daysInWeek - 1 });
}
subtract(...args) {
return PlainDateTime.from(super.subtract(...args));
}
add(...args) {
return PlainDateTime.from(super.add(...args));
}
since(...args) {
return Duration.from(super.since(...args));
}
until(...args) {
return Duration.from(super.until(...args));
}
round(...args) {
return PlainDateTime.from(super.round(...args));
}
toPlainDate() {
return PlainDate.from(this);
}
toPlainTime() {
return PlainTime.from(this);
}
toZonedDateTime(...args) {
return ZonedDateTime.from(super.toZonedDateTime(...args));
}
toPlainYearMonth() {
return PlainYearMonth.from(this);
}
withPlainTime(timeLike) {
return PlainDateTime.from(super.withPlainTime(timeLike));
}
withCalendar(calendar) {
return PlainDateTime.from(super.withCalendar(calendar));
}
with(...args) {
return PlainDateTime.from(super.with(...args));
}
}
//# sourceMappingURL=plain-date-time.js.map