Class: DBI::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/dbi/utils/time.rb

Overview

Represents a Time

DEPRECATED: Please use a regular Time or DateTime object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hourObject

Returns the value of attribute hour



7
8
9
# File 'lib/dbi/utils/time.rb', line 7

def hour
  @hour
end

#minuteObject Also known as: min

Returns the value of attribute minute



7
8
9
# File 'lib/dbi/utils/time.rb', line 7

def minute
  @minute
end

#secondObject Also known as: sec

Returns the value of attribute second



7
8
9
# File 'lib/dbi/utils/time.rb', line 7

def second
  @second
end

Instance Method Details

#to_sObject

Returns a DBI::Time object as a string in HH:MM:SS format.



48
49
50
# File 'lib/dbi/utils/time.rb', line 48

def to_s
   sprintf("%02d:%02d:%02d", @hour, @minute, @second)
end

#to_timeObject

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.



38
39
40
41
42
43
44
45
# File 'lib/dbi/utils/time.rb', line 38

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