holidays / holidays

A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!
Other
816 stars 281 forks source link

region is not being populated for custom functions #433

Open erluti opened 2 months ago

erluti commented 2 months ago

I'm trying to put together a PR for when Utah observes Juneteenth (https://github.com/holidays/definitions/pull/290) and came across the issue that no value is being passed in for region to a custom function.

The syntax docs state that region is a supported argument: https://github.com/holidays/definitions/blob/master/doc/SYNTAX.md#available-arguments

Ex:

  juneteenth_national_independence_day:
    # In Utah...
    # When Saturday or Sunday, it's on next Monday
    # When Tuesday through Friday, it's on the preceeding Monday
    # all other states it's observed like "to_weekday_if_weekend"
    arguments: date, region
    ruby: |
      if region == :us_ut
        case date.wday
        when 1
          date
        when 2,3,4,5
          date - (date.wday - 1)
        when 6
          date + 2
        when 0
          date + 1
        end
      elsif date.wday == 0
        date + 1
      elsif date.wday == 6
        date - 1
      else
        date
      end

this results in this code being created in us.rb file in generated definitions:

"juneteenth_national_independence_day(region, date)" => Proc.new { |date, region|
if region == :us_ut
  case date.wday
  when 1
    date
  when 2,3,4,5
    date - (date.wday - 1)
  when 6
    date + 2
  when 0
    date + 1
  end
elsif date.wday == 0
  date + 1
elsif date.wday == 6
  date - 1
else
  date
end
},

When I add a line to output the region (puts "REGION: #{region} (#{region.class})"), the result shows the value is nil. When I reversed the arguments in the custom method, the generated file had reversed arguments, and the result was that region was set to the date and date was nil.