Class: Ourtime
- Inherits:
-
Object
- Object
- Ourtime
- Defined in:
- lib/ndr_support/ourtime.rb
Overview
Convert a string into a time value (timestamp) (helped by String.thetime)
Instance Attribute Summary collapse
-
#thetime ⇒ Object
readonly
Returns the value of attribute thetime.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(x = nil) ⇒ Ourtime
constructor
TODO: deprecate this…
- #to_s ⇒ Object
Constructor Details
#initialize(x = nil) ⇒ Ourtime
TODO: deprecate this…
14 15 16 17 18 19 20 21 22 23 24 |
# 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 |
Instance Attribute Details
#thetime ⇒ Object (readonly)
Returns the value of attribute thetime.
7 8 9 |
# File 'lib/ndr_support/ourtime.rb', line 7 def thetime @thetime end |
Class Method Details
.zone ⇒ Object
9 10 11 |
# File 'lib/ndr_support/ourtime.rb', line 9 def self.zone @zone ||= ActiveSupport::TimeZone.new('London') end |
Instance Method Details
#empty? ⇒ Boolean
30 31 32 33 |
# File 'lib/ndr_support/ourtime.rb', line 30 def empty? # An unspecified time will be empty. A valid or invalid time will not. @thetime.nil? && @source.blank? end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/ndr_support/ourtime.rb', line 26 def to_s @thetime ? @thetime.to_time.to_s(:ui) : '' end |