Created
May 22, 2009 18:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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