Class: SqlPostgres::PgTime
Overview
This class holds the value of a “time” column.
Instance Attribute Summary collapse
-
#hour ⇒ Object
readonly
Return the hour (0..23).
-
#minute ⇒ Object
readonly
Return the minute (0..59).
-
#second ⇒ Object
readonly
Return the second (0..59).
Class Method Summary collapse
-
.from_sql(s) ⇒ Object
Create a PgTime from a string in Postgres format (ie “12:00:00”).
Instance Method Summary collapse
-
#initialize(hour = 0, minute = 0, second = 0) ⇒ PgTime
constructor
Constructor taking hour (0..23), minute (0..59), and second (0..59).
-
#to_local_time ⇒ Object
Convert to an instance of Time on date 1970/01/01, local time zone.
-
#to_s ⇒ Object
Return a string representation (ie “12:00:00”).
-
#to_utc_time ⇒ Object
Convert to an instance of Time on date 1970/01/01, utc time zone.
Methods inherited from PgType
Constructor Details
#initialize(hour = 0, minute = 0, second = 0) ⇒ PgTime
Constructor taking hour (0..23), minute (0..59), and second (0..59)
33 34 35 36 37 |
# File 'lib/sqlpostgres/PgTime.rb', line 33 def initialize(hour = 0, minute = 0, second = 0) @hour = hour @minute = minute @second = second end |
Instance Attribute Details
#hour ⇒ Object (readonly)
Return the hour (0..23)
11 12 13 |
# File 'lib/sqlpostgres/PgTime.rb', line 11 def hour @hour end |
#minute ⇒ Object (readonly)
Return the minute (0..59)
15 16 17 |
# File 'lib/sqlpostgres/PgTime.rb', line 15 def minute @minute end |
#second ⇒ Object (readonly)
Return the second (0..59)
19 20 21 |
# File 'lib/sqlpostgres/PgTime.rb', line 19 def second @second end |
Class Method Details
Instance Method Details
#to_local_time ⇒ Object
Convert to an instance of Time on date 1970/01/01, local time zone.
47 48 49 |
# File 'lib/sqlpostgres/PgTime.rb', line 47 def to_local_time Time.local(1970, 1, 1, @hour, @minute, @second) end |
#to_s ⇒ Object
Return a string representation (ie “12:00:00”).
41 42 43 |
# File 'lib/sqlpostgres/PgTime.rb', line 41 def to_s "%02d:%02d:%02d" % [@hour, @minute, @second] end |
#to_utc_time ⇒ Object
Convert to an instance of Time on date 1970/01/01, utc time zone.
53 54 55 |
# File 'lib/sqlpostgres/PgTime.rb', line 53 def to_utc_time Time.utc(1970, 1, 1, @hour, @minute, @second) end |