Class: Mysql::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/ffi-mysql/time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, neg = false, second_part = 0) ⇒ Time

Returns a new instance of Time.



3
4
5
6
# File 'lib/ffi-mysql/time.rb', line 3

def initialize(year=0, month=0, day=0, hour=0, minute=0, second=0, neg=false, second_part=0)
    @year, @month, @day, @hour, @minute, @second, @neg, @second_part =
        year.to_i, month.to_i, day.to_i, hour.to_i, minute.to_i, second.to_i, neg, second_part.to_i
end

Instance Attribute Details

#dayObject

Returns the value of attribute day.



7
8
9
# File 'lib/ffi-mysql/time.rb', line 7

def day
  @day
end

#hourObject

Returns the value of attribute hour.



7
8
9
# File 'lib/ffi-mysql/time.rb', line 7

def hour
  @hour
end

#minuteObject Also known as: min

Returns the value of attribute minute.



7
8
9
# File 'lib/ffi-mysql/time.rb', line 7

def minute
  @minute
end

#monthObject Also known as: mon

Returns the value of attribute month.



7
8
9
# File 'lib/ffi-mysql/time.rb', line 7

def month
  @month
end

#negObject

Returns the value of attribute neg.



7
8
9
# File 'lib/ffi-mysql/time.rb', line 7

def neg
  @neg
end

#secondObject Also known as: sec

Returns the value of attribute second.



7
8
9
# File 'lib/ffi-mysql/time.rb', line 7

def second
  @second
end

#second_partObject

Returns the value of attribute second_part.



7
8
9
# File 'lib/ffi-mysql/time.rb', line 7

def second_part
  @second_part
end

#yearObject

Returns the value of attribute year.



7
8
9
# File 'lib/ffi-mysql/time.rb', line 7

def year
  @year
end

Instance Method Details

#==(other) ⇒ Object



12
13
14
15
16
17
# File 'lib/ffi-mysql/time.rb', line 12

def ==(other)
    other.is_a?(Mysql::Time) &&
        @year == other.year && @month == other.month && @day == other.day &&
        @hour == other.hour && @minute == other.minute && @second == other.second &&
        @neg == neg && @second_part == other.second_part
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ffi-mysql/time.rb', line 19

def eql?(other)
    self == other
end

#to_sObject



23
24
25
26
27
28
29
30
# File 'lib/ffi-mysql/time.rb', line 23

def to_s
    if year == 0 and mon == 0 and day == 0
        h = neg ? hour * -1 : hour
        sprintf "%02d:%02d:%02d", h, min, sec
    else
        sprintf "%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec
    end
end