module Holidays::CoreExtensions::Date
Public Class Methods
included(base)
click to toggle source
# File lib/holidays/core_extensions/date.rb, line 4 def self.included(base) base.extend ClassMethods end
Public Instance Methods
change(options)
click to toggle source
Returns a new Date
where one or more of the elements have been changed according to the options
parameter. The options
parameter is a hash with a combination of these keys: :year
, :month
, :day
.
Date.new(2007, 5, 12).change(day: 1) # => Date.new(2007, 5, 1) Date.new(2007, 5, 12).change(year: 2005, month: 1) # => Date.new(2005, 1, 12)
# File lib/holidays/core_extensions/date.rb, line 37 def change(options) ::Date.new( options.fetch(:year, year), options.fetch(:month, month), options.fetch(:day, day) ) end
end_of_month()
click to toggle source
# File lib/holidays/core_extensions/date.rb, line 45 def end_of_month last_day = ::Time.days_in_month( self.month, self.year ) change(:day => last_day) end
holiday?(*options)
click to toggle source
Check if the current date is a holiday.
Returns true or false.
Date.civil('2008-01-01').holiday?(:ca) => true
# File lib/holidays/core_extensions/date.rb, line 27 def holiday?(*options) holidays = self.holidays(*options) holidays && !holidays.empty? end
holidays(*options)
click to toggle source
Get holidays on the current date.
Returns an array of hashes or nil. See Holidays#between for options and the output format.
Date.civil('2008-01-01').holidays(:ca_) => [{:name => 'New Year\'s Day',...}]
Also available via Holidays#on.
# File lib/holidays/core_extensions/date.rb, line 17 def holidays(*options) Holidays.on(self, *options) end