rubyredrick / ri_cal

Home | Edit | New

Why doesn't RiCal use the zone from Ruby times?

In Rails 2.2, the ActiveSupport gem added a TimeWithZone class which acts like a ruby Time or DateTIme but knows its time zone.

RiCal detects when a TimeWithZone is used as the value of a property like DTSTART or DTEND, and uses the time zone.

Normal Ruby Time and DateTime instances have a zone method, which you might think could be used in a similar way.

Unfortunately, the value returned by Time#zone or DateTime#zone is useless,
it’s really neither a time zone nor a time zone identifier.
It at best represents a potentially ambiguous time zone period, and at
worst just a shift from UTC time.

A time zone identifier represents a legislated time zone with defined
transitions between standard and daylight saving times.

$ irb
irb(main):001:0> Time.now.zone
=> “EDT
irb(main):002:0> require ‘date’
=> true
irb(main):004:0> DateTime.now.zone
=> “-04:00”

Now it might seem that “EDT” might be used to map to a timezone
idenfifier by searching all known TZInfo::Timezones for a period with
that name, but I’m pretty sure that in general a short time zone name
within a particular period is not unique, for a made up example, EDT
might mean either Eastern Daylight time or Estonian Daylight time.

irb(main):004:0> DateTime.now.zone
=> “-04:00”

This is even more useless since there are several time zones (even at
a particular time) which have a shift of -4 hours from UTC.

Last edited by rubyredrick, Tue May 05 13:58:08 -0700 2009
Home | Edit | New
Versions: