Sha256: 75dcf4e1bb8204145e20b805e280e74489954b9b8a79eb6aa2713337ae07260c

Contents?: true

Size: 814 Bytes

Versions: 8

Compression:

Stored size: 814 Bytes

Contents

require 'active_support/time'
require 'ndr_support/ourdate'

# Convert a string into a time value (timestamp)
# (helped by String.thetime)
class Ourtime
  attr_reader :thetime

  def self.zone
    @zone ||= ActiveSupport::TimeZone.new('London')
  end

  # TODO: deprecate this...
  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

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

  def empty?
    # An unspecified time will be empty. A valid time will not.
    @thetime.nil?
  end

  private

  def source=(s)
    @thetime = zone.parse(s)
  end

  def zone
    # `delegate` doesn't work for this on Rails 3.2
    self.class.zone
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ndr_support-5.9.2 lib/ndr_support/ourtime.rb
ndr_support-5.9.1 lib/ndr_support/ourtime.rb
ndr_support-5.9.0 lib/ndr_support/ourtime.rb
ndr_support-5.8.4 lib/ndr_support/ourtime.rb
ndr_support-5.8.3 lib/ndr_support/ourtime.rb
ndr_support-5.8.2 lib/ndr_support/ourtime.rb
ndr_support-5.8.1 lib/ndr_support/ourtime.rb
ndr_support-5.8.0 lib/ndr_support/ourtime.rb