Last active
April 25, 2018 19:09
-
-
Save escaroda/175def396ddf878a8002b03f0e41cf10 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 getSpecifiedDay = { | |
oncePerMonth: (fromDate, dayOfWeek, numberOfTimes, startHours, endHours) => { | |
// Get first day of the month by given fromDate | |
const currentMonth = moment(fromDate).startOf('month'); | |
// Get desired dayOfWeek of currentMonth's first week | |
const firstDayInMonth = currentMonth.clone().weekday(dayOfWeek); | |
// Check if firstDayInMonth is in the given month | |
if (firstDayInMonth.month() !== currentMonth.month()) { | |
numberOfTimes++; | |
} | |
return firstDayInMonth.add(--numberOfTimes, 'weeks'); | |
}, | |
oncePerWeek: (fromDate, dayOfWeek, startHours, endHours) => { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment