1/**2 * The proleptic Gregorian calendar, in UTC: leap years, month lengths, and3 * the instant a calendar day starts. Months are 1 to 12 here, as people4 * write them, not 0 to 11 as `Date` counts them.5 */67export const MS_PER_SECOND = 1000;8export const MS_PER_MINUTE = 60 * MS_PER_SECOND;9export const MS_PER_HOUR = 60 * MS_PER_MINUTE;10export const MS_PER_DAY = 24 * MS_PER_HOUR;1112/** Whether `year` has a February 29. */13export const isLeapYear = (year: number): boolean =>14 (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;1516const MONTH_LENGTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];1718/** How many days `month` (1 to 12) of `year` has. */19export const daysInMonth = (year: number, month: number): number =>20 month === 2 && isLeapYear(year) ? 29 : (MONTH_LENGTHS[month - 1] ?? Number.NaN);2122/** How many days `year` has: 365, or 366 in a leap year. */23export const daysInYear = (year: number): number => (isLeapYear(year) ? 366 : 365);2425/**26 * The instant `year-month-day` starts in UTC, in epoch milliseconds.27 * `Date.UTC` reads the years 0 to 99 as 1900 to 1999; this doesn't.28 */29export const utcMidnight = (year: number, month: number, day: number): number => {30 const date = new Date(0);3132 date.setUTCFullYear(year, month - 1, day);3334 return date.getTime();35};3637/** The ISO weekday of an instant in UTC: Monday is 1 and Sunday is 7. */38export const isoWeekday = (date: Date): number => date.getUTCDay() || 7;