Sha256: dce12227b7af6af4366bb6979919068551c816fb77c9641fee54798134408744

Contents?: true

Size: 1.85 KB

Versions: 21

Compression:

Stored size: 1.85 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
require 'test/unit'
require 'tzinfo/data_timezone'
require 'tzinfo/timezone_info'

include TZInfo

class TCDataTimezone < Test::Unit::TestCase
  
  class TestTimezoneInfo < TimezoneInfo
    attr_reader :utc
    attr_reader :local
    
    def initialize(identifier, utc_period, local_periods)
      super(identifier)
      @utc_period = utc_period
      @local_periods = local_periods || []
    end
    
    def period_for_utc(utc)
      @utc = utc
      @utc_period     
    end
    
    def periods_for_local(local)
      @local = local      
      @local_periods
    end
  end    

  def test_identifier
    tz = DataTimezone.new(TestTimezoneInfo.new('Test/Zone', nil, []))
    assert_equal('Test/Zone', tz.identifier)
  end
  
  def test_period_for_utc
    # Don't need actual TimezonePeriods. DataTimezone isn't supposed to do
    # anything with them apart from return them.
    period = Object.new 
    tti = TestTimezoneInfo.new('Test/Zone', period, [])
    tz = DataTimezone.new(tti)
    
    t = Time.utc(2006, 6, 27, 22, 50, 12)
    assert_same(period, tz.period_for_utc(t))
    assert_same(t, tti.utc)    
  end
  
  def test_periods_for_local
    # Don't need actual TimezonePeriods. DataTimezone isn't supposed to do
    # anything with them apart from return them.
    periods = [Object.new, Object.new] 
    tti = TestTimezoneInfo.new('Test/Zone', nil, periods)
    tz = DataTimezone.new(tti)
    
    t = Time.utc(2006, 6, 27, 22, 50, 12)
    assert_same(periods, tz.periods_for_local(t))
    assert_same(t, tti.local)  
  end
  
  def test_periods_for_local_not_found
    periods = []
    tti = TestTimezoneInfo.new('Test/Zone', nil, periods)
    tz = DataTimezone.new(tti)
    
    t = Time.utc(2006, 6, 27, 22, 50, 12)
    assert_same(periods, tz.periods_for_local(t))
    assert_same(t, tti.local)
  end    
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
tzinfo-0.3.20 test/tc_data_timezone.rb
tzinfo-0.3.19 test/tc_data_timezone.rb
tzinfo-0.3.18 test/tc_data_timezone.rb
tzinfo-0.3.17 test/tc_data_timezone.rb
tzinfo-0.3.16 test/tc_data_timezone.rb
tzinfo-0.3.15 test/tc_data_timezone.rb
tzinfo-0.3.14 test/tc_data_timezone.rb
tzinfo-0.3.0 test/tc_data_timezone.rb
tzinfo-0.3.1 test/tc_data_timezone.rb
tzinfo-0.3.10 test/tc_data_timezone.rb
tzinfo-0.3.11 test/tc_data_timezone.rb
tzinfo-0.3.12 test/tc_data_timezone.rb
tzinfo-0.3.13 test/tc_data_timezone.rb
tzinfo-0.3.2 test/tc_data_timezone.rb
tzinfo-0.3.3 test/tc_data_timezone.rb
tzinfo-0.3.4 test/tc_data_timezone.rb
tzinfo-0.3.5 test/tc_data_timezone.rb
tzinfo-0.3.6 test/tc_data_timezone.rb
tzinfo-0.3.7 test/tc_data_timezone.rb
tzinfo-0.3.8 test/tc_data_timezone.rb