Last active
December 10, 2015 15:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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