Skip to content

Instantly share code, notes, and snippets.

@dhenze
Last active January 22, 2019 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhenze/ed621f94f4ca335adbd68d89c3278e34 to your computer and use it in GitHub Desktop.
Save dhenze/ed621f94f4ca335adbd68d89c3278e34 to your computer and use it in GitHub Desktop.
require "time"
class Timestamp
attr_reader :time
private_class_method :new
def initialize(time)
fail TypeError.new("String required") unless time.is_a?(String)
@time = Time.parse(time)
end
def self.from_string(time_string)
new(time_string)
end
def to_s
time.to_s
end
def equals(t2)
self.time == t2.time
end
def before(t2)
self.time < t2.time
end
def after(t2)
self.time > t2.time
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment