-
Notifications
You must be signed in to change notification settings - Fork 359
Add timezone parsing / serializing #455
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
base: full_tz
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,8 @@ | |
|
||
# rspec failure tracking | ||
.rspec_status | ||
|
||
# Vagrant files | ||
Vagrantfile | ||
.vagrant | ||
ubuntu* | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,11 +37,13 @@ def self.ical_utc_format(time) | |
|
||
def self.ical_format(time, force_utc) | ||
time = time.dup.utc if force_utc | ||
|
||
if time.utc? | ||
":#{IceCube::I18n.l(time, format: '%Y%m%dT%H%M%SZ')}" # utc time | ||
elsif time.respond_to?(:time_zone) | ||
";TZID=#{time.time_zone.name}:#{IceCube::I18n.l(time, format: '%Y%m%dT%H%M%S')}" # time zone specified | ||
else | ||
time_zone = time.respond_to?(:time_zone) ? time.time_zone.name : time.zone | ||
";TZID=#{time_zone}:#{IceCube::I18n.l(time, format: '%Y%m%dT%H%M%S')}" # local time specified | ||
":#{IceCube::I18n.l(time, format: '%Y%m%dT%H%M%S')}" # local time specified | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As shown in the spec, dates in local / floating time should be serialized in the form While I don't think |
||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,19 @@ def self.schedule_from_ical(ical_string, options = {}) | |
ical_string.each_line do |line| | ||
(property, value) = line.split(':') | ||
(property, tzid) = property.split(';') | ||
(_, time_zone) = tzid.split('=') if tzid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this won't always work - looking at the spec, a component may have many parameters, of the form For example, this is a valid ical line: Another example would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @iainbeeston you're correct. This might fix it: (property, *params) = property.split(';')
params.map! { |p| p.split('=') }
time_zone = params.select { |p| p&.first&.upcase == "TZID" }.first&.last
value_type = params.select { |p| p&.first&.upcase == "VALUE" }.first&.last
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this still needs to be resolved? |
||
|
||
case property | ||
when 'DTSTART' | ||
data[:start_time] = TimeUtil.deserialize_time(value) | ||
data[:start_time] = TimeUtil.deserialize_time({time: value, zone: time_zone}) | ||
when 'DTEND' | ||
data[:end_time] = TimeUtil.deserialize_time(value) | ||
data[:end_time] = TimeUtil.deserialize_time({time: value, zone: time_zone}) | ||
when 'RDATE' | ||
data[:rtimes] ||= [] | ||
data[:rtimes] += value.split(',').map { |v| TimeUtil.deserialize_time(v) } | ||
data[:rtimes] += value.split(',').map { |v| TimeUtil.deserialize_time({time: v, zone: time_zone}) } | ||
when 'EXDATE' | ||
data[:extimes] ||= [] | ||
data[:extimes] += value.split(',').map { |v| TimeUtil.deserialize_time(v) } | ||
data[:extimes] += value.split(',').map { |v| TimeUtil.deserialize_time({time: v, zone: time_zone}) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the Also, while the |
||
when 'DURATION' | ||
data[:duration] # FIXME | ||
when 'RRULE' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,10 +109,10 @@ def self.deserialize_time(time_or_hash) | |
when Time, Date | ||
time_or_hash | ||
when DateTime | ||
Time.local(time.year, time.month, time.day, time.hour, time.min, time.sec) | ||
Time.local(time_or_hash.year, time_or_hash.month, time_or_hash.day, time_or_hash.hour, time_or_hash.min, time_or_hash.sec) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I think that this was a bug. Not sure when, if ever, the I think this was a copy-paste error from the |
||
when Hash | ||
hash = FlexibleHash.new(time_or_hash) | ||
hash[:time].in_time_zone(hash[:zone]) | ||
hash[:zone] ? hash[:time].in_time_zone(hash[:zone]) : hash[:time] | ||
when String | ||
Time.parse(time_or_hash) | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,7 +201,7 @@ | |
it 'should default to to_ical using local time' do | ||
time = Time.now | ||
schedule = IceCube::Schedule.new(Time.now) | ||
expect(schedule.to_ical).to eq("DTSTART;TZID=#{time.zone}:#{time.strftime('%Y%m%dT%H%M%S')}") # default false | ||
expect(schedule.to_ical).to eq("DTSTART:#{time.strftime('%Y%m%dT%H%M%S')}") # default false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would argue that this test's expectation was just plain incorrect before. As stated, it is testing to ensure a date is serialized in local time (i.e. without a TZID), but before the test expected a string with TZID. |
||
end | ||
|
||
it 'should not have an rtime that duplicates start time' do | ||
|
@@ -214,8 +214,8 @@ | |
it 'should be able to receive a to_ical in utc time' do | ||
time = Time.now | ||
schedule = IceCube::Schedule.new(Time.now) | ||
expect(schedule.to_ical).to eq("DTSTART;TZID=#{time.zone}:#{time.strftime('%Y%m%dT%H%M%S')}") # default false | ||
expect(schedule.to_ical(false)).to eq("DTSTART;TZID=#{time.zone}:#{time.strftime('%Y%m%dT%H%M%S')}") | ||
expect(schedule.to_ical).to eq("DTSTART:#{time.strftime('%Y%m%dT%H%M%S')}") # default false | ||
expect(schedule.to_ical(false)).to eq("DTSTART:#{time.strftime('%Y%m%dT%H%M%S')}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the above, this spec was updated to expect local times to be serialized as local times. |
||
expect(schedule.to_ical(true)).to eq("DTSTART:#{time.utc.strftime('%Y%m%dT%H%M%S')}Z") | ||
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.
I don't think we need these?