Top Level Namespace
Defined Under Namespace
Modules: FourTwenty Classes: App
Instance Method Summary collapse
Instance Method Details
#timeUntil(time = Time.new) ⇒ Object
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 |
# File 'lib/420.rb', line 20 def timeUntil(time=Time.new) # This truncates the seconds off the time, to prevent rounding time = Time.parse(time.strftime("%H:%M:00"), time) time = Time.local(time.year, time.month, time.day, time.strftime("%I"), time.strftime("%M")) bowl_times = [Time.local(time.year, time.month, time.day, 4, 20), Time.local(time.year, time.month, time.day, 16, 20)] # This means it's exactly 420! if time.strftime("%I:%M") == "04:20" local = I18n.t :happy, :scope => 'returns' return local # This means it's before 4:20am. elsif time < bowl_times[0] time_until = Time.diff(time, bowl_times[0]) if time_until[:hour] == 0 local = I18n.t :time_minutes, :scope => 'returns' return local % [time_until[:minute]] else local = I18n.t :time, :scope => 'returns' return local % [time_until[:hour], time_until[:minute]] end # This means it's passed 4:20am. elsif time > bowl_times[0] and time < bowl_times[1] time_until = Time.diff(time, bowl_times[1]) if time_until[:hour] == 0 local = I18n.t :time_minutes, :scope => 'returns' return local % [time_until[:minute]] else local = I18n.t :time, :scope => 'returns' return local % [time_until[:hour], time_until[:minute]] end end end |