Rails - Added sub seconds to Time inspect

1 minute read

Ruby 2.7 added sub seconds to Time#inspect and separated it from Time#to_s .

Rails also added sub seconds to ActiveSupport::TimeWithZone#inspect .

This is particularly helpful when multiple time objects are created in a short interval. For e.g., when executing imports in parallel, or when we need to assert time differences in our test cases.

Before

Time . at ( 1587660977 ). in_time_zone . inspect # => "Thu, 23 Apr 2020 16:56:17 UTC +00:00" Time . at ( 1587660977 , 456789123 , :nsec ). in_time_zone . inspect # => "Thu, 23 Apr 2020 16:56:17 UTC +00:00"

After

Time . at ( 1587660977 ). in_time_zone . inspect # => "Thu, 23 Apr 2020 16:56:17 UTC +00:00" Time . at ( 1587660977 , 456789123 , :nsec ). in_time_zone . inspect # => "Thu, 23 Apr 2020 16:56:17.456789123 UTC +00:00"

Summary