Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created September 20, 2012 19:01
Show Gist options
  • Save havenwood/3757702 to your computer and use it in GitHub Desktop.
Save havenwood/3757702 to your computer and use it in GitHub Desktop.
Bedtime Calculator
def wakeup_tomorrow hour, minute
now = Time.now
@wakeup_time = Time.local(now.year, now.month, now.day + 1, hour, minute)
"Wakeup at #{@wakeup_time.hour}:#{@wakeup_time.min}"
end
def sleep_for hour, minute
@bedtime = @wakeup_time - hour * 3600 - minute * 60
"Bedtime at #{@bedtime.hour}:#{@bedtime.min}"
end
wakeup_tomorrow 9, 15
# => "Wakeup at 9:15"
sleep_for 7, 30
# => "Bedtime at 1:45"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment