Class: Ourtime

Inherits:
Object
  • Object
show all
Defined in:
lib/ndr_support/ourtime.rb

Overview

Convert a string into a time value (timestamp) (helped by String.thetime)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#thetimeObject (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

.zoneObject



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

Returns:

  • (Boolean)


30
31
32
33
# 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_sObject



26
27
28
# File 'lib/ndr_support/ourtime.rb', line 26

def to_s
  @thetime ? @thetime.to_time.to_formatted_s(:ui) : ''
end