@everwhen/temporal
Version:
76 lines • 2.36 kB
JavaScript
import { Temporal } from 'temporal-polyfill';
import { Duration } from './duration.js';
import { PlainDateTime } from './plain-date-time.js';
import { PlainYearMonth } from './plain-year-month.js';
import { ZonedDateTime } from './zoned-date-time.js';
export class PlainDate extends Temporal.PlainDate {
static now(tzLike) {
return PlainDate.from(Temporal.Now.plainDateISO(tzLike));
}
static from(...args) {
const date = Temporal.PlainDate.from(...args);
return new PlainDate(date.year, date.month, date.day, date.calendarId);
}
weekday(locales, format = 'long') {
return this.toLocaleString(locales, { weekday: format });
}
compare(other) {
return PlainDate.compare(this, other);
}
isBefore(other) {
return PlainDate.compare(this, other) === -1;
}
isAfter(other) {
return PlainDate.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 });
}
with(...args) {
return PlainDate.from(super.with(...args));
}
add(...args) {
return PlainDate.from(super.add(...args));
}
subtract(...args) {
return PlainDate.from(super.subtract(...args));
}
isToday() {
return PlainDate.now().equals(this);
}
toPlainYearMonth() {
return PlainYearMonth.from(this);
}
toZonedDateTime(...args) {
return ZonedDateTime.from(super.toZonedDateTime(...args));
}
toPlainDateTime(...args) {
return PlainDateTime.from(super.toPlainDateTime(...args));
}
withCalendar(calendar) {
return PlainDate.from(super.withCalendar(calendar));
}
since(...args) {
return Duration.from(super.since(...args));
}
until(...args) {
return Duration.from(super.until(...args));
}
}
//# sourceMappingURL=plain-date.js.map