Skip to content

Commit 4cc7cab

Browse files
committed
Removed unused functions and fixed a small issue with recurrence override handling
1 parent affc719 commit 4cc7cab

File tree

2 files changed

+3
-102
lines changed

2 files changed

+3
-102
lines changed

modules/default/calendar/calendar.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* global CalendarUtils */
22

3-
const moment = require("moment-timezone");
4-
53
Module.register("calendar", {
64
// Define module defaults
75
defaults: {

modules/default/calendar/calendarfetcherutils.js

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ const CalendarFetcherUtils = {
9797

9898
Log.debug("fix rrule start=", rule.options.dtstart);
9999
Log.debug("event before rrule.between=", JSON.stringify(event, null, 2), "exdates=", event.exdate);
100-
// fixup the exdate and recurrence date to local time too for post between() handling
101-
// TODO figure out what this does
102-
// CalendarFetcherUtils.fixEventtoLocal(event);
103100

104101
Log.debug(`RRule: ${rule.toString()}`);
105102
rule.options.tzid = null; // RRule gets *very* confused with timezones
@@ -218,8 +215,8 @@ const CalendarFetcherUtils = {
218215
Log.debug("have a recurrence match for dateKey=", dateKey);
219216
// We found an override, so for this recurrence, use a potentially different title, start date, and duration.
220217
curEvent = curEvent.recurrences[dateKey];
221-
recurringEventStartMoment = moment(curEvent.start).tz(curEvent.start.tz, true).tz(moment.tz.guess());
222-
recurringEventEndMoment = moment(curEvent.end).tz(curEvent.end.tz, true).tz(moment.tz.guess());
218+
recurringEventStartMoment = moment(curEvent.start).tz(curEvent.start.tz).tz(moment.tz.guess());
219+
recurringEventEndMoment = moment(curEvent.end).tz(curEvent.end.tz).tz(moment.tz.guess());
223220
} else {
224221
Log.debug("recurrence key ", dateKey, " doesn't match");
225222
}
@@ -329,87 +326,6 @@ const CalendarFetcherUtils = {
329326
return newEvents;
330327
},
331328

332-
/**
333-
* Fixes the event fields that have dates to use local time
334-
* before calling rrule.between.
335-
* @param {object} event - The event being processed.
336-
* @returns {void}
337-
*/
338-
fixEventtoLocal (event) {
339-
// if there are excluded dates, their date is incorrect and possibly key as well.
340-
if (event.exdate !== undefined) {
341-
Object.keys(event.exdate).forEach((dateKey) => {
342-
// get the date
343-
let exdate = event.exdate[dateKey];
344-
Log.debug("exdate w key=", exdate);
345-
//exdate=CalendarFetcherUtils.convertDateToLocalTime(exdate, event.end.tz)
346-
exdate = new Date(new Date(exdate.valueOf() - ((120 * 60 * 1000))).getTime());
347-
Log.debug("new exDate item=", exdate, " with old key=", dateKey);
348-
let newkey = exdate.toISOString().slice(0, 10);
349-
if (newkey !== dateKey) {
350-
Log.debug("new exDate item=", exdate, ` key=${newkey}`);
351-
event.exdate[newkey] = exdate;
352-
//delete event.exdate[dateKey]
353-
}
354-
});
355-
Log.debug("updated exdate list=", event.exdate);
356-
}
357-
if (event.recurrences) {
358-
Object.keys(event.recurrences).forEach((dateKey) => {
359-
let exdate = event.recurrences[dateKey];
360-
//exdate=new Date(new Date(exdate.valueOf()-(60*60*1000)).getTime())
361-
Log.debug("new recurrence item=", exdate, " with old key=", dateKey);
362-
exdate.start = CalendarFetcherUtils.convertDateToLocalTime(exdate.start, exdate.start.tz);
363-
exdate.end = CalendarFetcherUtils.convertDateToLocalTime(exdate.end, exdate.end.tz);
364-
Log.debug("adjusted recurringEvent start=", exdate.start, " end=", exdate.end);
365-
});
366-
}
367-
Log.debug("modified recurrences before rrule.between", event.recurrences);
368-
},
369-
370-
/**
371-
* convert a UTC date to local time
372-
* BEFORE calling rrule.between
373-
* @param {Date} date The date to convert
374-
* @param {string} tz The timezone string to convert the date to.
375-
* @returns {Date} updated date object
376-
*/
377-
convertDateToLocalTime (date, tz) {
378-
let delta_tz_offset = 0;
379-
let now_offset = CalendarFetcherUtils.getTimezoneOffsetFromTimezone(moment.tz.guess());
380-
let event_offset = CalendarFetcherUtils.getTimezoneOffsetFromTimezone(tz);
381-
Log.debug("date to convert=", date);
382-
if (Math.sign(now_offset) !== Math.sign(event_offset)) {
383-
delta_tz_offset = Math.abs(now_offset) + Math.abs(event_offset);
384-
} else {
385-
// signs are the same
386-
// if negative
387-
if (Math.sign(now_offset) === -1) {
388-
// la looking at chicago
389-
if (now_offset < event_offset) { // 5 -7
390-
delta_tz_offset = now_offset - event_offset;
391-
}
392-
else { //7 -5 , chicago looking at LA
393-
delta_tz_offset = event_offset - now_offset;
394-
}
395-
}
396-
else {
397-
// berlin looking at sydney
398-
if (now_offset < event_offset) { // 5 -7
399-
delta_tz_offset = event_offset - now_offset;
400-
Log.debug("less delta=", delta_tz_offset);
401-
}
402-
else { // 11 - 2, sydney looking at berlin
403-
delta_tz_offset = -(now_offset - event_offset);
404-
Log.debug("more delta=", delta_tz_offset);
405-
}
406-
}
407-
}
408-
const newdate = new Date(new Date(date.valueOf() + (delta_tz_offset * 60 * 1000)).getTime());
409-
Log.debug("modified date =", newdate);
410-
return newdate;
411-
},
412-
413329
/**
414330
* get the exdate/recurrence hash key from the date object
415331
* BEFORE calling rrule.between
@@ -418,9 +334,8 @@ const CalendarFetcherUtils = {
418334
*/
419335
getDateKeyFromDate (date) {
420336
// get our runtime timezone offset
421-
const nowDiff = CalendarFetcherUtils.getTimezoneOffsetFromTimezone(moment.tz.guess());
422337
let startday = date.getDate();
423-
Log.debug(" day of month=", (`0${startday}`).slice(-2), " nowDiff=", nowDiff, ` start time=${date.toString().split(" ")[4].slice(0, 2)}`);
338+
Log.debug(" day of month=", (`0${startday}`).slice(-2), ` start time=${date.toString().split(" ")[4].slice(0, 2)}`);
424339
Log.debug("date string= ", date.toString());
425340
Log.debug("date iso string ", date.toISOString());
426341
// if the dates are different
@@ -436,18 +351,6 @@ const CalendarFetcherUtils = {
436351
return date.toISOString().substring(0, 8) + (`0${startday}`).slice(-2);
437352
},
438353

439-
/**
440-
* get the timezone offset from the timezone string
441-
* @param {string} timeZone The timezone string
442-
* @returns {number} The numerical offset in minutes from UTC.
443-
*/
444-
getTimezoneOffsetFromTimezone (timeZone) {
445-
const str = new Date().toLocaleString("en", { timeZone, timeZoneName: "longOffset" });
446-
Log.debug("tz offset=", str);
447-
const [_, h, m] = str.match(/([+-]\d+):(\d+)$/) || ["", "+00", "00"];
448-
return h * 60 + (h > 0 ? +m : -m);
449-
},
450-
451354
/**
452355
* Gets the title from the event.
453356
* @param {object} event The event object to check.

0 commit comments

Comments
 (0)