class DataMapper::Property::Legacy::TimeString

Public Instance Methods

dump(value) click to toggle source

Dumps a time to a string.

@param [Time, nil] value

The time to dump.

@return [String, nil]

The time string.
# File lib/dm-core/property/legacy/time_string.rb, line 52
def dump(value)
  case value
  when ::Time
    value.to_s
  when ::Date
    value.to_time.to_s
  when nil
    nil
  else
    value.to_s
  end
end
load(value) click to toggle source

Parses a time string.

@param [String] value

The time string.

@return [Time, nil]

The parsed time.
# File lib/dm-core/property/legacy/time_string.rb, line 20
def load(value)
  ::Time.parse(value) unless (value.nil? || value.empty?)
end
typecast(value) click to toggle source

Typecasts a time.

@param [Time, Date, String, nil] value

The time to typecast.

@return [Time, nil]

The typecasted time.
# File lib/dm-core/property/legacy/time_string.rb, line 33
def typecast(value)
  if value.kind_of?(::Time)
    value
  elsif value.kind_of?(::Date)
    value.to_time
  elsif value.kind_of?(::String)
    ::Time.parse(value) unless value.empty?
  end
end