Last active
January 14, 2021 04:45
-
-
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)
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
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