-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Time zone support in schedule_from_ical
#526
base: master
Are you sure you want to change the base?
Conversation
7409e6f
to
b2e0af3
Compare
@@ -4,18 +4,27 @@ def self.schedule_from_ical(ical_string, options = {}) | |||
data = {} | |||
ical_string.each_line do |line| | |||
(property, value) = line.split(":") | |||
(property, _tzid) = property.split(";") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This _tzid
contained the ignored time zone information.
b2e0af3
to
14da4a5
Compare
lib/ice_cube/parsers/ical_parser.rb
Outdated
Time.find_zone!(zone) if zone.present? | ||
rescue ArgumentError | ||
(rails_zone, _tzinfo_id) = ActiveSupport::TimeZone::MAPPING.find do |(k, _)| | ||
Time.find_zone!(k).now.strftime("%Z") == zone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where time zone identifiers like "MDT"
are matched with Rails time zones, using strftime
.
it "round trips from and to ical with time zones in the summer (MDT)" do | ||
original = <<-ICAL.gsub(/^\s*/, "").strip | ||
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 | ||
ICAL | ||
|
||
schedule_from_ical = IceCube::Schedule.from_ical original | ||
expect(schedule_from_ical.to_ical).to eq original | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may seem like a superfluous test compared to the one below, but before the last commit on this branch, this test would have failed when run during the winter (standard time vs. daylight saving time period).
I tested this using Timecop locally, but I didn't want to add a dependency to your repository just for this PR, so I didn't commit that part.
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? |
b4cd303
to
ab6265b
Compare
Co-authored-by: Jankees van Woezik <[email protected]>
Co-authored-by: Jankees van Woezik <[email protected]>
ab6265b
to
9b2faeb
Compare
Co-authored-by: Jankees van Woezik <[email protected]>
Co-authored-by: Jankees van Woezik <[email protected]>
Using `.now` causes a search for "MST" in the winter, even if the time of the given schedule is in summer and would only match "MDT". By parsing the time value and using the components as values in the candidate time zone, this issue is fixed.
9b2faeb
to
c3a7ede
Compare
Hi, thanks, will do / already done!
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! |
I think once you get your first PR through, you don't need approval for future PR test runs. |
Update: I added a commit because the standardrb lint prevents the other tests from running. |
Hi - any chance this will be merged ? |
We are running this PR in production now, would be great to get this in master. |
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. |
Hi @pacso, |
Hi @pacso |
I'm wondering... are any of you still maintaining this repo? |
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. |
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
Output schedule on master
Output schedule on this branch
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.