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

Resolve ambiguity for permanent timezone changes #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion lib/biz/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def on_date(date, day_time)
day_time.minute,
day_time.second
),
true
true,
&:first
)
rescue TZInfo::PeriodNotFound
on_date(Date.for_dst(date, day_time), day_time.for_dst)
Expand Down
12 changes: 12 additions & 0 deletions spec/time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@
)
end
end

context 'when an ambiguous non-daylight-savings time is targeted' do
let(:time_zone) { TZInfo::Timezone.get('Asia/Pyongyang') }
let(:date) { Date.new(2015, 8, 14) }
let(:day_time) { Biz::DayTime.new(day_second(hour: 23, min: 59)) }

it 'returns the earliest occurrence of the time' do
expect(time.on_date(date, day_time)).to eq(
time_zone.local_to_utc(Time.utc(2015, 8, 14, 23, 59), &:first)
)
end
end
end

describe '#during_week' do
Expand Down