# Reinterpret Date within other timezone in Rails

The Date type in Rails does not retain the timezone information. The default timezone is consistent with the system Rails provides. But it’s implicit, so we should never forget which timezone we use as a Date type.

We can use in_time_zone to be explicit about which timezone we are aware of.

pry(main)> d = Date.new(2023, 1, 20)
=> Fri, 20 Jan 2023
pry(main)> d.to_time
=> 2023-01-20 00:00:00 +0000
pry(main)> d.in_time_zone('Asia/Tokyo')
=> Fri, 20 Jan 2023 00:00:00.000000000 JST +09:00
pry(main)> d.in_time_zone('Canada/Eastern')
=> Fri, 20 Jan 2023 00:00:00.000000000 EST -05:00


in_time_zone returns the TimeWithZone which inherently retains the timezone information. It’s useful to pass the timezone identifier in string type without changing the system configuration.

And the book, Agile Web Development with Rails 6 will be a more comprehensive guide to understanding the timezone structure in Rails.