Last active
February 12, 2022 12:43
-
-
Save hirokihokari/fd5dbe02638405857d799dcc6817f5a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
date.setHours(23,59,59,59) | |
return new Date(date) | |
} | |
const getMonthStart = (date: Date=new Date()): Date => { | |
date.setDate(1) | |
date.setHours(0,0,0,0) | |
return new Date(date) | |
} | |
const getMonthEnd = (date: Date=new Date()): Date => { | |
date.setMonth(date.getMonth()+1) | |
date.setDate(0) | |
date.setHours(23,59,59,59) | |
return new Date(date) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment