时间解析修复

This commit is contained in:
wangshilong 2024-12-10 16:53:09 +08:00
parent b1aae0b189
commit 3c31c70070
1 changed files with 12 additions and 13 deletions

View File

@ -1,7 +1,6 @@
package com.isu.gaswellwatch.vo.command; package com.isu.gaswellwatch.vo.command;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.time.LocalTime; import java.time.LocalTime;
@ -24,14 +23,14 @@ public interface Timing {
String[] times = StringUtils.split(time, ":"); String[] times = StringUtils.split(time, ":");
int hour = 0, minute = 0, second = 0; int hour = 0, minute = 0, second = 0;
if (times.length == 1) { if (times.length == 1) {
hour = NumberUtils.createInteger(times[0]); hour = Integer.parseInt(times[0]);
} else if (times.length == 2) { } else if (times.length == 2) {
hour = NumberUtils.createInteger(times[0]); hour = Integer.parseInt(times[0]);
minute = NumberUtils.createInteger(times[1]); minute = Integer.parseInt(times[1]);
} else if (times.length == 3) { } else if (times.length == 3) {
hour = NumberUtils.createInteger(times[0]); hour = Integer.parseInt(times[0]);
minute = NumberUtils.createInteger(times[1]); minute = Integer.parseInt(times[1]);
second = NumberUtils.createInteger(times[2]); second = Integer.parseInt(times[2]);
} else { } else {
throw new InvalidParameterException(name + " is invalid. Valid format: [0-" + maxHours + "]:[0-59]:[0-59]"); throw new InvalidParameterException(name + " is invalid. Valid format: [0-" + maxHours + "]:[0-59]:[0-59]");
} }
@ -93,16 +92,16 @@ public interface Timing {
int hours = 0, minutes = 0, seconds = 0; int hours = 0, minutes = 0, seconds = 0;
switch (values.length) { switch (values.length) {
case 1 -> { case 1 -> {
seconds = NumberUtils.createInteger(values[0]); seconds = Integer.parseInt(values[0]);
} }
case 2 -> { case 2 -> {
minutes = NumberUtils.createInteger(values[0]); minutes = Integer.parseInt(values[0]);
seconds = NumberUtils.createInteger(values[1]); seconds = Integer.parseInt(values[1]);
} }
case 3 -> { case 3 -> {
hours = NumberUtils.createInteger(values[0]); hours = Integer.parseInt(values[0]);
minutes = NumberUtils.createInteger(values[1]); minutes = Integer.parseInt(values[1]);
seconds = NumberUtils.createInteger(values[2]); seconds = Integer.parseInt(values[2]);
} }
default -> { default -> {
throw new RuntimeException("格式不合法"); throw new RuntimeException("格式不合法");