Class: Formatter::Date::TimeOrDateTime

Inherits:
TZInfo::TimeOrDateTime
  • Object
show all
Defined in:
lib/formatter/date.rb

Overview

Wrapper class around TZInfo::TimeOrDateTime that only accepts Time or DateTime.

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ TimeOrDateTime

Returns a new instance of TimeOrDateTime.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/formatter/date.rb', line 12

def initialize(object)
  case object
  when Time
    object = object.utc
  when DateTime
    object = object.new_offset Rational(0, 24)
  else
    fail ArgumentError, "invalid Time or DateTime: #{object.inspect}"
  end

  super TZInfo::TimeOrDateTime.wrap(object)
end