class SqlPostgres::PgTimeWithTimeZone
This class holds the value of a “time” column.
Attributes
hour[R]
Return the hour (0..23)
minute[R]
Return the minute (0..59)
second[R]
Return the second (0..59)
zone_hours[R]
Return the hours of the time-zone offset.
zone_minutes[R]
Return the minutes of the time-zone offset.
Public Class Methods
from_sql(s)
click to toggle source
Create a PgTimeWithTimeZone
from a string in Postgres format (ie “12:00:00+0800”).
# File lib/sqlpostgres/PgTimeWithTimeZone.rb, line 34 def from_sql(s) if s =~ /^(\d+):(\d+):(\d+)((?:\+|-)\d+)(?::(\d+))?$/ PgTimeWithTimeZone.new($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i) else raise ArgumentError, "Invalid time with time zone: #{s.inspect}" end end
new(hour = 0, minute = 0, second = 0, zone_hours = 0, zone_minutes = 0)
click to toggle source
Constructor.
- hour
-
0..23
- minute
-
0..59
[second}
0..59
zone_hours
-
The hours of the time-zone offset (-23..23)
zone_minutes
-
The seconds of the time-zone offset (0..60)
# File lib/sqlpostgres/PgTimeWithTimeZone.rb, line 57 def initialize(hour = 0, minute = 0, second = 0, zone_hours = 0, zone_minutes = 0) @hour = hour @minute = minute @second = second @zone_hours = zone_hours @zone_minutes = zone_minutes end
Public Instance Methods
to_s()
click to toggle source
Return a string representation (ie “12:00:00-07:00”).
# File lib/sqlpostgres/PgTimeWithTimeZone.rb, line 68 def to_s "%02d:%02d:%02d%+03d:%02d" % parts end
to_sql()
click to toggle source
Convert to sql format (ie “timestamp '2001-01-01 12:00:00'”).
# File lib/sqlpostgres/PgTimeWithTimeZone.rb, line 74 def to_sql "time with time zone '#{to_s}'" end
Protected Instance Methods
parts()
click to toggle source
# File lib/sqlpostgres/PgTimeWithTimeZone.rb, line 80 def parts [@hour, @minute, @second, @zone_hours, @zone_minutes] end
Private Instance Methods
column_type()
click to toggle source
# File lib/sqlpostgres/PgTimeWithTimeZone.rb, line 86 def column_type 'time with time zone' end