Method: Mysql::Time#second_part

Defined in:
lib/vendor/mysql.rb,
lib/vendor/mysql.rb

#second_partInteger

Returns:

  • (Integer)


1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
# File 'lib/vendor/mysql.rb', line 1037

class Time
  # @param [Integer] year
  # @param [Integer] month
  # @param [Integer] day
  # @param [Integer] hour
  # @param [Integer] minute
  # @param [Integer] second
  # @param [Boolean] neg negative flag
  # @param [Integer] second_part
  def initialize(year=0, month=0, day=0, hour=0, minute=0, second=0, neg=false, second_part=0)
    @date_flag = !(hour && minute && second)
    @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
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part
  alias mon month
  alias min minute
  alias sec second

  # @private
  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

  # @private
  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      sprintf "%04d-%02d-%02d", year, mon, day
    elsif 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

  # @return [Integer] yyyymmddHHMMSS
  def to_i
    sprintf("%04d%02d%02d%02d%02d%02d", year, mon, day, hour, min, sec).to_i
  end

  # @private
  def inspect
    sprintf "#<#{self.class.name}:%04d-%02d-%02d %02d:%02d:%02d>", year, mon, day, hour, min, sec
  end

end