Class: MiniSql::Postgres::Coders::TimestampUtc

Inherits:
PG::SimpleDecoder
  • Object
show all
Defined in:
lib/mini_sql/postgres/coders.rb

Constant Summary collapse

ISO_DATETIME =

exact same implementation as Rails here

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

Instance Method Summary collapse

Instance Method Details

#decode(string, tuple = nil, field = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/mini_sql/postgres/coders.rb', line 22

def decode(string, tuple = nil, field = nil)
  if string =~ ISO_DATETIME
    microsec = ($7.to_r * 1_000_000).to_i
    Time.utc $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec
  else
    STDERR.puts "unexpected date time format #{string}"
    string
  end
end