Sha256: afebd8e25ec63e2217315a310ae339d406aa398a8941bc6b68e8e20d25bcde8e

Contents?: true

Size: 671 Bytes

Versions: 1

Compression:

Stored size: 671 Bytes

Contents

module Timezone
  @@rules = {}
  def self.rules ; @@rules ; end

  Rule = Struct.new(:name, :from, :to, :type, :month, :day, :time, :save, :letter) do
    def initialize(name, *args)
      super.tap do |rule|
        Timezone.rules[name] ||= []
        Timezone.rules[name] << self
      end
    end

    # Converts hours and minutes to seconds.
    #
    # Example: 1:00 # => 3600
    def offset
      @offset ||= save
        .split(':')
        .reverse
        .each_with_index
        .map{ |number,index| number.to_i*(60**(index+1)) }
        .reduce(&:+)
    end

    # Does this rule have daylight savings time?
    def dst?
      letter == 'D'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timezone-0.2.1 lib/timezone/rule.rb