Permalink
Browse files

Fix DST issue related to fortnight

  • Loading branch information...
1 parent fbe35c8 commit d06a2b47b4a6953c982975b5dd8ee5727f0e1c9c @johnnyshields johnnyshields committed Jan 17, 2014
Showing with 22 additions and 22 deletions.
  1. +2 −2 lib/by_star/kernel.rb
  2. +20 −20 spec/unit/kernel_time_spec.rb
View
@@ -18,11 +18,11 @@ def end_of_weekend
# A "Fortnight" is defined as a two week period, with the first fortnight of the
# year beginning on 1st January.
def beginning_of_fortnight
- beginning_of_year + ((self - beginning_of_year) / 2.weeks).to_i * 2.weeks
+ (beginning_of_year.to_date + 14 * ((self - beginning_of_year) / 2.weeks).to_i).beginning_of_day
end
def end_of_fortnight
- (beginning_of_fortnight + 13.days).end_of_day
+ (beginning_of_fortnight.to_date + 13).end_of_day
end
# A "Calendar Month" is defined as a month as it appears on a calendar, including days
@@ -6,52 +6,52 @@
(0..6).each do |n|
context "Monday plus #{n} days" do
- subject { Time.parse('2014-01-06') + n.days }
- its(:beginning_of_weekend){ should eq Time.parse('2014-01-10 15:00') }
- its(:end_of_weekend){ should eq Time.parse('2014-01-13 02:00').end_of_hour }
+ subject { Time.zone.parse('2014-01-06') + n.days }
+ its(:beginning_of_weekend){ should eq Time.zone.parse('2014-01-10 15:00') }
+ its(:end_of_weekend){ should eq Time.zone.parse('2014-01-13 02:00').end_of_hour }
end
end
end
describe 'fortnight' do
context 'first day of year' do
- subject { Time.parse '2014-01-01' }
- its(:beginning_of_fortnight){ should eq Time.parse('2014-01-01') }
- its(:end_of_fortnight){ should eq Time.parse('2014-01-14').end_of_day }
+ subject { Time.zone.parse '2014-01-01' }
+ its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-01-01') }
+ its(:end_of_fortnight){ should eq Time.zone.parse('2014-01-14').end_of_day }
end
context 'second fortnight of year' do
- subject { Time.parse '2014-01-16' }
- its(:beginning_of_fortnight){ should eq Time.parse('2014-01-15') }
- its(:end_of_fortnight){ should eq Time.parse('2014-01-28').end_of_day }
+ subject { Time.zone.parse '2014-01-16' }
+ its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-01-15') }
+ its(:end_of_fortnight){ should eq Time.zone.parse('2014-01-28').end_of_day }
end
context 'middle of year' do
- subject { Time.parse '2014-06-13' }
- its(:beginning_of_fortnight){ should eq Time.parse('2014-06-04') }
- its(:end_of_fortnight){ should eq Time.parse('2014-06-17').end_of_day }
+ subject { Time.zone.parse '2014-06-13' }
+ its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-06-04') }
+ its(:end_of_fortnight){ should eq Time.zone.parse('2014-06-17').end_of_day }
end
context 'last day of year' do
- subject { Time.parse '2014-12-31' }
- its(:beginning_of_fortnight){ should eq Time.parse('2014-12-31') }
- its(:end_of_fortnight){ should eq Time.parse('2015-01-13').end_of_day }
+ subject { Time.zone.parse '2014-12-31' }
+ its(:beginning_of_fortnight){ should eq Time.zone.parse('2014-12-31') }
+ its(:end_of_fortnight){ should eq Time.zone.parse('2015-01-13').end_of_day }
end
end
describe 'calendar_month' do
- subject { Time.parse '2014-01-01' }
+ subject { Time.zone.parse '2014-01-01' }
context 'week begins Monday' do
- its(:beginning_of_calendar_month){ should eq Time.parse('2013-12-30') }
- its(:end_of_calendar_month){ should eq Time.parse('2014-02-02').end_of_day }
+ its(:beginning_of_calendar_month){ should eq Time.zone.parse('2013-12-30') }
+ its(:end_of_calendar_month){ should eq Time.zone.parse('2014-02-02').end_of_day }
end
context 'week begins Sunday' do
- it { subject.beginning_of_calendar_month(:sunday).should eq Time.parse('2013-12-29') }
- it { subject.end_of_calendar_month(:sunday).should eq Time.parse('2014-02-01').end_of_day }
+ it { subject.beginning_of_calendar_month(:sunday).should eq Time.zone.parse('2013-12-29') }
+ it { subject.end_of_calendar_month(:sunday).should eq Time.zone.parse('2014-02-01').end_of_day }
end
end
end

0 comments on commit d06a2b4

Please sign in to comment.