class Ourtime
Convert a string into a time value (timestamp) (helped by String.thetime
)
Attributes
thetime[R]
Public Class Methods
new(x = nil)
click to toggle source
TODO: deprecate this…
# File lib/ndr_support/ourtime.rb, line 14 def initialize(x = nil) if x.is_a?(Time) @thetime = x elsif x.is_a?(Date) @thetime = x.to_time elsif x.is_a?(String) self.source = x else @thetime = nil end end
zone()
click to toggle source
# File lib/ndr_support/ourtime.rb, line 9 def self.zone @zone ||= ActiveSupport::TimeZone.new('London') end
Public Instance Methods
empty?()
click to toggle source
# File lib/ndr_support/ourtime.rb, line 30 def empty? # An unspecified time will be empty. A valid time will not. @thetime.nil? end
to_s()
click to toggle source
# File lib/ndr_support/ourtime.rb, line 26 def to_s @thetime ? @thetime.to_time.to_formatted_s(:ui) : '' end
Private Instance Methods
source=(s)
click to toggle source
# File lib/ndr_support/ourtime.rb, line 37 def source=(s) @thetime = zone.parse(s) end
zone()
click to toggle source
# File lib/ndr_support/ourtime.rb, line 41 def zone # `delegate` doesn't work for this on Rails 3.2 self.class.zone end