Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing correct offsets for to_local #52

Merged
merged 9 commits into from Sep 19, 2016
29 changes: 26 additions & 3 deletions lib/tzinfo/time_or_datetime.rb
Expand Up @@ -11,7 +11,7 @@ class TimeOrDateTime
# Constructs a new TimeOrDateTime. timeOrDateTime can be a Time, DateTime
# or Integer. If using a Time or DateTime, any time zone information
# is ignored.
def initialize(timeOrDateTime)
def initialize(timeOrDateTime, ignore_offset = true)
@time = nil
@datetime = nil
@timestamp = nil
Expand All @@ -23,11 +23,11 @@ def initialize(timeOrDateTime)
nsec = @time.nsec
usec = nsec % 1000 == 0 ? nsec / 1000 : Rational(nsec, 1000)

@time = Time.utc(@time.year, @time.mon, @time.mday, @time.hour, @time.min, @time.sec, usec) unless @time.utc?
@time = Time.utc(@time.year, @time.mon, @time.mday, @time.hour, @time.min, @time.sec, usec) unless @time.utc? || !ignore_offset
@orig = @time
elsif timeOrDateTime.is_a?(DateTime)
@datetime = timeOrDateTime
@datetime = @datetime.new_offset(0) unless @datetime.offset == 0
@datetime = @datetime.new_offset(0) unless @datetime.offset == 0 || !ignore_offset
@orig = @datetime
else
@timestamp = timeOrDateTime.to_i
Expand Down Expand Up @@ -255,6 +255,29 @@ def -(seconds)
self + (-seconds)
end

# Sets offset from UTC for the TimeOrDateTime. Returns a new TimeOrDateTime,
# preserving original class. Does NOT changes values of hour-min-second,
# so, (18:00 UTC).offset(3600) will became (18:00 +01:00).
# Considers original value's UTC offset wisely.
def offset(seconds)
Copy link
Member

@philr philr May 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to produce a different result depending on whether DateTime or Time is used to initialize the TimeOrDateTime:

TZInfo::TimeOrDateTime.new(Time.new(2016,5,30,18,0,0,'+01:00'), false).offset(3600)
 => #<TZInfo::TimeOrDateTime: 2016-05-30 19:00:00 +0100> 
TZInfo::TimeOrDateTime.new(DateTime.new(2016,5,30,18,0,0,'+01:00'), false).offset(3600)
 => #<TZInfo::TimeOrDateTime: #<DateTime: 2016-05-30T18:00:00+01:00 ((2457539j,61200s,0n),+3600s,2299161j)>>

return self if seconds == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the TimeOrDateTime represents a Time or DateTime with an offset, then shouldn't calling offset(0) change the offset to 0 instead of leaving it unchanged?


if @orig.is_a?(DateTime)
off = OffsetRationals.rational_for_offset(seconds)
TimeOrDateTime.new(@orig.new_offset(off), false)
elsif @orig.is_a?(Time)
offset_str = '%+03i:%02i' % [seconds / 3600, seconds / 60 % 60]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the Time constructor can take either a String or an Integer number of seconds as the offset. Would it be better to avoid the conversion to a String?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right. Didn't find this on time, will change.


time = @time + seconds
nsec_part = Rational(time.nsec, 1_000_000_000)
time = Time.new(time.year, time.mon, time.mday, time.hour, time.min, time.sec + nsec_part, offset_str)
TimeOrDateTime.new(time, false)
else
# Integer: fallback to "just shift timestamp"
TimeOrDateTime.new(@orig + seconds)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaves slightly differently to the Time and DateTime cases, which feels a bit suspect to me.

end
end

# Returns true if todt represents the same time and was originally
# constructed with the same type (DateTime, Time or timestamp) as this
# TimeOrDateTime.
Expand Down
6 changes: 6 additions & 0 deletions lib/tzinfo/timezone.rb
Expand Up @@ -428,6 +428,12 @@ def utc_to_local(utc)
}
end

def to_local(date_or_time)
TimeOrDateTime.wrap(date_or_time, false) {|wrapped|
period_for(wrapped).to_local(wrapped)
}
end

# Converts a time in the local timezone to UTC. local can either be
# a DateTime, Time or timestamp (Time.to_i). The returned time has the same
# type as local. Any timezone information in local is ignored (it is treated
Expand Down
3 changes: 2 additions & 1 deletion lib/tzinfo/timezone_offset.rb
Expand Up @@ -36,7 +36,8 @@ def dst?
# the offset of this period.
def to_local(utc)
TimeOrDateTime.wrap(utc) {|wrapped|
wrapped + @utc_total_offset
#wrapped + @utc_total_offset
wrapped.offset(@utc_total_offset)
}
end

Expand Down
30 changes: 30 additions & 0 deletions test/tc_time_or_datetime.rb
Expand Up @@ -18,6 +18,15 @@ def test_initialize_time_local
assert(tdt.to_orig.utc?)
end

def test_initialize_time_local_preserve_offset
t = Time.new(2006, 3, 24, 15, 32, 3, '+03:00')
tdt = TimeOrDateTime.new(t, false)
assert_equal(t, tdt.to_time)
assert_equal(t, tdt.to_orig)
assert(!tdt.to_time.utc?)
assert(!tdt.to_orig.utc?)
end

def test_intialize_time_local_usec
tdt = TimeOrDateTime.new(Time.local(2006, 3, 24, 15, 32, 3, 721123))
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721123), tdt.to_time)
Expand Down Expand Up @@ -482,6 +491,27 @@ def test_subtract
assert_equal(1143214324, (TimeOrDateTime.new(1143214323) - (-1)).to_orig)
end

def test_offset
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).offset(0)).to_orig)
assert_equal(Time.utc(2006, 3, 24, 15, 32, 3, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).offset(0)).to_orig)
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).offset(0)).to_orig)
assert_equal(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).offset(0)).to_orig)
assert_equal(1143214323, (TimeOrDateTime.new(1143214323).offset(0)).to_orig)

assert_equal(Time.new(2006, 3, 24, 18, 32, 3, '+03:00'), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)).offset(3600*3)).to_orig)
assert_equal(Time.new(2006, 3, 24, 18, 32, 3 + Rational(721, 1000), '+03:00'), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)).offset(3600*3)).to_orig)
assert_equal(DateTime.new(2006, 3, 24, 18, 32, 3, '+3'), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)).offset(3600*3)).to_orig)
assert_equal(DateTime.new(2006, 3, 24, 18, 32, 3 + Rational(721, 1000), '+3'), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))).offset(3600*3)).to_orig)
#assert_equal(1143214322, (TimeOrDateTime.new(1143214323).offset(3600*3)).to_orig)
#assert_equal(Time.utc(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3)) - (-1)).to_orig)
#assert_equal(Time.utc(2006, 3, 24, 15, 32, 4, 721000), (TimeOrDateTime.new(Time.utc(2006, 3, 24, 15, 32, 3, 721000)) - (-1)).to_orig)
#assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3)) - (-1)).to_orig)
#assert_equal(DateTime.new(2006, 3, 24, 15, 32, 4 + Rational(721, 1000)), (TimeOrDateTime.new(DateTime.new(2006, 3, 24, 15, 32, 3 + Rational(721, 1000))) - (-1)).to_orig)
#assert_equal(1143214324, (TimeOrDateTime.new(1143214323) - (-1)).to_orig)

# TODO: check what to do if orig is not UTC
end

def test_wrap_time
t = TimeOrDateTime.wrap(Time.utc(2006, 3, 24, 15, 32, 3))
assert_instance_of(TimeOrDateTime, t)
Expand Down
40 changes: 20 additions & 20 deletions test/tc_timezone.rb
Expand Up @@ -724,14 +724,14 @@ def test_utc_to_local
TestTimezoneTransition.new(o2, o1, 1111885200),
TestTimezoneTransition.new(o1, o2, 1130634000))

assert_equal(DateTime.new(2005,6,18,17,24,23), TestTimezone.new('Europe/London', period, [], dt).utc_to_local(dt))
assert_equal(DateTime.new(2005,6,18,17,24,23), TestTimezone.new('Europe/London', period, [], dt2).utc_to_local(dt2))
assert_equal(DateTime.new(2005,6,18,17,24,23 + Rational(567,1000)), TestTimezone.new('Europe/London', period, [], dtu).utc_to_local(dtu))
assert_equal(DateTime.new(2005,6,18,17,24,23 + Rational(567,1000)), TestTimezone.new('Europe/London', period, [], dtu2).utc_to_local(dtu2))
assert_equal(Time.utc(2005,6,18,17,24,23), TestTimezone.new('Europe/London', period, [], t).utc_to_local(t))
assert_equal(Time.utc(2005,6,18,17,24,23), TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2))
assert_equal(Time.utc(2005,6,18,17,24,23,567000), TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu))
assert_equal(Time.utc(2005,6,18,17,24,23,567000), TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2))
assert_equal(DateTime.new(2005,6,18,17,24,23,'+1'), TestTimezone.new('Europe/London', period, [], dt).utc_to_local(dt))
assert_equal(DateTime.new(2005,6,18,17,24,23,'+1'), TestTimezone.new('Europe/London', period, [], dt2).utc_to_local(dt2))
assert_equal(DateTime.new(2005,6,18,17,24,23 + Rational(567,1000),'+1'), TestTimezone.new('Europe/London', period, [], dtu).utc_to_local(dtu))
assert_equal(DateTime.new(2005,6,18,17,24,23 + Rational(567,1000),'+1'), TestTimezone.new('Europe/London', period, [], dtu2).utc_to_local(dtu2))
assert_equal(Time.new(2005,6,18,17,24,23,'+01:00'), TestTimezone.new('Europe/London', period, [], t).utc_to_local(t))
assert_equal(Time.new(2005,6,18,17,24,23,'+01:00'), TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2))
assert_equal(Time.new(2005,6,18,17,24,23+Rational(567,1000), '+01:00'), TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu))
assert_equal(Time.new(2005,6,18,17,24,23+Rational(567,1000), '+01:00'), TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2))
assert_equal(Time.utc(2005,6,18,17,24,23).to_i, TestTimezone.new('Europe/London', period, [], ts).utc_to_local(ts))
end

Expand All @@ -752,18 +752,18 @@ def test_utc_to_local_offset
TestTimezoneTransition.new(o2, o1, 1111885200),
TestTimezoneTransition.new(o1, o2, 1130634000))

assert_equal(0, TestTimezone.new('Europe/London', period, [], dt).utc_to_local(dt).offset)
assert_equal(0, TestTimezone.new('Europe/London', period, [], dt2).utc_to_local(dt2).offset)
assert_equal(0, TestTimezone.new('Europe/London', period, [], dtu).utc_to_local(dtu).offset)
assert_equal(0, TestTimezone.new('Europe/London', period, [], dtu2).utc_to_local(dtu2).offset)
assert_equal(0, TestTimezone.new('Europe/London', period, [], t).utc_to_local(t).utc_offset)
assert(TestTimezone.new('Europe/London', period, [], t).utc_to_local(t).utc?)
assert_equal(0, TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2).utc_offset)
assert(TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2).utc?)
assert_equal(0, TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu).utc_offset)
assert(TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu).utc?)
assert_equal(0, TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2).utc_offset)
assert(TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2).utc?)
assert_equal(1/24r, TestTimezone.new('Europe/London', period, [], dt).utc_to_local(dt).offset)
assert_equal(1/24r, TestTimezone.new('Europe/London', period, [], dt2).utc_to_local(dt2).offset)
assert_equal(1/24r, TestTimezone.new('Europe/London', period, [], dtu).utc_to_local(dtu).offset)
assert_equal(1/24r, TestTimezone.new('Europe/London', period, [], dtu2).utc_to_local(dtu2).offset)
assert_equal(3600, TestTimezone.new('Europe/London', period, [], t).utc_to_local(t).utc_offset)
assert(!TestTimezone.new('Europe/London', period, [], t).utc_to_local(t).utc?)
assert_equal(3600, TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2).utc_offset)
assert(!TestTimezone.new('Europe/London', period, [], t2).utc_to_local(t2).utc?)
assert_equal(3600, TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu).utc_offset)
assert(!TestTimezone.new('Europe/London', period, [], tu).utc_to_local(tu).utc?)
assert_equal(3600, TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2).utc_offset)
assert(!TestTimezone.new('Europe/London', period, [], tu2).utc_to_local(tu2).utc?)
end

def test_local_to_utc
Expand Down
12 changes: 6 additions & 6 deletions test/tc_timezone_london.rb
Expand Up @@ -11,8 +11,8 @@ def test_2004

tz = Timezone.get('Europe/London')
assert_equal(DateTime.new(2004,3,28,0,59,59), tz.utc_to_local(DateTime.new(2004,3,28,0,59,59)))
assert_equal(DateTime.new(2004,3,28,2,0,0), tz.utc_to_local(DateTime.new(2004,3,28,1,0,0)))
assert_equal(DateTime.new(2004,10,31,1,59,59), tz.utc_to_local(DateTime.new(2004,10,31,0,59,59)))
assert_equal(DateTime.new(2004,3,28,2,0,0,'+1'), tz.utc_to_local(DateTime.new(2004,3,28,1,0,0)))
assert_equal(DateTime.new(2004,10,31,1,59,59,'+1'), tz.utc_to_local(DateTime.new(2004,10,31,0,59,59)))
assert_equal(DateTime.new(2004,10,31,1,0,0), tz.utc_to_local(DateTime.new(2004,10,31,1,0,0)))

assert_equal(DateTime.new(2004,3,28,0,59,59), tz.local_to_utc(DateTime.new(2004,3,28,0,59,59)))
Expand Down Expand Up @@ -70,8 +70,8 @@ def test_1961

tz = Timezone.get('Europe/London')
assert_equal(DateTime.new(1961,3,26,1,59,59), tz.utc_to_local(DateTime.new(1961,3,26,1,59,59)))
assert_equal(DateTime.new(1961,3,26,3,0,0), tz.utc_to_local(DateTime.new(1961,3,26,2,0,0)))
assert_equal(DateTime.new(1961,10,29,2,59,59), tz.utc_to_local(DateTime.new(1961,10,29,1,59,59)))
assert_equal(DateTime.new(1961,3,26,3,0,0,'+1'), tz.utc_to_local(DateTime.new(1961,3,26,2,0,0)))
assert_equal(DateTime.new(1961,10,29,2,59,59,'+1'), tz.utc_to_local(DateTime.new(1961,10,29,1,59,59)))
assert_equal(DateTime.new(1961,10,29,2,0,0), tz.utc_to_local(DateTime.new(1961,10,29,2,0,0)))

assert_equal(DateTime.new(1961,3,26,1,59,59), tz.local_to_utc(DateTime.new(1961,3,26,1,59,59)))
Expand Down Expand Up @@ -127,9 +127,9 @@ def test_time_boundary
#Europe/London Sun Oct 31 01:59:59 1971 UTC = Sun Oct 31 02:59:59 1971 GMT isdst=0 gmtoff=3600

tz = Timezone.get('Europe/London')
assert_equal(DateTime.new(1970,1,1,1,0,0), tz.utc_to_local(DateTime.new(1970,1,1,0,0,0)))
assert_equal(DateTime.new(1970,1,1,1,0,0,'+1'), tz.utc_to_local(DateTime.new(1970,1,1,0,0,0)))
assert_equal(DateTime.new(1970,1,1,0,0,0), tz.local_to_utc(DateTime.new(1970,1,1,1,0,0)))
assert_equal(Time.utc(1970,1,1,1,0,0), tz.utc_to_local(Time.utc(1970,1,1,0,0,0)))
assert_equal(Time.new(1970,1,1,1,0,0,'+01:00'), tz.utc_to_local(Time.utc(1970,1,1,0,0,0)))
assert_equal(Time.utc(1970,1,1,0,0,0), tz.local_to_utc(Time.utc(1970,1,1,1,0,0)))
assert_equal(3600, tz.utc_to_local(0))
assert_equal(0, tz.local_to_utc(3600))
Expand Down
20 changes: 10 additions & 10 deletions test/tc_timezone_melbourne.rb
Expand Up @@ -10,10 +10,10 @@ def test_2004
#Australia/Melbourne Sat Oct 30 16:00:00 2004 UTC = Sun Oct 31 03:00:00 2004 AEDT isdst=1 gmtoff=39600

tz = Timezone.get('Australia/Melbourne')
assert_equal(DateTime.new(2004,3,28,2,59,59), tz.utc_to_local(DateTime.new(2004,3,27,15,59,59)))
assert_equal(DateTime.new(2004,3,28,2,0,0), tz.utc_to_local(DateTime.new(2004,3,27,16,0,0)))
assert_equal(DateTime.new(2004,10,31,1,59,59), tz.utc_to_local(DateTime.new(2004,10,30,15,59,59)))
assert_equal(DateTime.new(2004,10,31,3,0,0), tz.utc_to_local(DateTime.new(2004,10,30,16,0,0)))
assert_equal(DateTime.new(2004,3,28,2,59,59,'+11'), tz.utc_to_local(DateTime.new(2004,3,27,15,59,59)))
assert_equal(DateTime.new(2004,3,28,2,0,0,'+10'), tz.utc_to_local(DateTime.new(2004,3,27,16,0,0)))
assert_equal(DateTime.new(2004,10,31,1,59,59,'+10'), tz.utc_to_local(DateTime.new(2004,10,30,15,59,59)))
assert_equal(DateTime.new(2004,10,31,3,0,0,'+11'), tz.utc_to_local(DateTime.new(2004,10,30,16,0,0)))

assert_equal(DateTime.new(2004,3,27,15,59,59), tz.local_to_utc(DateTime.new(2004,3,28,2,59,59), true))
assert_equal(DateTime.new(2004,3,27,16,59,59), tz.local_to_utc(DateTime.new(2004,3,28,2,59,59), false))
Expand Down Expand Up @@ -69,10 +69,10 @@ def test_1942
#Australia/Melbourne Sat Sep 26 16:00:00 1942 UTC = Sun Sep 27 03:00:00 1942 AEDT isdst=1 gmtoff=39600

tz = Timezone.get('Australia/Melbourne')
assert_equal(DateTime.new(1942,3,29,1,59,59), tz.utc_to_local(DateTime.new(1942,3,28,14,59,59)))
assert_equal(DateTime.new(1942,3,29,1,0,0), tz.utc_to_local(DateTime.new(1942,3,28,15,0,0)))
assert_equal(DateTime.new(1942,9,27,1,59,59), tz.utc_to_local(DateTime.new(1942,9,26,15,59,59)))
assert_equal(DateTime.new(1942,9,27,3,0,0), tz.utc_to_local(DateTime.new(1942,9,26,16,0,0)))
assert_equal(DateTime.new(1942,3,29,1,59,59,'+11'), tz.utc_to_local(DateTime.new(1942,3,28,14,59,59)))
assert_equal(DateTime.new(1942,3,29,1,0,0,'+10'), tz.utc_to_local(DateTime.new(1942,3,28,15,0,0)))
assert_equal(DateTime.new(1942,9,27,1,59,59,'+10'), tz.utc_to_local(DateTime.new(1942,9,26,15,59,59)))
assert_equal(DateTime.new(1942,9,27,3,0,0,'+11'), tz.utc_to_local(DateTime.new(1942,9,26,16,0,0)))

assert_equal(DateTime.new(1942,3,28,14,59,59), tz.local_to_utc(DateTime.new(1942,3,29,1,59,59), true))
assert_equal(DateTime.new(1942,3,28,15,59,59), tz.local_to_utc(DateTime.new(1942,3,29,1,59,59), false))
Expand Down Expand Up @@ -126,9 +126,9 @@ def test_time_boundary
#Australia/Melbourne Sat Oct 30 15:59:59 1971 UTC = Sun Oct 31 01:59:59 1971 AEST isdst=0 gmtoff=36000

tz = Timezone.get('Australia/Melbourne')
assert_equal(DateTime.new(1970,1,1,10,0,0), tz.utc_to_local(DateTime.new(1970,1,1,0,0,0)))
assert_equal(DateTime.new(1970,1,1,10,0,0,'+10'), tz.utc_to_local(DateTime.new(1970,1,1,0,0,0)))
assert_equal(DateTime.new(1970,1,1,0,0,0), tz.local_to_utc(DateTime.new(1970,1,1,10,0,0)))
assert_equal(Time.utc(1970,1,1,10,0,0), tz.utc_to_local(Time.utc(1970,1,1,0,0,0)))
assert_equal(Time.new(1970,1,1,10,0,0,'+10:00'), tz.utc_to_local(Time.utc(1970,1,1,0,0,0)))
assert_equal(Time.utc(1970,1,1,0,0,0), tz.local_to_utc(Time.utc(1970,1,1,10,0,0)))
assert_equal(36000, tz.utc_to_local(0))
assert_equal(0, tz.local_to_utc(36000))
Expand Down
20 changes: 10 additions & 10 deletions test/tc_timezone_new_york.rb
Expand Up @@ -10,10 +10,10 @@ def test_2004
#America/New_York Sun Oct 31 06:00:00 2004 UTC = Sun Oct 31 01:00:00 2004 EST isdst=0 gmtoff=-18000

tz = Timezone.get('America/New_York')
assert_equal(DateTime.new(2004,4,4,1,59,59), tz.utc_to_local(DateTime.new(2004,4,4,6,59,59)))
assert_equal(DateTime.new(2004,4,4,3,0,0), tz.utc_to_local(DateTime.new(2004,4,4,7,0,0)))
assert_equal(DateTime.new(2004,10,31,1,59,59), tz.utc_to_local(DateTime.new(2004,10,31,5,59,59)))
assert_equal(DateTime.new(2004,10,31,1,0,0), tz.utc_to_local(DateTime.new(2004,10,31,6,0,0)))
assert_equal(DateTime.new(2004,4,4,1,59,59,'-5'), tz.utc_to_local(DateTime.new(2004,4,4,6,59,59)))
assert_equal(DateTime.new(2004,4,4,3,0,0,'-4'), tz.utc_to_local(DateTime.new(2004,4,4,7,0,0)))
assert_equal(DateTime.new(2004,10,31,1,59,59,'-4'), tz.utc_to_local(DateTime.new(2004,10,31,5,59,59)))
assert_equal(DateTime.new(2004,10,31,1,0,0,'-5'), tz.utc_to_local(DateTime.new(2004,10,31,6,0,0)))

assert_equal(DateTime.new(2004,4,4,6,59,59), tz.local_to_utc(DateTime.new(2004,4,4,1,59,59)))
assert_equal(DateTime.new(2004,4,4,7,0,0), tz.local_to_utc(DateTime.new(2004,4,4,3,0,0)))
Expand Down Expand Up @@ -69,10 +69,10 @@ def test_1957
#America/New_York Sun Oct 27 06:00:00 1957 UTC = Sun Oct 27 01:00:00 1957 EST isdst=0 gmtoff=-18000

tz = Timezone.get('America/New_York')
assert_equal(DateTime.new(1957,4,28,1,59,59), tz.utc_to_local(DateTime.new(1957,4,28,6,59,59)))
assert_equal(DateTime.new(1957,4,28,3,0,0), tz.utc_to_local(DateTime.new(1957,4,28,7,0,0)))
assert_equal(DateTime.new(1957,10,27,1,59,59), tz.utc_to_local(DateTime.new(1957,10,27,5,59,59)))
assert_equal(DateTime.new(1957,10,27,1,0,0), tz.utc_to_local(DateTime.new(1957,10,27,6,0,0)))
assert_equal(DateTime.new(1957,4,28,1,59,59,'-5'), tz.utc_to_local(DateTime.new(1957,4,28,6,59,59)))
assert_equal(DateTime.new(1957,4,28,3,0,0,'-4'), tz.utc_to_local(DateTime.new(1957,4,28,7,0,0)))
assert_equal(DateTime.new(1957,10,27,1,59,59,'-4'), tz.utc_to_local(DateTime.new(1957,10,27,5,59,59)))
assert_equal(DateTime.new(1957,10,27,1,0,0,'-5'), tz.utc_to_local(DateTime.new(1957,10,27,6,0,0)))

assert_equal(DateTime.new(1957,4,28,6,59,59), tz.local_to_utc(DateTime.new(1957,4,28,1,59,59)))
assert_equal(DateTime.new(1957,4,28,7,0,0), tz.local_to_utc(DateTime.new(1957,4,28,3,0,0)))
Expand Down Expand Up @@ -126,9 +126,9 @@ def test_time_boundary
#America/New_York Sun Apr 26 06:59:59 1970 UTC = Sun Apr 26 01:59:59 1970 EST isdst=0 gmtoff=-18000

tz = Timezone.get('America/New_York')
assert_equal(DateTime.new(1970,1,1,0,0,0), tz.utc_to_local(DateTime.new(1970,1,1,5,0,0)))
assert_equal(DateTime.new(1970,1,1,0,0,0,'-5'), tz.utc_to_local(DateTime.new(1970,1,1,5,0,0)))
assert_equal(DateTime.new(1970,1,1,5,0,0), tz.local_to_utc(DateTime.new(1970,1,1,0,0,0)))
assert_equal(Time.utc(1970,1,1,0,0,0), tz.utc_to_local(Time.utc(1970,1,1,5,0,0)))
assert_equal(Time.new(1970,1,1,0,0,0,'-05:00'), tz.utc_to_local(Time.utc(1970,1,1,5,0,0)))
assert_equal(Time.utc(1970,1,1,5,0,0), tz.local_to_utc(Time.utc(1970,1,1,0,0,0)))
assert_equal(0, tz.utc_to_local(18000))
assert_equal(18000, tz.local_to_utc(0))
Expand Down