Skip to content

Instantly share code, notes, and snippets.

@jphastings
Created May 22, 2009 18:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jphastings/116293 to your computer and use it in GitHub Desktop.
Save jphastings/116293 to your computer and use it in GitHub Desktop.
An ETA class to allow intuitive access to an estimated time of arrival
# Thanks Ellie and Robert! http://www.ruby-forum.com/topic/187604
# Allows relative times, most frequently used in times of arrival etc.
class ETA < Time
# Takes a number of seconds until the event
def self.new(seconds)
raise "ETA requires a number of seconds" if not seconds.is_a?(Numeric)
at Time.now + seconds
end
# Requires http://gist.github.com/116290
def to_s
roughly
end
# Gives a full textual representation of the time expected time of arrival (Time.rfc2822)
def eta
rfc2822
end
# Has the eta passed?
def arrived?
self < Time.now
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment