Class: DBI::Time
- Inherits:
-
Object
- Object
- DBI::Time
- Defined in:
- lib/dbi/utils.rb
Instance Attribute Summary collapse
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#minute ⇒ Object
(also: #min)
Returns the value of attribute minute.
-
#second ⇒ Object
(also: #sec)
Returns the value of attribute second.
Instance Method Summary collapse
-
#initialize(hour = 0, minute = 0, second = 0) ⇒ Time
constructor
DBI::Time.new(hour = 0, minute = 0, second = 0) DBI::Time.new(Time).
-
#to_s ⇒ Object
Returns a DBI::Time object as a string in HH:MM:SS format.
-
#to_time ⇒ Object
Returns a new Time object based on the hour, minute and second, using the current year, month and day.
Constructor Details
#initialize(hour = 0, minute = 0, second = 0) ⇒ Time
DBI::Time.new(hour = 0, minute = 0, second = 0) DBI::Time.new(Time)
Creates and returns a new DBI::Time object. Unlike the Time object in the standard library, accepts an hour, minute and second, or a Time object.
62 63 64 65 66 67 68 69 70 |
# File 'lib/dbi/utils.rb', line 62 def initialize(hour=0, minute=0, second=0) case hour when ::Time @hour, @minute, @second = hour.hour, hour.min, hour.sec @original_time = hour else @hour, @minute, @second = hour, minute, second end end |
Instance Attribute Details
#hour ⇒ Object
Returns the value of attribute hour.
54 55 56 |
# File 'lib/dbi/utils.rb', line 54 def hour @hour end |
#minute ⇒ Object Also known as: min
Returns the value of attribute minute.
54 55 56 |
# File 'lib/dbi/utils.rb', line 54 def minute @minute end |
#second ⇒ Object Also known as: sec
Returns the value of attribute second.
54 55 56 |
# File 'lib/dbi/utils.rb', line 54 def second @second end |
Instance Method Details
#to_s ⇒ Object
Returns a DBI::Time object as a string in HH:MM:SS format.
90 91 92 |
# File 'lib/dbi/utils.rb', line 90 def to_s sprintf("%02d:%02d:%02d", @hour, @minute, @second) end |
#to_time ⇒ Object
Returns a new Time object based on the hour, minute and second, using the current year, month and day. If a Time object was passed to the constructor, returns that object instead.
80 81 82 83 84 85 86 87 |
# File 'lib/dbi/utils.rb', line 80 def to_time if @original_time @original_time else t = ::Time.now ::Time.local(t.year, t.month, t.day, @hour, @minute, @second) end end |