Hello all
I am struggling with ActiveSupport::Duration and creation of a duration that matches the #end_of_day
. Summarised in code as follows:
Date.today.end_of_day == Date.today + ActiveSupport::Duration.parse("PT23H59M59.999999S") #=> false
I need only the duration (there is no date within the context where the duration is built)
I have tried ::build
method without success
ActiveSupport::Duration.build((1440 * 60) - 0.0000000001.second)
Both these Duration instanciation methods are nearly correct, only nano seconds out.
Can anyone suggest something I can try to construct a Duration that can be used to match #end_of_day
??
More code to demo my issue:
def end_duration
ActiveSupport::Duration.parse("PT23H59M59.999999S")
end
date = Date.new(2022, 1, 1)
date_with_duration = date + end_duration
# both dates appear the same..
date.end_of_day.to_s == date_with_duration.to_s #=> true
# .. but they are not
date.end_of_day == date_with_duration #=> false
# looks like itd down the second fraction
date.end_of_day.sec_fraction #=> (999999999/1000000000)
date_with_duration.sec_fraction #=> (8796084226115/8796093022208)