@@ -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
@@ -115,9 +112,12 @@ const CalendarFetcherUtils = {
115112 return JSON . stringify ( d ) !== "null" ;
116113 } ) ;
117114
115+ console . log ( dates ) ;
116+ console . log ( event ) ;
117+
118118 // Dates are returned in UTC timezone but with localdatetime because tzid is null.
119119 // So we map the date to a moment using the original timezone of the event.
120- return dates . map ( ( d ) => moment ( d ) . tz ( event . start . tz , true ) ) ;
120+ return dates . map ( ( d ) => ( event . start . tz ? moment ( d ) . tz ( event . start . tz , true ) : moment ( d ) ) ) ;
121121 } ,
122122
123123 /**
@@ -200,9 +200,13 @@ const CalendarFetcherUtils = {
200200 // Recurring event.
201201 let moments = CalendarFetcherUtils . getMomentsFromRecurringEvent ( event , pastLocalMoment , futureLocalMoment ) ;
202202
203+ console . log ( moments ) ;
204+
203205 // Loop through the set of moment entries to see which recurrences should be added to our event list.
204206 // TODO This should create an event per moment so we can change anything we want.
205207 for ( let m in moments ) {
208+ console . log ( typeof moments [ m ] ) ;
209+ console . log ( moments [ m ] ) ;
206210 let curEvent = event ;
207211 let showRecurrence = true ;
208212 let recurringEventStartMoment = moments [ m ] . tz ( moment . tz . guess ( ) ) . clone ( ) ;
@@ -218,8 +222,17 @@ const CalendarFetcherUtils = {
218222 Log . debug ( "have a recurrence match for dateKey=" , dateKey ) ;
219223 // We found an override, so for this recurrence, use a potentially different title, start date, and duration.
220224 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 ( ) ) ;
225+ // Some event start/end dates don't have timezones
226+ if ( curEvent . start . tz ) {
227+ recurringEventStartMoment = moment ( curEvent . start ) . tz ( curEvent . start . tz ) . tz ( moment . tz . guess ( ) ) ;
228+ } else {
229+ recurringEventStartMoment = moment ( curEvent . start ) . tz ( moment . tz . guess ( ) ) ;
230+ }
231+ if ( curEvent . end . tz ) {
232+ recurringEventEndMoment = moment ( curEvent . end ) . tz ( curEvent . end . tz ) . tz ( moment . tz . guess ( ) ) ;
233+ } else {
234+ recurringEventEndMoment = moment ( curEvent . end ) . tz ( moment . tz . guess ( ) ) ;
235+ }
223236 } else {
224237 Log . debug ( "recurrence key " , dateKey , " doesn't match" ) ;
225238 }
@@ -329,87 +342,6 @@ const CalendarFetcherUtils = {
329342 return newEvents ;
330343 } ,
331344
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-
413345 /**
414346 * get the exdate/recurrence hash key from the date object
415347 * BEFORE calling rrule.between
@@ -418,9 +350,8 @@ const CalendarFetcherUtils = {
418350 */
419351 getDateKeyFromDate ( date ) {
420352 // get our runtime timezone offset
421- const nowDiff = CalendarFetcherUtils . getTimezoneOffsetFromTimezone ( moment . tz . guess ( ) ) ;
422353 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 ) } ` ) ;
354+ Log . debug ( " day of month=" , ( `0${ startday } ` ) . slice ( - 2 ) , ` start time=${ date . toString ( ) . split ( " " ) [ 4 ] . slice ( 0 , 2 ) } ` ) ;
424355 Log . debug ( "date string= " , date . toString ( ) ) ;
425356 Log . debug ( "date iso string " , date . toISOString ( ) ) ;
426357 // if the dates are different
@@ -436,18 +367,6 @@ const CalendarFetcherUtils = {
436367 return date . toISOString ( ) . substring ( 0 , 8 ) + ( `0${ startday } ` ) . slice ( - 2 ) ;
437368 } ,
438369
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-
451370 /**
452371 * Gets the title from the event.
453372 * @param {object } event The event object to check.
0 commit comments