Class: MysqlPR::Time

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

Overview

MySQL Time class

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)


1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
# File 'lib/mysql-pr.rb', line 1097

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 = year.to_i
  @month = month.to_i
  @day = day.to_i
  @hour = hour.to_i
  @minute = minute.to_i
  @second = second.to_i
  @neg = neg
  @second_part = second_part.to_i
end

Instance Attribute Details

#dayInteger

Returns:

  • (Integer)


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/mysql-pr.rb', line 1082

class Time
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part

  alias mon month
  alias min minute
  alias sec second

  # @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 = year.to_i
    @month = month.to_i
    @day = day.to_i
    @hour = hour.to_i
    @minute = minute.to_i
    @second = second.to_i
    @neg = neg
    @second_part = second_part.to_i
  end

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

  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      format("%04d-%02d-%02d", year, mon, day)
    elsif year.zero? && mon.zero? && day.zero?
      h = neg ? hour * -1 : hour
      format("%02d:%02d:%02d", h, min, sec)
    else
      format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
    end
  end

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

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

#hourInteger

Returns:

  • (Integer)


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/mysql-pr.rb', line 1082

class Time
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part

  alias mon month
  alias min minute
  alias sec second

  # @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 = year.to_i
    @month = month.to_i
    @day = day.to_i
    @hour = hour.to_i
    @minute = minute.to_i
    @second = second.to_i
    @neg = neg
    @second_part = second_part.to_i
  end

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

  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      format("%04d-%02d-%02d", year, mon, day)
    elsif year.zero? && mon.zero? && day.zero?
      h = neg ? hour * -1 : hour
      format("%02d:%02d:%02d", h, min, sec)
    else
      format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
    end
  end

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

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

#minuteInteger Also known as: min

Returns:

  • (Integer)


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/mysql-pr.rb', line 1082

class Time
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part

  alias mon month
  alias min minute
  alias sec second

  # @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 = year.to_i
    @month = month.to_i
    @day = day.to_i
    @hour = hour.to_i
    @minute = minute.to_i
    @second = second.to_i
    @neg = neg
    @second_part = second_part.to_i
  end

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

  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      format("%04d-%02d-%02d", year, mon, day)
    elsif year.zero? && mon.zero? && day.zero?
      h = neg ? hour * -1 : hour
      format("%02d:%02d:%02d", h, min, sec)
    else
      format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
    end
  end

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

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

#monthInteger Also known as: mon

Returns:

  • (Integer)


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/mysql-pr.rb', line 1082

class Time
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part

  alias mon month
  alias min minute
  alias sec second

  # @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 = year.to_i
    @month = month.to_i
    @day = day.to_i
    @hour = hour.to_i
    @minute = minute.to_i
    @second = second.to_i
    @neg = neg
    @second_part = second_part.to_i
  end

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

  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      format("%04d-%02d-%02d", year, mon, day)
    elsif year.zero? && mon.zero? && day.zero?
      h = neg ? hour * -1 : hour
      format("%02d:%02d:%02d", h, min, sec)
    else
      format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
    end
  end

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

  def inspect
    format("#<#{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



1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/mysql-pr.rb', line 1082

class Time
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part

  alias mon month
  alias min minute
  alias sec second

  # @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 = year.to_i
    @month = month.to_i
    @day = day.to_i
    @hour = hour.to_i
    @minute = minute.to_i
    @second = second.to_i
    @neg = neg
    @second_part = second_part.to_i
  end

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

  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      format("%04d-%02d-%02d", year, mon, day)
    elsif year.zero? && mon.zero? && day.zero?
      h = neg ? hour * -1 : hour
      format("%02d:%02d:%02d", h, min, sec)
    else
      format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
    end
  end

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

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

#secondInteger Also known as: sec

Returns:

  • (Integer)


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/mysql-pr.rb', line 1082

class Time
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part

  alias mon month
  alias min minute
  alias sec second

  # @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 = year.to_i
    @month = month.to_i
    @day = day.to_i
    @hour = hour.to_i
    @minute = minute.to_i
    @second = second.to_i
    @neg = neg
    @second_part = second_part.to_i
  end

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

  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      format("%04d-%02d-%02d", year, mon, day)
    elsif year.zero? && mon.zero? && day.zero?
      h = neg ? hour * -1 : hour
      format("%02d:%02d:%02d", h, min, sec)
    else
      format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
    end
  end

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

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

#second_partInteger

Returns:

  • (Integer)


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/mysql-pr.rb', line 1082

class Time
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part

  alias mon month
  alias min minute
  alias sec second

  # @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 = year.to_i
    @month = month.to_i
    @day = day.to_i
    @hour = hour.to_i
    @minute = minute.to_i
    @second = second.to_i
    @neg = neg
    @second_part = second_part.to_i
  end

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

  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      format("%04d-%02d-%02d", year, mon, day)
    elsif year.zero? && mon.zero? && day.zero?
      h = neg ? hour * -1 : hour
      format("%02d:%02d:%02d", h, min, sec)
    else
      format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
    end
  end

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

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

#yearInteger

Returns:

  • (Integer)


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
# File 'lib/mysql-pr.rb', line 1082

class Time
  attr_accessor :year, :month, :day, :hour, :minute, :second, :neg, :second_part

  alias mon month
  alias min minute
  alias sec second

  # @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 = year.to_i
    @month = month.to_i
    @day = day.to_i
    @hour = hour.to_i
    @minute = minute.to_i
    @second = second.to_i
    @neg = neg
    @second_part = second_part.to_i
  end

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

  def eql?(other)
    self == other
  end

  # @return [String] "yyyy-mm-dd HH:MM:SS"
  def to_s
    if @date_flag
      format("%04d-%02d-%02d", year, mon, day)
    elsif year.zero? && mon.zero? && day.zero?
      h = neg ? hour * -1 : hour
      format("%02d:%02d:%02d", h, min, sec)
    else
      format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
    end
  end

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

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

Instance Method Details

#==(other) ⇒ Object



1109
1110
1111
1112
1113
1114
# File 'lib/mysql-pr.rb', line 1109

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


1116
1117
1118
# File 'lib/mysql-pr.rb', line 1116

def eql?(other)
  self == other
end

#inspectObject



1137
1138
1139
# File 'lib/mysql-pr.rb', line 1137

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

#to_iInteger

Returns yyyymmddHHMMSS.

Returns:

  • (Integer)

    yyyymmddHHMMSS



1133
1134
1135
# File 'lib/mysql-pr.rb', line 1133

def to_i
  format("%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”



1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
# File 'lib/mysql-pr.rb', line 1121

def to_s
  if @date_flag
    format("%04d-%02d-%02d", year, mon, day)
  elsif year.zero? && mon.zero? && day.zero?
    h = neg ? hour * -1 : hour
    format("%02d:%02d:%02d", h, min, sec)
  else
    format("%04d-%02d-%02d %02d:%02d:%02d", year, mon, day, hour, min, sec)
  end
end