Class: Mysql::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql.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.



735
736
737
738
# File 'lib/mysql.rb', line 735

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.



739
740
741
# File 'lib/mysql.rb', line 739

def day
  @day
end

#hourObject

Returns the value of attribute hour.



739
740
741
# File 'lib/mysql.rb', line 739

def hour
  @hour
end

#minuteObject Also known as: min

Returns the value of attribute minute.



739
740
741
# File 'lib/mysql.rb', line 739

def minute
  @minute
end

#monthObject Also known as: mon

Returns the value of attribute month.



739
740
741
# File 'lib/mysql.rb', line 739

def month
  @month
end

#negObject

Returns the value of attribute neg.



739
740
741
# File 'lib/mysql.rb', line 739

def neg
  @neg
end

#secondObject Also known as: sec

Returns the value of attribute second.



739
740
741
# File 'lib/mysql.rb', line 739

def second
  @second
end

#second_partObject

Returns the value of attribute second_part.



739
740
741
# File 'lib/mysql.rb', line 739

def second_part
  @second_part
end

#yearObject

Returns the value of attribute year.



739
740
741
# File 'lib/mysql.rb', line 739

def year
  @year
end

Instance Method Details

#==(other) ⇒ Object



744
745
746
747
748
749
# File 'lib/mysql.rb', line 744

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)


751
752
753
# File 'lib/mysql.rb', line 751

def eql?(other)
  self == other
end

#to_sObject



755
756
757
758
759
760
761
762
# File 'lib/mysql.rb', line 755

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