Sha256: a0af63a0d281ce9f0e1043cd635938ec3045fe002b3a3c7636c784c5d588c621

Contents?: true

Size: 721 Bytes

Versions: 24

Compression:

Stored size: 721 Bytes

Contents

module Toy
  module Extensions
    module Time
      def to_store(value, *)
        if value.nil? || value == ''
          nil
        else
          time_class = ::Time.try(:zone).present? ? ::Time.zone : ::Time
          time = value.is_a?(::Time) ? value : time_class.parse(value.to_s)
          # strip milliseconds as Ruby does micro and bson does milli and rounding rounded wrong
          at(time.to_i).utc if time
        end
      end

      def from_store(value, *)
        value = to_store(value)
        if ::Time.try(:zone).present? && value.present?
          value.in_time_zone(::Time.zone)
        else
          value
        end
      end
    end
  end
end

class Time
  extend Toy::Extensions::Time
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
toystore-0.13.2 lib/toy/extensions/time.rb
toystore-0.13.1 lib/toy/extensions/time.rb
toystore-0.13.0 lib/toy/extensions/time.rb
toystore-0.12.0 lib/toy/extensions/time.rb
toystore-0.11.0 lib/toy/extensions/time.rb
toystore-0.10.4 lib/toy/extensions/time.rb
toystore-0.10.3 lib/toy/extensions/time.rb
toystore-0.10.2 lib/toy/extensions/time.rb
toystore-0.10.1 lib/toy/extensions/time.rb
toystore-0.10.0 lib/toy/extensions/time.rb
toystore-0.9.0 lib/toy/extensions/time.rb
toystore-0.8.3 lib/toy/extensions/time.rb
toystore-0.8.2 lib/toy/extensions/time.rb
toystore-0.8.1 lib/toy/extensions/time.rb
toystore-0.8.0 lib/toy/extensions/time.rb
toystore-0.7.0 lib/toy/extensions/time.rb
toystore-0.6.6 lib/toy/extensions/time.rb
toystore-0.6.5 lib/toy/extensions/time.rb
toystore-0.6.4 lib/toy/extensions/time.rb
toystore-0.6.3 lib/toy/extensions/time.rb