Sha256: 94273ee838eda92d11888a7c3258daf63b5668a8f8b59514bad135d25c23f40a

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'timezone/parser/zone'
require 'timezone/parser/zone/until'
require 'timezone/parser/rule'
require 'time'

# The data object that represents a zone entry in the TZData file.
# Tests for this class are contained in the parser/zone_test.rb file.
module Timezone::Parser::Zone
  class Entry
    attr_reader :name, :format, :offset, :end_date, :rules

    def initialize(name, offset, rule, format, end_date)
      @name, @format = name, format

      @end_date = parse_end_date(end_date)
      @offset   = parse_offset(offset)
      @rules    = parse_rules(rule, @end_date)
    end

    private

    # Only select rules that fall within the timeline of this entry.
    # Then apply the rule to this entry so that the offset is accurate.
    def parse_rules(name, end_date)
      Timezone::Parser.select_rules(name, end_date).sort_by(&:start_date)
    end

    # Use the UNTIL parser to decode the end date.
    def parse_end_date(end_date)
      Until.parse(end_date)
    end

    # The offset is calculated in minutes.
    def parse_offset(offset)
      offset = Time.parse(offset)
      offset.hour*60*60 + offset.min*60 + offset.sec
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
timezone-0.3.2 lib/timezone/parser/zone/entry.rb
timezone-0.3.1 lib/timezone/parser/zone/entry.rb
timezone-0.3.0 lib/timezone/parser/zone/entry.rb