UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

20 lines • 1.08 kB
/** * Compare two month-day strings (`--MM-DD`, or `MM-DD`) in calendar order: month first, then day. * * - Accepts both input forms, so `12-25` and `--12-25` compare equal. * - The year is not part of a month-day: `--02-29` sorts between `--02-28` and `--03-01`. * (Temporal has no `PlainMonthDay.compare`; this compares the matching `PlainDate`s in the * leap reference year 1972, as the note on `PlainMonthDay.prototype.valueOf` directs.) * - Returns `null` if either input is invalid or not in the ISO calendar. * * @param a month-day string * @param b month-day string * @returns -1, 0, or 1, or null on invalid input * * @example compareMonthDays("--01-01", "--12-31") // -1 * @example compareMonthDays("12-25", "--12-25") // 0 * @example compareMonthDays("--02-29", "--02-28") // 1 * @example compareMonthDays("--02-30", "--03-01") // null * @example ["--12-25", "--02-29", "--02-28"].sort((a, b) => compareMonthDays(a, b) ?? 0) // ["--02-28", "--02-29", "--12-25"] */ export declare function compareMonthDays(a: string, b: string): number | null;