import { Dayjs } from 'dayjs'; import { Duration } from '@wisemen/quantity'; import { Timezone } from '../common/timezone.js'; import { PlainTime } from '../plain-time/plain-time.js'; import { Month } from '../common/month.js'; import { Timestamp } from '../timestamp/timestamp.js'; import { PlainDateObject } from './plain-date-object.js'; import { PlainDateUnit, ReachablePlainDateUnit, DiffPlainDateUnit } from './plain-date.units.js'; import { IsoWeekParity } from './iso-week-parity.js'; import { IsoWeekday } from '#src/common/iso-weekday.js'; export type PlainDateInput = Dayjs | string | Date | PlainDateObject | PlainDate | number | Timestamp | { toDate(): Date; } | undefined; export interface PlainDate { isSame(otherDate: PlainDateInput): boolean; isAfter(otherDate: PlainDateInput): boolean; isSameOrAfter(otherDate: PlainDateInput): boolean; isBefore(otherDate: PlainDateInput, unit?: PlainDateUnit): boolean; isSameOrBefore(otherDate: PlainDateInput): boolean; startOf(unit: ReachablePlainDateUnit): PlainDate; endOf(unit: ReachablePlainDateUnit): PlainDate; year(): number; month(): Month; dayOfMonth(): number; weekOfYear(): number; dayOfYear(): number; isToday(): boolean; isTomorrow(): boolean; isYesterday(): boolean; add(amount: number, unit: PlainDateUnit): PlainDate; /** * Returns a new `PlainDate` instance with the duration added. \ * Any duration less than a full day does not change the date, but still returns a * new instance (except for infinities which are singletons). \ * Similarly a duration of 1.4 days is applied as 1 day. */ addDuration(duration: Duration): PlainDate; subtract(amount: number, unit: PlainDateUnit): PlainDate; /** * Returns a new `PlainDate` instance with the duration subtracted. \ * Any duration less than a full day does not change the date, but still returns a new instance * (except for infinities which are singletons). \ * Similarly a duration of 1.4 days is applied as 1 day. */ subtractDuration(duration: Duration): PlainDate; /** * Returns the duration until the given date. * If the date lies before this date, the duration is negative. * If the date lies after this date, the duration is positive. */ until(otherDate: PlainDateInput): Duration; /** * Returns the duration since the given date. * If the date lies before this date, the duration is positive. * If the date lies after this date, the duration is negative. */ since(otherDate: PlainDateInput): Duration; diff(withOther: PlainDateInput, unit: DiffPlainDateUnit): number; /** * Compares the order of the given date with this date. \ * returns < 0 if this date is before the given date \ * returns 0 if this date is the same as the given date \ * returns > 0 if this date is after the given date \ * \ * Comparing a date with infinities results in `-Infinity` or `Infinity` (Number) \ * Comparing infinities will result in 0 when they represent the same infinity. * \ * The returned value is the result of a `diff` days between the compared values. */ compare(withOther: PlainDateInput): number; /** @see https://day.js.org/docs/en/display/format */ format(template: string): string; clone(): PlainDate; toPlainObject(): PlainDateObject; toDate(withTime?: PlainTime, timezone?: Timezone): Date; toString(): string; toJSON(): string; toTimestamp(withTime?: PlainTime, timezone?: Timezone): Timestamp; isFutureInfinity(): boolean; isPastInfinity(): boolean; /** @returns Returns numbers from 0 (Sunday) to 6 (Saturday). */ day(): number; isMonday(): boolean; isTuesday(): boolean; isWednesday(): boolean; isThursday(): boolean; isFriday(): boolean; isSaturday(): boolean; isSunday(): boolean; /** * @returns Returns numbers from 1 (Monday) to 7 (Sunday). */ isoWeekday(): IsoWeekday; /** * @param day a number in 1 (Monday) to 7 (Sunday). * @returns A new plain date with the changed iso weekday. */ isoWeekday(day: IsoWeekday): PlainDate; /** * Get a new plain date with the next occurrence of the target weekday. * * Advances to the next week when the target weekday has already occurred in the * week of this date or when the target weekday is the weekday of this date. * * @param day the ISO weekday to target * @returns a new plain date */ nextIsoWeekday(day: IsoWeekday): PlainDate; /** * Get a new plain date with the next occurrence of the target weekday, * keeping the current date when it already falls on that weekday. * * Advances to the next week only when the target weekday has already occurred * in the week of this date. * * @param day the ISO weekday to target * @returns a new plain date */ nextOrSameIsoWeekday(day: IsoWeekday): PlainDate; /** * Get a new plain date with the previous occurrence of the target weekday. * * Moves to the previous week when the target weekday occurs later in the week * of this date or when the target weekday is the weekday of this date. * * @param day the ISO weekday to target * @returns a new plain date */ previousIsoWeekday(day: IsoWeekday): PlainDate; /** * Get a new plain date with the previous occurrence of the target weekday, * keeping the current date when it already falls on that weekday. * * Moves to the previous week only when the target weekday occurs later in the * week of this date. * * @param day the ISO weekday to target * @returns a new plain date */ previousOrSameIsoWeekday(day: IsoWeekday): PlainDate; /** * @returns Returns the ISO week number (1–53). */ isoWeek(): number; /** * @returns Returns whether the ISO week number is odd or even. */ isoWeekParity(): IsoWeekParity; /** * @returns Returns the Unix timestamp (the number of seconds since the Unix Epoch) */ unix(withTime?: PlainTime, timezone?: Timezone): number; isInfinity(): boolean; valueOf(): string; }