aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Zajc <marko@zajc.eu.org>2023-03-03 16:29:11 +0100
committerMarko Zajc <marko@zajc.eu.org>2023-03-03 16:29:11 +0100
commita5e657e018c7b16a42a373a15832e3ab6e801be6 (patch)
tree84c097e9f919bec403153e106cea479d8ab53a4e
parent446daea1d002b76fcd52d8a84fa99face679e40e (diff)
Prefer relative timestamps and treat numbers a without unit as seconds
-rw-r--r--src/main/java/libot/utils/ParseUtils.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main/java/libot/utils/ParseUtils.java b/src/main/java/libot/utils/ParseUtils.java
index 155728e..83b3d1f 100644
--- a/src/main/java/libot/utils/ParseUtils.java
+++ b/src/main/java/libot/utils/ParseUtils.java
@@ -83,15 +83,16 @@ public class ParseUtils {
83 } 83 }
84 84
85 public static long parseTime(String input) { 85 public static long parseTime(String input) {
86 long time = parseClock(input); 86 long time;
87 87 if (input.contains(":"))
88 if (time < 0) 88 time = parseClock(input);
89 else
89 time = parseRelativeTime(input); 90 time = parseRelativeTime(input);
90 91
91 if (time < 0) 92 if (time < 0)
92 throw new TimeParseException(); 93 throw new TimeParseException();
93 else 94 else
94 return time; // because parseRelativeTime is relative 95 return time;
95 } 96 }
96 97
97 private static long parseClock(String input) { 98 private static long parseClock(String input) {
@@ -138,11 +139,16 @@ public class ParseUtils {
138 }; 139 };
139 if (append) 140 if (append)
140 continue; 141 continue;
141 if (unit == null || durationBuffer.length() == 0) 142 if (unit == null || durationBuffer.length() == 0) // not a number and not a unit
142 return -1; 143 return -1;
143 duration += unit.toMillis(Long.parseLong(durationBuffer.toString())); 144 duration += unit.toMillis(Long.parseLong(durationBuffer.toString()));
144 durationBuffer.setLength(0); 145 durationBuffer.setLength(0);
145 } 146 }
147
148 if (durationBuffer.length() != 0)
149 duration += SECONDS.toMillis(Long.parseLong(durationBuffer.toString())); // any number without unit is
150 // treated as seconds
151
146 return duration; 152 return duration;
147 } 153 }
148 154