Skip to content

Instantly share code, notes, and snippets.

@escaroda
Last active April 25, 2018 19:09
Show Gist options
  • Save escaroda/175def396ddf878a8002b03f0e41cf10 to your computer and use it in GitHub Desktop.
Save escaroda/175def396ddf878a8002b03f0e41cf10 to your computer and use it in GitHub Desktop.
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