module GBDate::ActiveRecord::Type::Time

Constants

DISTANCE_TO_DEFAULT_DAY
SECONDS_A_DAY

Public Instance Methods

cast_value(value) click to toggle source
Calls superclass method
# File lib/gb_date/active_record/type/time.rb, line 8
def cast_value(value)
  return ::Time.at(calculate_float_value value)  if value.is_a? Numeric
  if value.is_a?(::String) && value =~ ::ActiveRecord::ConnectionAdapters::Column::Format::NUMERIC_TIME
    return ::Time.at(calculate_float_value value)
  end
  super value
end
fast_string_to_time(string) click to toggle source
Calls superclass method
# File lib/gb_date/active_record/type/time.rb, line 16
def fast_string_to_time(string)
  if string =~ ::ActiveRecord::ConnectionAdapters::Column::Format::NUMERIC_TIME
    ::Time.at(string.to_f)
  else
    super string
  end
end

Private Instance Methods

calculate_float_value(value) click to toggle source
# File lib/gb_date/active_record/type/time.rb, line 26
def calculate_float_value(value)
  DISTANCE_TO_DEFAULT_DAY + ( value.to_f % 86400.0)
end