[TZInfo-users] using TZInfo to generate iCalendar VTIMEZONE

Philip Ross phil.ross at gmail.com
Tue Jan 9 09:23:20 EST 2007

On 09/01/07, Brandon Keepers <brandon at opensoul.org> wrote:
> I'm working on a CalDAV client for Ruby, and part of the icalendar
> specification requires that you define any timezones that you you
> use.  From what I've gathered, this timezone definition should
> include all the rules for dates in the icalendar file.  So, if I have
> dates spanning from Jan 2006 - June 2007, then I would need to
> include 4 rules, the old standard and daylight times, and the new
> standard and daylight times.

You might be interested in a C program called Vzic
This program takes the source data from
http://www.twinsun.com/tz/tz-link.htm (that TZInfo also uses) and
produces a set of iCalendar VTIMEZONE files.

> If possible, I would like to use TZInfo to get this information.
>  From what I can tell, this data is available in TZInfo, but it is
> not accessible through the API.  Could someone give me some pointers
> on how to get all "active" timezone periods for a given date
> (standard & daylight), and all timezone periods for a given date range?

There will only be one timezone period active for any UTC datetime.
There can be zero or more active for a local datetime.  The methods
Timezone#period_for_utc and Timezone#periods_for_local can be used to
obtain TimezonePeriods for a given time. You could then use the
TimezonePeriod#(utc|local)_(start|end) methods to scan forward or back
to find other periods.

When packaging a TZInfo release, the source data is read and converted
(by TZInfo::TZDataParser) into a set of transitions for each zone -
one transition for each time the offset to UTC or zone name changes.
You can access this data, but not through the public interface (so
this may not work in future releases):

module TZInfo
  class DataTimezoneInfo
    attr_reader :transitions

tz = TZInfo::Timezone.get('Europe/London')
transitions = tz.send(:info).transitions

transitions will be an array of TimezoneTransitionInfo classes.  See
the source for timezone_transition_info.rb
to see the available methods.

This will only work on 'data' timezones
(tz.kind_of?(TZInfo::DataTimezone)).  Many of the zones are 'linked'
(essentially symbolic links to other zones).  You can find the linked
to timezone by adding a attr_reader to the LinkedTimezone class:

module TZInfo
  class LinkedTimezone
    attr_reader :linked_timezone

tz = TZInfo::Timezone.get('GB-Eire').linked_timezone
transitions = tz.send(:info).transitions

I hope this has been of some help to you. Please let me know if you
have any further questions.

Phil Ross
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby

More information about the TZInfo-users mailing list