Dates and timezones - inconsistency with detected timezone

I’m working on a system which needs to be timezone aware, however I’ve come across an odd discrepancy. Consider the following:

x = DateTime.parse("2017-02-01 12:00:00+0200")
puts x.t_time.inspect

The result given is (correctly) returned to me in my current timezone of -0800

However, if I perform the following:

y = Date.today - 1
puts y.to_time.inspect

I end up getting a result in -0700

I fail to understand how this is happening or even how I correct it. When looking up time zone manipulation in Ruby, all I got was “good luck” (from an actual documentation site).

You are sure, that the country, you are working from, didn’t have daylight savings back in February?

I’m currently in Denmark, where we are +0200 at the moment, but were +0100 on February 1st, thus:

DateTime.parse("2017-02-01 12:00:00+0200").to_time # => 2017-02-01 11:00:00 +0100
DateTime.parse("2017-07-01 12:00:00+0200").to_time # => 2017-07-01 12:00:00 +0200
(Date.today - 1).to_time                           # => 2017-06-19 00:00:00 +0200
(Date.today - 91).to_time                          # => 2017-03-21 00:00:00 +0100
1 Like

Daaaaamn, you are absolutely correct! Thank you so much Ohm!