ice_cube icon indicating copy to clipboard operation
ice_cube copied to clipboard

Time zone support in `schedule_from_ical`

Open epologee opened this issue 2 years ago • 12 comments

The base implementation of IceCube::IcalParser.schedule_from_ical ignores time zone identifiers, resulting in all times being parsed in the current time zone of the host.

This PR exposes the issue with a series of specs, and fixes it with a (somewhat lengthy) time zone lookup. This last part was added because the TZID strings of the iCal format don't map cleanly onto Rails time zones.

Input schedule

DTSTART;TZID=MDT:20130731T143000
RRULE:FREQ=WEEKLY;UNTIL=20140730T203000Z;BYDAY=MO,WE,FR
RDATE;TZID=MDT:20150812T143000
RDATE;TZID=MDT:20150807T143000
EXDATE;TZID=MDT:20130823T143000
EXDATE;TZID=MDT:20130812T143000
EXDATE;TZID=MDT:20130807T143000
DTEND;TZID=MDT:20130731T153000

Output schedule on master

DTSTART;TZID=CEST:20130731T143000
RRULE:FREQ=WEEKLY;UNTIL=20140730T203000Z;BYDAY=MO,WE,FR
RDATE;TZID=CEST:20150812T143000
RDATE;TZID=CEST:20150807T143000
EXDATE;TZID=CEST:20130823T143000
EXDATE;TZID=CEST:20130812T143000
EXDATE;TZID=CEST:20130807T143000
DTEND;TZID=CEST:20130731T153000

Output schedule on this branch

DTSTART;TZID=MDT:20130731T143000
RRULE:FREQ=WEEKLY;UNTIL=20140730T203000Z;BYDAY=MO,WE,FR
RDATE;TZID=MDT:20150812T143000
RDATE;TZID=MDT:20150807T143000
EXDATE;TZID=MDT:20130823T143000
EXDATE;TZID=MDT:20130812T143000
EXDATE;TZID=MDT:20130807T143000
DTEND;TZID=MDT:20130731T153000

P.S. Note that time zones will not always match the exact same string, because something like "America/Denver" will get converted to "MDT" along the way. The times will still match semantically.

epologee avatar Apr 28 '22 10:04 epologee

Hey @epologee, thanks for sending this through!

I'll find some time in the next day or two to review this properly. In the mean time, can you add a changelog entry and ensure your tests pass?

pacso avatar May 03 '22 07:05 pacso

Hi, thanks, will do / already done!

In the mean time, can you add a changelog entry and ensure your tests pass?

standardrb reports an indentation issue on lines that I did not touch (in a file I did touch), would you like me to add a commit to fix that indentation? Because the workflow needs your approval to run, I'm not sure if it passes or errors right now:

  lib/ice_cube/time_util.rb:289:18: Layout/CaseIndentation: Indent `when` as deep as `end`.
  lib/ice_cube/time_util.rb:290:18: Layout/CaseIndentation: Indent `when` as deep as `end`.
  lib/ice_cube/time_util.rb:291:18: Layout/CaseIndentation: Indent `when` as deep as `end`.
  lib/ice_cube/time_util.rb:292:18: Layout/CaseIndentation: Indent `when` as deep as `end`.
  lib/ice_cube/time_util.rb:293:18: Layout/CaseIndentation: Indent `when` as deep as `end`.
  lib/ice_cube/time_util.rb:294:18: Layout/CaseIndentation: Indent `when` as deep as `end`.

Cheers!

epologee avatar May 03 '22 11:05 epologee

I think once you get your first PR through, you don't need approval for future PR test runs.

pacso avatar May 03 '22 14:05 pacso

would you like me to add a commit to fix that indentation?

Update: I added a commit because the standardrb lint prevents the other tests from running.

epologee avatar May 05 '22 08:05 epologee

Hi - any chance this will be merged ?

suzumejakku avatar May 20 '22 16:05 suzumejakku

We are running this PR in production now, would be great to get this in master.

jankeesvw avatar Jun 01 '22 14:06 jankeesvw

Can you resolve the failing tests? I'll then do a full review and merge it 👍🏻

Although ... these might be tests that I've broken by reverting another branch 🤔 If so ... I'll hopefully sort it soon, and release everything together.

pacso avatar Jun 01 '22 20:06 pacso

Hi @pacso, Did you have any chance to review this ?

suzumejakku avatar Jul 28 '22 16:07 suzumejakku

Hi @pacso Sorry to insist, but is there any way to make it into production ?

suzumejakku avatar Oct 04 '22 08:10 suzumejakku

Hi @seejohnrun @avit @pacso

I'm wondering... are any of you still maintaining this repo?

frsantos avatar Jul 06 '23 14:07 frsantos

Yes, we are. However I sadly don't have time to resolve the issues on this branch. If you can push changes to fix the failing tests, I'll happily merge it.

pacso avatar Jul 08 '23 06:07 pacso

I pushed a minor edit to re-run the specs. I recall that the failures looked like they weren't created by the changes in this PR, but can have another look after the workflow is approved.

CleanShot 2023-07-18 at 12 50 48@2x

epologee avatar Jul 18 '23 10:07 epologee