Skip to content

Instantly share code, notes, and snippets.

@banjeremy
Last active May 24, 2016 17:54
Show Gist options
  • Save banjeremy/f36a5bac846b66c255bec37ac26ee711 to your computer and use it in GitHub Desktop.
Save banjeremy/f36a5bac846b66c255bec37ac26ee711 to your computer and use it in GitHub Desktop.
checks if a given day is an occurance in a recurrence rule
export function isDayAnOccurance(day, recurrenceRule) {
const rule = RRule.fromString(recurrenceRule);
// Convert all dates into UTC before comparison
const today = moment(day).utc().startOf('day');
const nextOccurrence = moment(rule.after(today, true)).utc();
const match = moment(nextOccurrence).isSame(today, 'day');
return match;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment