Class: Mysql::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/mysql.rb,
ext/mysql/ext.c

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.

Parameters:

  • year (Integer) (defaults to: 0)
  • month (Integer) (defaults to: 0)
  • day (Integer) (defaults to: 0)
  • hour (Integer) (defaults to: 0)
  • minute (Integer) (defaults to: 0)
  • second (Integer) (defaults to: 0)
  • neg (Boolean) (defaults to: false)

    negative flag

  • second_part (Integer) (defaults to: 0)


1057
1058
1059
1060
1061
# File 'lib/mysql.rb', line 1057

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

Instance Attribute Details

#dayInteger

Returns:

  • (Integer)


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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/mysql.rb', line 1048

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

#hourInteger

Returns:

  • (Integer)


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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/mysql.rb', line 1048

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

#minuteInteger Also known as: min

Returns:

  • (Integer)


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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/mysql.rb', line 1048

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

#monthInteger Also known as: mon

Returns:

  • (Integer)


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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/mysql.rb', line 1048

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

#negBoolean

Returns negative flag.

Returns:

  • (Boolean)

    negative flag



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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/mysql.rb', line 1048

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

#secondInteger Also known as: sec

Returns:

  • (Integer)


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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/mysql.rb', line 1048

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

#second_partInteger

Returns:

  • (Integer)


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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/mysql.rb', line 1048

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

#yearInteger

Returns:

  • (Integer)


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
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'lib/mysql.rb', line 1048

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

Instance Method Details

#==(other) ⇒ Object



1068
1069
1070
1071
1072
1073
# File 'lib/mysql.rb', line 1068

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)


1076
1077
1078
# File 'lib/mysql.rb', line 1076

def eql?(other)
  self == other
end

#inspectObject



1098
1099
1100
# File 'lib/mysql.rb', line 1098

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

#to_iInteger

Returns yyyymmddHHMMSS.

Returns:

  • (Integer)

    yyyymmddHHMMSS



1093
1094
1095
# File 'lib/mysql.rb', line 1093

def to_i
  sprintf("%04d%02d%02d%02d%02d%02d", year, mon, day, hour, min, sec).to_i
end

#to_sString

Returns “yyyy-mm-dd HH:MM:SS”.

Returns:

  • (String)

    "yyyy-mm-dd HH:MM:SS"



1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
# File 'lib/mysql.rb', line 1081

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