holidays / holidays

A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strange behavoir with end_of_month

chriskrams opened this issue · comments

Is it possible that the end_of_month function of holidays/core_extensions/date also overwrites the end_of_month core function of Ruby DateTime?

For all calls (all_month, all_year, all_quarter - uses ruby core end_of_month) I only get the last date with the current time and not at_end_of_day.

I also just discovered this. Holidays' Holidays::CoreExetensions::Date#end_of_month method in

def end_of_month
last_day = ::Time.days_in_month( self.month, self.year )
change(:day => last_day)
end
overwrites Rails' ActiveSupport::CoreExt::DateAndTime::Calculation#end_of_month method in https://github.com/rails/rails/blob/3a931c2e6a55514f0432fe8d2797cecfcd08c0f9/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb#L284-L290

This is resulting in:

irb(main):003:0> Time.current.end_of_month
=> Fri, 31 Mar 2023 13:19:00.924926000 UTC +00:00

irb(main):004:0> DateTime.current.end_of_month
=> Fri, 31 Mar 2023 13:19:01 +0000

irb(main):006:0> Time.current.all_month
=> Wed, 01 Mar 2023 00:00:00.000000000 UTC +00:00..Fri, 31 Mar 2023 13:31:55.474560000 UTC +00:00

I was able to resolve this, by making sure to not include the Holidays::CoreExtensions::Date module inside the DateTime or Time class:

require "holidays/core_extensions/date"
require "holidays/core_extensions/time"

class Date
  include Holidays::CoreExtensions::Date
end

class Time
- include Holidays::CoreExtensions::Date
  include Holidays::CoreExtensions::Time
end