The TimeWithZone is a Time-like class that can represent a time in any time zone. It is necessary because standard Ruby Time instances are limited to UTC and the system’s ENV['TZ'] zone.
TimeWithZone instances implement the same API as Ruby Time instances, so that Time and TimeWithZone instances are interchangeable.
TimeWithZone#inspect Returns a string of the object’s date, time, zone, and offset from UTC.
Before
TimeWithZone#inspect used an RFC822-inspired format for displaying timestamps. For instance:
Time.zone.now.inspect
#=> "Mon, 30 Sep 2024 05:04:48.516544000 UTC +00:00"This format is readable but lacks consistency with Ruby’s internal Time#inspect, which follows the ISO 8601 standard.
After
Rails 8 now uses ISO 8601 style time for TimeWithZone#inspect method like Time#inspect
Time.zone.now.inspect
#=> 2024-09-30 10:37:27.675403 +0530 The update to TimeWithZone#inspect aligns Rails with Ruby standards, ensuring time formatting consistency across the board.
