Compare the utc offset from the timestamp, not now (#15256)

Time Zones are political things, and move. The timezone database knows
this, and correctly interprets times as they would have been at the
time.

For example, when the Time zone is Africa/Monrovia, the offset now is
0, but the offset in 1970 was -44.5 minutes, so Time.zone.at(0) is Dec
31st, 1969, 23:15:30 and not Jan 1st, 1970 00:00:00.

Prevent this spec from randomly failing based on Zonebie's selected
timezone by comparing the offset _then_ against UTC, and predicting
whether the 60's have ended yet.
This commit is contained in:
Daniel Uber 2021-11-01 16:49:35 -04:00 committed by GitHub
parent 4a9f442354
commit e3ebc623da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,7 +72,7 @@ RSpec.describe "articles/show", type: :view do
render
# Jan 1, 1970 or Dec 31, 1969, depending on time zone
expected_date = Time.zone.utc_offset.negative? ? "Dec 31, 1969" : "Jan 1, 1970"
expected_date = Time.zone.at(0).utc_offset.negative? ? "Dec 31, 1969" : "Jan 1, 1970"
expect(rendered).to have_text(expected_date)
expect(rendered).not_to have_text("</time>")
end