Created
June 26, 2018 09:43
-
-
Save rodloboz/9db00e2ed8d67c36e19949732efdc182 to your computer and use it in GitHub Desktop.
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
require 'date' | |
def days_until_xmas(date = Date.today) | |
# TODO: calculate the number of days | |
# until Christmas | |
current_year = Time.now.year | |
if (Date.new(current_year, 12, 25) - date).to_i < 0 | |
(Date.new(current_year + 1, 12, 25) - date).to_i | |
else | |
(Date.new(current_year, 12, 25) - date).to_i | |
end | |
end | |
# We want to display "true" to test | |
# our method (TDD) | |
# 182 | |
puts days_until_xmas == 182 | |
puts days_until_xmas(Date.new(2018, 12, 24)) == 1 | |
puts days_until_xmas(Date.new(2018, 12, 26)) == 364 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment