-
Notifications
You must be signed in to change notification settings - Fork 0
/
date_calc.rb
73 lines (54 loc) · 1.02 KB
/
date_calc.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'date'
def get_birthday
puts "Please enter your date of birth in this format: YYYY-MM-DD"
gets.chomp
end
def convert_birthday(dob)
dob = dob.split("-")
@birth_day = dob[2].to_i
@birth_month = dob[1].to_i
@birth_year = dob[0].to_i
end
def today
date = Date.today
@this_day = date.day
@this_month = date.mon
@this_year = date.year
date.yday
end
def calculate_age
years = Date.today.year - @birth_day
end
def birthday_passed?
if (@this_month > @birth_month)
true
elsif (@this_month = @birth_month) && (@this_day >= @birth_day)
true
else
false
end
end
def age
today
convert_birthday(get_birthday)
if birthday_passed?
years_old = @this_year - @birth_year
else
years_old = @this_year - @birth_year - 1
end
puts "You are #{years_old}"
pause
end
def xmas
Date.new(2015, 12, 25).yday
end
def sleeps_till_xmas
sleeps = xmas - today
if xmas > today
sleeps
else
sleeps + 365
end
puts "There are #{sleeps} sleeps till Christmas!!!"
pause
end