class Bronze::Transforms::Attributes::TimeTransform

Transform class that converts a Time to an integer timestamp.

Public Class Methods

instance() click to toggle source

@return [TimeTransform] a memoized instance of TimeTransform.

# File lib/bronze/transforms/attributes/time_transform.rb, line 12
def self.instance
  @instance ||= new
end

Public Instance Methods

denormalize(value) click to toggle source

Converts an integer timestamp to a Time.

@param value [Integer] The integer timestamp.

@return [Time] the Time corresponding to the timestamp.

# File lib/bronze/transforms/attributes/time_transform.rb, line 21
def denormalize(value)
  return nil if value.nil?

  Time.at(value).utc
end
normalize(value) click to toggle source

Converts a Time to an integer timestamp.

@param value [Time] The Time to normalize.

@return [Integer] the integer timestamp.

# File lib/bronze/transforms/attributes/time_transform.rb, line 32
def normalize(value)
  return nil if value.nil?

  value.to_i
end