import { chunkArray } from './array' ; /**
 * Days of the week (JS-like enum)
 */ export enum WeekDays { Sunday = 0 , Monday , Tuesday , Wednesday , Thursday , Friday , Saturday } /**
 * Months (JS-like enum)
 */ export enum Months { January = 0 , February , March , April , May , June , July , August , September , October , November , December } param year param month param startOn export function getCalendar ( year , month , startOn = WeekDays . Sunday ) { if ( month < 0 || month > 11 ) { throw new Error ( 'Invalid month' ) ; } const daysInMonth = new Date ( year , month + 1 , 0 ) . getDate ( ) ; const daysInLastMonth = new Date ( year , month , 0 ) . getDate ( ) ; const firstWeekDay = new Date ( year , month , 1 ) . getDay ( ) ; const lastMonthSlice = firstWeekDay - startOn ; const nextMonthSlice = 7 - ( ( lastMonthSlice + daysInMonth ) % 7 ) ; const days = [ ... Array ( lastMonthSlice ) . fill ( 0 ) . map ( ( _ , i , lastMonthSlice ) => new Date ( year , month - 1 , daysInLastMonth - lastMonthSlice . length + i + 1 ) ) , ... Array ( daysInMonth ) . fill ( 0 ) . map ( ( _ , i ) => new Date ( year , month , i + 1 ) ) , ... Array ( nextMonthSlice ) . fill ( 0 ) . map ( ( _ , i ) => new Date ( year , month + 1 , i + 1 ) ) , ] ; return chunkArray ( days , 7 ) ; } param date export function normalizeDate ( date ) { return new Date ( date . getFullYear ( ) , date . getMonth ( ) , date . getDate ( ) ) . getTime ( ) ; } param date export function normalizeMonth ( date ) { const year = date . getFullYear ( ) ; const month = `${ date . getMonth ( ) + 1 }` . padStart ( 2 , '0' ) ; return parseInt ( [ year , month ] . join ( '' ) , 10 ) ; }