class SqlPostgres::PgTime
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)
Public Class Methods
from_sql(s)
click to toggle source
Create a PgTime
from a string in Postgres format (ie “12:00:00”).
# File lib/sqlpostgres/PgTime.rb, line 25 def from_sql(s) PgTime.new(*s.split(":").collect do |p| p.to_i end) end
new(hour = 0, minute = 0, second = 0)
click to toggle source
Constructor taking hour (0..23), minute (0..59), and second (0..59)
# File lib/sqlpostgres/PgTime.rb, line 33 def initialize(hour = 0, minute = 0, second = 0) @hour = hour @minute = minute @second = second end
Public Instance Methods
to_local_time()
click to toggle source
Convert to an instance of Time on date 1970/01/01, local time zone.
# File lib/sqlpostgres/PgTime.rb, line 47 def to_local_time Time.local(1970, 1, 1, @hour, @minute, @second) end
to_s()
click to toggle source
Return a string representation (ie “12:00:00”).
# File lib/sqlpostgres/PgTime.rb, line 41 def to_s "%02d:%02d:%02d" % [@hour, @minute, @second] end
to_utc_time()
click to toggle source
Convert to an instance of Time on date 1970/01/01, utc time zone.
# File lib/sqlpostgres/PgTime.rb, line 53 def to_utc_time Time.utc(1970, 1, 1, @hour, @minute, @second) end
Protected Instance Methods
parts()
click to toggle source
# File lib/sqlpostgres/PgTime.rb, line 59 def parts [hour, minute, second] end
Private Instance Methods
column_type()
click to toggle source
# File lib/sqlpostgres/PgTime.rb, line 65 def column_type 'time' end