Skip to content

Commit bf952c9

Browse files
committed
Fixes #6 - Parsing of timestamps with microsecond precision (without require 'time')
1 parent 84c7122 commit bf952c9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lib/db/postgres/native/types.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,16 @@ def initialize(name = "TIMESTAMP")
9999
attr :name
100100

101101
def parse(string)
102-
if match = string.match(/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)([\+\-].*)?/)
103-
parts = match.captures
104-
parts[6] ||= "UTC"
105-
106-
return Time.new(*parts)
102+
return nil unless match = string.match(/\A(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+(?:\.\d+)?)([-+].*)?\z/)
103+
parts = match.captures
104+
parts[5] = BigDecimal(parts[5])
105+
if parts[6].nil?
106+
parts[6] = '+00:00'
107+
elsif /^[-+]\d\d$/ === parts[6]
108+
parts[6] += ':00'
107109
end
110+
111+
Time.new(*parts)
108112
end
109113
end
110114

0 commit comments

Comments
 (0)