Rails does weird rounding in comparisons between Date
and ActiveSupport::TimeWithZone
classes.
It’s probably because I’m (in GMT) within the boundary of the days in the two timezones, but:
monday = Date.new(2023, 9, 25)
# => Mon, 25 Sep 2023
ten_days_from_now = 10.days.from_now
# => Sun, 24 Sep 2023 20:28:02.217735000 EDT -04:00
monday.class
# => Date
ten_days_from_now.class
# => ActiveSupport::TimeWithZone
monday <= ten_days_from_now
# => true
This is incorrect, Monday is not less than or equal to Sunday.
But, if we make 10.days.from_now
also a Date
:
monday <= ten_days_from_now.to_date
# => false
We get the correct answer, where that is:
ten_days_from_now.to_date
# => Sun, 24 Sep 2023
So, Monday is before or equal to Sunday at 20:28, but after “Sunday”.
Thanks, Rails.
[dynamically types languages are a curse, sometimes]
— Adam Dawkins
Who are Dragon Drop?
Dragon Drop is a specialist web and app development agency. The team has extensive full-stack technical credentials and a strong focus on user experience.
The Dragon Drop founding team have over 40 years of web development and project experience. They have managed or developed over 100 significant ecommerce and web projects during their careers, including implementations for major UK high street retailers, financial services companies and government agencies.
Their approach to innovative solutions stems from perspectives gained as retailer, software supplier and web agency.