Skip to content

Instantly share code, notes, and snippets.

@rodloboz
Created June 26, 2018 09:43
Show Gist options
  • Save rodloboz/9db00e2ed8d67c36e19949732efdc182 to your computer and use it in GitHub Desktop.
Save rodloboz/9db00e2ed8d67c36e19949732efdc182 to your computer and use it in GitHub Desktop.
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