Parent

Methods

Files

Class/Module Index [+]

Quicksearch

TZInfo::Data::TZDataParser

Parses Time Zone Data from the IANA Time Zone Database and transforms it into a set of Ruby modules that can be used with TZInfo.

Normally, this class wouldn't be used. It is only run to update the timezone data and index modules.

Constants

DEFAULT_FUTURE_YEARS

Default number of future years data to generate (not including the current year).

DEFAULT_MIN_YEAR

Default earliest year that will be considered.

Attributes

exclude_zones[RW]

Zones to exclude from generation when not using only_zones (set to an array containing zone identifiers).

generate_countries[RW]

Whether to generate country definitions (set to false to stop countries being generated).

generate_zones[RW]

Whether to generate zone definitions (set to false to stop zones being generated).

max_year[RW]

Latest year that will be considered. Defaults to the current year plus FUTURE_YEARS.

min_year[RW]

Earliest year that will be considered. Defaults to DEFAULT_MIN_YEAR.

only_zones[RW]

Limit the set of zones to generate (set to an array containing zone identifiers).

Public Class Methods

new(input_dir, output_dir) click to toggle source

Initializes a new TZDataParser. input_dir must contain the extracted tzdata tarball. output_dir is the location to output the modules (in definitions and indexes directories).

# File lib/tzinfo/data/tzdataparser.rb, line 128
def initialize(input_dir, output_dir)
  super()
  @input_dir = input_dir
  @output_dir = output_dir
  @min_year = DEFAULT_MIN_YEAR
  @max_year = Time.now.year + DEFAULT_FUTURE_YEARS
  @rule_sets = {}
  @zones = {}
  @countries = {}
  @no_rules = TZDataNoRules.new
  @generate_zones = true
  @generate_countries = true
  @only_zones = []
  @exclude_zones = []
end

Public Instance Methods

execute() click to toggle source

Reads the tzdata source and generates the classes. Progress information is written to standard out.

# File lib/tzinfo/data/tzdataparser.rb, line 146
def execute
  # Note that the backzone file is ignored. backzone contains alternative
  # definitions of certain zones, primarily for pre-1970 data. It is not
  # recommended for ordinary use and the tzdata Makefile does not
  # install its entries by default.

  files = Dir.entries(@input_dir).select do |file|
    file =~ /\A[^\.]+\z/ &&            
      !%(backzone checktab.awk leapseconds leapseconds.awk leap-seconds.list CONTRIBUTING Makefile NEWS README SOURCE Theory zoneinfo2tdf.pl).include?(file) &&
      File.file?(File.join(@input_dir, file))
  end

  files.each {|file| load_rules(file) }
  files.each {|file| load_zones(file) }
  files.each {|file| load_links(file) }
  
  load_countries
  
  if @generate_zones
    modules = []
    
    if @only_zones.nil? || @only_zones.empty?
      @zones.each_value {|zone|
        zone.write_module(@output_dir) unless @exclude_zones.include?(zone.name)
      }
    else
      @only_zones.each {|id|
        zone = @zones[id]
        zone.write_module(@output_dir)            
      }          
    end
    
    write_timezones_index
  end
  
  if @generate_countries        
    write_countries_index
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.