Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/et-orbi/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ def seconds=(f)

def zone=(z)

tz = self.class.get_tzone(z || zone)
fail ArgumentError.new("Cannot determine timezone from #{z.inspect}") \
unless tz

@zone = self.class.get_tzone(zone || :current)
@zone = tz

touch

Expand Down
27 changes: 27 additions & 0 deletions test/eo_time_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,33 @@
end
end

group '#zone=' do

test 'assigns the requested timezone and invalidates the time cache' do

ot = EtOrbi::EoTime.new(0, 'UTC')
ot.hour

ot.zone = 'Asia/Kolkata'

assert ot.zone.name, 'Asia/Kolkata'
assert ot.hour, 5
assert ot.min, 30
assert ot.to_f, 0.0
end

test 'does not change the timezone when assignment fails' do

ot = EtOrbi::EoTime.new(0, 'UTC')

assert_error(
lambda { ot.zone = 'Invalid/Timezone' },
ArgumentError)

assert ot.zone.name, 'UTC'
end
end

group '.utc' do

[
Expand Down