UNPKG

@everwhen/temporal

Version:
63 lines 2.08 kB
import { Temporal } from 'temporal-polyfill'; import { Duration } from './duration.js'; import { PlainDate } from './plain-date.js'; export class PlainYearMonth extends Temporal.PlainYearMonth { static now() { return PlainYearMonth.from(PlainDate.now()); } static from(...args) { const month = Temporal.PlainYearMonth.from(...args); return new PlainYearMonth(month.year, month.month); } compare(other) { return PlainYearMonth.compare(this, other); } /** * Compares two PlainYearMonth objects. * Comparison is based on the first day of the month in the real world, regardless of the calendar. * * @link https://tc39.es/proposal-temporal/docs/plainyearmonth.html#compare */ isBefore(other) { return PlainYearMonth.compare(this, other) === -1; } /** * Compares two PlainYearMonth objects. * Comparison is based on the first day of the month in the real world, regardless of the calendar. * * @link https://tc39.es/proposal-temporal/docs/plainyearmonth.html#compare */ isAfter(other) { return PlainYearMonth.compare(this, other) === 1; } add(...args) { return PlainYearMonth.from(super.add(...args)); } subtract(...args) { return PlainYearMonth.from(super.subtract(...args)); } contains(date) { return (PlainYearMonth.compare(this, date) <= 0 && PlainYearMonth.compare(this, date) >= 0); } startOfMonth() { return this.toPlainDate({ day: 1 }); } endOfMonth() { return this.toPlainDate({ day: this.toPlainDate().daysInMonth }); } toPlainDate(day) { const opts = day ? day : { day: 1 }; return PlainDate.from(super.toPlainDate(opts)); } with(...args) { return PlainYearMonth.from(super.with(...args)); } until(...args) { return Duration.from(super.until(...args)); } since(...args) { return Duration.from(super.since(...args)); } } //# sourceMappingURL=plain-year-month.js.map