Skip to content

Instantly share code, notes, and snippets.

const getWeekStart = (date: Date=new Date(), mondayStart: boolean=false): Date => {
const offset = mondayStart ? 1 : 0
date.setDate(date.getDate() - date.getDay() +offset)
date.setHours(0,0,0,0)
return new Date(date)
}
const getWeekEnd = (date: Date=new Date(), mondayStart: boolean=false): Date => {
const offset = mondayStart ? 1 : 0
date.setDate(date.getDate() - date.getDay() + 6 + offset)