Class: DB::Postgres::Native::Types::DateTime
- Inherits:
-
Object
- Object
- DB::Postgres::Native::Types::DateTime
- Defined in:
- lib/db/postgres/native/types.rb
Overview
A datetime/timestamp type converter.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
- #The SQL type name.(SQLtypename.) ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(name = "TIMESTAMP") ⇒ DateTime
constructor
Initialize a datetime type converter.
-
#parse(string) ⇒ Object
Parse a datetime value from the database.
Constructor Details
#initialize(name = "TIMESTAMP") ⇒ DateTime
Initialize a datetime type converter.
123 124 125 |
# File 'lib/db/postgres/native/types.rb', line 123 def initialize(name = "TIMESTAMP") @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
128 129 130 |
# File 'lib/db/postgres/native/types.rb', line 128 def name @name end |
#The SQL type name.(SQLtypename.) ⇒ Object (readonly)
128 |
# File 'lib/db/postgres/native/types.rb', line 128 attr :name |
Instance Method Details
#parse(string) ⇒ Object
Parse a datetime value from the database.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/db/postgres/native/types.rb', line 133 def parse(string) if string == "-infinity" || string == "infinity" || string.nil? return string end if match = string.match(/\A(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+(?:\.\d+)?)([-+]\d\d(?::\d\d)?)?\z/) parts = match.captures parts[5] = Rational(parts[5]) if parts[6].nil? parts[6] = "+00" end return Time.new(*parts) end end |