Class: Superstore::Types::TimeType

Inherits:
BaseType
  • Object
show all
Defined in:
lib/superstore/types/time_type.rb

Instance Attribute Summary

Attributes inherited from BaseType

#model, #options

Instance Method Summary collapse

Methods inherited from BaseType

#initialize, #typecast

Constructor Details

This class inherits a constructor from Superstore::Types::BaseType

Instance Method Details

#decode(str) ⇒ Object



10
11
12
13
14
# File 'lib/superstore/types/time_type.rb', line 10

def decode(str)
  Time.parse(str).in_time_zone if str
rescue

end

#encode(time) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
# File 'lib/superstore/types/time_type.rb', line 4

def encode(time)
  raise ArgumentError.new("#{time.inspect} does not respond to #to_time") unless time.is_a?(Time) || time.respond_to?(:to_time)
  time = time.to_time unless time.is_a?(Time)
  time.utc.xmlschema(6)
end