Skip to content

Commit

Permalink
spec/ruby/core/time/: Use near time for timezone test
Browse files Browse the repository at this point in the history
`time_with_zone.zone.should == (time_with_zone - 60*60).zone` fails when
the time is immediately before the change of summer time.

https://rubyci.org/logs/rubyci.s3.amazonaws.com/unstable11s/ruby-master/log/20200328T232504Z.fail.html.gz

```
1)
Time#+ preserves time zone FAILED
Expected "CET" == "CEST"
to be truthy but was false
```

It is acceptable as it fails at most twice per year, but it would be
good to use near time objects to reduce the possibility.
  • Loading branch information
mame authored and eregon committed Apr 2, 2020
1 parent 8bb1921 commit bce4f2b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/time/minus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@

it "preserves time zone" do
time_with_zone = Time.now.utc
time_with_zone.zone.should == (time_with_zone - 60*60).zone
time_with_zone.zone.should == (time_with_zone - 1).zone

time_with_zone = Time.now
time_with_zone.zone.should == (time_with_zone - 60*60).zone
time_with_zone.zone.should == (time_with_zone - 1).zone
end

ruby_version_is "2.6" do
context "zone is a timezone object" do
it "preserves time zone" do
zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 60*60
time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 1

time.zone.should == zone
end
Expand Down
6 changes: 3 additions & 3 deletions core/time/plus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@

it "preserves time zone" do
time_with_zone = Time.now.utc
time_with_zone.zone.should == (time_with_zone + 60*60).zone
time_with_zone.zone.should == (time_with_zone + 1).zone

time_with_zone = Time.now
time_with_zone.zone.should == (time_with_zone + 60*60).zone
time_with_zone.zone.should == (time_with_zone + 1).zone
end

ruby_version_is "2.6" do
context "zone is a timezone object" do
it "preserves time zone" do
zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
time = Time.new(2012, 1, 1, 12, 0, 0, zone) + 60*60
time = Time.new(2012, 1, 1, 12, 0, 0, zone) + 1

time.zone.should == zone
end
Expand Down
2 changes: 1 addition & 1 deletion core/time/succ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
context "zone is a timezone object" do
it "preserves time zone" do
zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 60*60
time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 1

time.zone.should == zone
end
Expand Down

0 comments on commit bce4f2b

Please sign in to comment.