Skip to content

Instantly share code, notes, and snippets.

@cngeru
Last active January 14, 2021 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cngeru/ba4a633f12102632c9a46eac318f0dc3 to your computer and use it in GitHub Desktop.
Save cngeru/ba4a633f12102632c9a46eac318f0dc3 to your computer and use it in GitHub Desktop.
Get all sundays a month or get "specific day of week" in a month using dayjs (In the future)
func getSundays {
let startTime = 1234294232 // unix timestamp of a day in paricular
const startTimeObj = dayjs.unix(startTime)
const startOfDay = dayjs().startOf('day',startTimeObj)
const endOfMonth = dayjs().endOf('month',startTimeObj)
const days = []
let pastEndMonth = false
let newDay = startOfDay.add(7, 'days')
do {
let diff = endOfMonth.diff(newDay,'days')
if (diff < 1) {
pastEndMonth = true
}else{
pastEndMonth = false
days.push(newDay)
newDay = newDay.add(7, 'days')
}
} while (pastEndMonth === false);
console.log(days)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment