Skip to content

Instantly share code, notes, and snippets.

@nacengineer
Last active December 10, 2015 15:29
Show Gist options
  • Save nacengineer/4454933 to your computer and use it in GitHub Desktop.
Save nacengineer/4454933 to your computer and use it in GitHub Desktop.
Simple Object to return Christmas and Thanksgiving as Date and query if its the Christmas holiday season
# also check out this sweet gem! https://github.com/alexdunae/holidays
class Christmas
attr_reader :christmastime, :christmas, :usa_thanksgiving
def initialize
@christmastime = is_christmastime?
end
def is_christmastime?(seed_date = Date.today, padding = 0)
((usa_thanksgiving - padding)..christmas).cover?( seed_date )
end
def christmas
Date.parse("25-12-#{Time.now.year}")
end
def usa_thanksgiving
nov_1 = Date.parse("1-11-#{Time.now.year}")
(nov_1..(nov_1 + 7)).reduce(nov_1) do |a,x|
return a + 21 if a.thursday?
a += 1; a
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment