Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function returnDatesArrayByRepeatRule(event, startDate, endDate) {
const rule = new RRule(createRRule(event));
try {
let eventDuration = event.end_time_utc - event.start_time_utc;
let adjustedStartDate = new Date(
moment(startDate).add(
-1 * eventDuration - 1 * 1000 * 60 * 60,
'milliseconds',
), // we are subtracting one hour because RRule has not been accounting for Daylight Savings Time properly - may need to consider rewriting to remove Rrule implementation with something that's more transparent about how it handles DST
); //between searches on START times, and we want to get anything in progress in this date range, so subtract the event duration from the start time
let events = rule.between(adjustedStartDate, new Date(endDate));
return events;
} catch (e) {
console.log('Error in returnDatesArrayByRepeatRule');
console.log(e);
return null;
this.id = event.id;
if (this.id) {
this.calendar = this.id.split('/')[0];
}
if (event['VEVENT']) {
const vevent = event['VEVENT'];
this.dtstart = moment(vevent.dtstart, moment.ISO_8601);
if (vevent.dtend) {
this.dtend = moment(vevent.dtend, moment.ISO_8601);
}
this.title = vevent.summary;
this.allDay = vevent.dtstart.indexOf('T') === -1;
this.vevent = vevent;
if (vevent.rrule) {
this.rrule = rrulestr(vevent.rrule, { dtstart: this.dtstart.toDate() });
this.draggable = false;
}
} else {
// "copy constructor" :)
this.dtstart = event.dtstart;
this.dtend = event.dtend;
this.title = event.title;
this.allDay = event.allDay;
this.vevent = event.vevent;
this.rrule = event.rrule;
this.color = event.color;
this.draggable = event.draggable;
}
this.refreshDates();
input_frequency = RRule.MONTHLY;
break;
case 2:
input_frequency = RRule.WEEKLY;
break;
case 3:
input_frequency = RRule.DAILY;
break;
}
if(isNaN(start_year) == false || isNaN(end_year) == false) {
// TODO Might be Deprecated -- IF RRule Breaks, this is where it will happen
// TODO remove tzid from rule object
let date_start = new Date(Date.UTC(start_year, start_month - 1, start_day, start_hour, start_minute))
let until = new Date(Date.UTC(end_year, end_month - 1, end_day, end_hour, end_minute))
const rule = new RRule({
freq: input_frequency,
count: this.selected_count,
byweekday: this.selected_weekdays,
dtstart: date_start,
until: until,
tzid: Intl.DateTimeFormat().resolvedOptions().timeZone,
})
let array = rule.all()
this.rrule_text = rule.toText()
array.forEach(date => {
let formatted_start_date = moment(date).clone().set({hour: local_start_hour}).format('YYYY-MM-DD HH:mm:ssZ')
let formatted_end_date = moment(date).clone().set({hour: local_start_hour}).add(duration_minutes, 'minutes').format('YYYY-MM-DD HH:mm:ssZ')
local_dates_array.push({start: formatted_start_date, end: formatted_end_date})
})
}
case 2:
booking_input_frequency = RRule.WEEKLY;
break;
case 3:
booking_input_frequency = RRule.DAILY;
break;
}
if(isNaN(start_year) == false || isNaN(end_year) == false){
// TODO Might be Deprecated -- IF RRule Breaks, this is where it will happen
// Removed hours and minutes from date_start and until
let date_start = new Date(Date.UTC(start_year, start_month -1, start_day))
let until = new Date(Date.UTC(end_year, end_month -1, end_day))
const rule = new RRule({
freq: booking_input_frequency,
count: this.selected_booking_count,
byweekday: this.selected_booking_weekdays,
dtstart: date_start,
until: until,
})
let array = rule.all()
this.booking_rrule_text = rule.toText()
array.forEach(date => {
// created date_with_offset to fix pst -> utc 5pm bug
let date_with_offset = moment(date).clone().set({hour: local_start_hour, minute: start_minute}).add(new Date().getTimezoneOffset(), 'minutes')
if(local_start_hour >= 8 && local_start_hour < 15){
date_with_offset.add(1, 'day')
}
let formatted_start_date = moment(date_with_offset).clone().set({hour: local_start_hour, minute: start_minute}).format('YYYY-MM-DD HH:mm:ssZ')
if (typeof refined.until === 'string') {
refined.until = dateEnv.createMarker(refined.until);
}
if (refined.freq != null) {
refined.freq = convertConstant(refined.freq);
}
if (refined.wkst != null) {
refined.wkst = convertConstant(refined.wkst);
}
else {
refined.wkst = (dateEnv.weekDow - 1 + 7) % 7; // convert Sunday-first to Monday-first
}
if (refined.byweekday != null) {
refined.byweekday = convertConstants(refined.byweekday); // the plural version
}
rrule = new RRule(refined);
}
if (rrule) {
return { rrule: rrule, allDayGuess: allDayGuess };
}
return null;
}
function convertConstants(input) {
input_frequency = RRule.MONTHLY;
break;
case 2:
input_frequency = RRule.WEEKLY;
break;
case 3:
input_frequency = RRule.DAILY;
break;
}
if(isNaN(start_year) == false || isNaN(end_year) == false){
// TODO Might be Deprecated -- IF RRule Breaks, this is where it will happen
let date_start = new Date(Date.UTC(start_year, start_month-1, start_day))
let until = new Date(Date.UTC(end_year, end_month-1, end_day))
const rule = new RRule({
freq: input_frequency,
count: this.other_selected_count,
byweekday: this.other_selected_weekdays,
dtstart: date_start,
until: until
})
let array = rule.all()
this.other_rrule_text = rule.toText()
// TODO For the night is dark and full of terror
let first_event_start_day = moment(this.startTime).clone().set({hour: local_start_hour, minute: local_start_minute}).add(new Date(this.startTime).getTimezoneOffset(), 'minutes')
let num_days = Math.floor(moment.duration(first_event_start_day.diff(moment(new Date()))).asDays())
array.forEach(date => {
// TODO For the night is dark and full of terror
let date_with_offset = moment(date).clone().set({hour: local_start_hour, minute: local_start_minute}).add(new Date(date).getTimezoneOffset(), 'minutes')
function parseRRule(input, dateEnv: DateEnv) {
let allDayGuess = null
let rrule
if (typeof input === 'string') {
rrule = rrulestr(input)
} else if (typeof input === 'object' && input) { // non-null object
let refined = { ...input } // copy
if (typeof refined.dtstart === 'string') {
let dtstartMeta = dateEnv.createMarkerMeta(refined.dtstart)
if (dtstartMeta) {
refined.dtstart = dtstartMeta.marker
allDayGuess = dtstartMeta.isTimeUnspecified
} else {
delete refined.dtstart
}
}
if (typeof refined.until === 'string') {
let duration_minutes = duration.asMinutes()
let booking_input_frequency = null
let local_booking_dates_array = []
switch(this.selected_booking_frequency[0]){
case 0:
booking_input_frequency = RRule.YEARLY;
break;
case 1:
booking_input_frequency = RRule.MONTHLY;
break;
case 2:
booking_input_frequency = RRule.WEEKLY;
break;
case 3:
booking_input_frequency = RRule.DAILY;
break;
}
if(isNaN(start_year) == false || isNaN(end_year) == false){
// TODO Might be Deprecated -- IF RRule Breaks, this is where it will happen
// Removed hours and minutes from date_start and until
let date_start = new Date(Date.UTC(start_year, start_month -1, start_day))
let until = new Date(Date.UTC(end_year, end_month -1, end_day))
const rule = new RRule({
freq: booking_input_frequency,
count: this.selected_booking_count,
byweekday: this.selected_booking_weekdays,
dtstart: date_start,
until: until,
let duration_minutes = duration.asMinutes()
let input_frequency = null
let local_other_dates_array = []
switch(this.other_selected_frequency[0]){
case 0:
input_frequency = RRule.YEARLY;
break;
case 1:
input_frequency = RRule.MONTHLY;
break;
case 2:
input_frequency = RRule.WEEKLY;
break;
case 3:
input_frequency = RRule.DAILY;
break;
}
if(isNaN(start_year) == false || isNaN(end_year) == false){
// TODO Might be Deprecated -- IF RRule Breaks, this is where it will happen
let date_start = new Date(Date.UTC(start_year, start_month-1, start_day))
let until = new Date(Date.UTC(end_year, end_month-1, end_day))
const rule = new RRule({
freq: input_frequency,
count: this.other_selected_count,
byweekday: this.other_selected_weekdays,
dtstart: date_start,
until: until
})
let duration_minutes = duration.asMinutes()
let input_frequency = null
let local_dates_array = []
switch(this.selected_frequency[0]){
case 0:
input_frequency = RRule.YEARLY;
break;
case 1:
input_frequency = RRule.MONTHLY;
break;
case 2:
input_frequency = RRule.WEEKLY;
break;
case 3:
input_frequency = RRule.DAILY;
break;
}
if(isNaN(start_year) == false || isNaN(end_year) == false) {
// TODO Might be Deprecated -- IF RRule Breaks, this is where it will happen
// TODO remove tzid from rule object
let date_start = new Date(Date.UTC(start_year, start_month - 1, start_day, start_hour, start_minute))
let until = new Date(Date.UTC(end_year, end_month - 1, end_day, end_hour, end_minute))
const rule = new RRule({
freq: input_frequency,
count: this.selected_count,
byweekday: this.selected_weekdays,
dtstart: date_start,
until: until,
tzid: Intl.DateTimeFormat().resolvedOptions().timeZone,
})