Module: ChronoModel::Conversions
Constant Summary collapse
- ISO_DATETIME =
/\A(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(?:\.(\d+))?\z/
Instance Method Summary collapse
Instance Method Details
#string_to_utc_time(string) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/chrono_model/conversions.rb', line 8 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 |
#time_to_utc_string(time) ⇒ Object
15 16 17 |
# File 'lib/chrono_model/conversions.rb', line 15 def time_to_utc_string(time) [time.to_s(:db), sprintf('%06d', time.usec)].join '.' end |