From e3ebc623da54945e8b5b349ac7ab73e07114ca89 Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Mon, 1 Nov 2021 16:49:35 -0400 Subject: [PATCH] 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. --- spec/views/articles_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/views/articles_spec.rb b/spec/views/articles_spec.rb index 80316e6c8..93ed82a7d 100644 --- a/spec/views/articles_spec.rb +++ b/spec/views/articles_spec.rb @@ -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("") end