Skip to content

Instantly share code, notes, and snippets.

@davidedicillo
Created July 13, 2011 00:26
Show Gist options
  • Select an option

  • Save davidedicillo/1079494 to your computer and use it in GitHub Desktop.

Select an option

Save davidedicillo/1079494 to your computer and use it in GitHub Desktop.
filename = 'birthdays.txt'
file_string = File.read filename
birthdays = {}
person = ()
file_string.each_line do |line|
line = line.chomp
arr = line.split(', ')
name = arr[0]
day_month = arr[1].split
date = [arr[2], day_month[0], day_month[1]]
birthdays[name] = date
end
#puts "who's birthday?"
#person = gets.chomp
def next_birthday person, birthdays
birthday = birthdays[person]
year = birthday[0]
month = birthday[1]
day = birthday[2]
t = Time.now
this_year = t.year
if t > Time.local(this_year,month,day)
return Time.local(this_year + 1,month,day)
else
return Time.local(this_year,month,day)
end
end
puts "who's birthday?"
person = gets.chomp
puts next_birthday(person, birthdays)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment