Class: MysqlPR::Time
- Inherits:
-
Object
- Object
- MysqlPR::Time
- Defined in:
- lib/mysql-pr.rb
Overview
MySQL Time class
Instance Attribute Summary collapse
- #day ⇒ Integer
- #hour ⇒ Integer
- #minute ⇒ Integer (also: #min)
- #month ⇒ Integer (also: #mon)
-
#neg ⇒ Boolean
Negative flag.
- #second ⇒ Integer (also: #sec)
- #second_part ⇒ Integer
- #year ⇒ Integer
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, neg = false, second_part = 0) ⇒ Time
constructor
A new instance of Time.
- #inspect ⇒ Object
-
#to_i ⇒ Integer
YyyymmddHHMMSS.
-
#to_s ⇒ String
“yyyy-mm-dd HH:MM:SS”.
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.
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
#day ⇒ 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 |
#hour ⇒ 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 |
#minute ⇒ Integer Also known as: min
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 |
#month ⇒ Integer Also known as: mon
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 |
#neg ⇒ Boolean
Returns 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 |
#second ⇒ Integer Also known as: sec
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_part ⇒ 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 |
#year ⇒ 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
1116 1117 1118 |
# File 'lib/mysql-pr.rb', line 1116 def eql?(other) self == other end |
#inspect ⇒ Object
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_i ⇒ Integer
Returns 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_s ⇒ String
Returns “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 |