Created
July 9, 2019 16:32
-
-
Save krokrob/5cd0be3d3c6ec6b188d98fba8d9a05e0 to your computer and use it in GitHub Desktop.
This file contains 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
# TODO: Implement a method which returns | |
# the number of days until next Xmas | |
require 'date' | |
def compute_result(year, today) | |
xmas = Date.new(year,12,25) | |
xmas - today | |
end | |
def days_until_xmas | |
# définir la date du jour | |
today = Date.today | |
#récupérrer l'année | |
year = today.year | |
# définir la date de noël | |
diff = compute_result(year, today) | |
# verifier si result est negatif | |
if diff.to_i < 0 | |
# si oui | |
# incrementer year | |
year += 1 | |
# redefinir la date de noel | |
# reclalculer result | |
diff = compute_result(year, today) | |
end | |
# renvoyer le résultat | |
return diff.to_i | |
end | |
puts days_until_xmas | |
puts days_until_xmas.class == Integer | |
puts days_until_xmas >= 0 | |
puts days_until_xmas == 169 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment