1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
$:.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
|