Sha256: da602a9a8280b34b5234825c1dceffc8bfa8214a488dde63022a00b325ab75d1

Contents?: true

Size: 500 Bytes

Versions: 4

Compression:

Stored size: 500 Bytes

Contents

module ChronoModel

  module Conversions
    extend self

    ISO_DATETIME = /\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.(\d+))?\z/

    def string_to_utc_time(string)
      if string =~ ISO_DATETIME
        usec = $7.nil? ? '000000' : $7.ljust(6, '0') # .1 is .100000, not .000001
        Time.utc $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, usec.to_i
      end
    end

    def time_to_utc_string(time)
      [time.to_s(:db), sprintf('%06d', time.usec)].join '.'
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chrono_model-1.2.2 lib/chrono_model/conversions.rb
chrono_model-1.2.1 lib/chrono_model/conversions.rb
chrono_model-1.2.0 lib/chrono_model/conversions.rb
chrono_model-1.1.0 lib/chrono_model/conversions.rb