parent
7101ecea94
commit
bd5c7f0889
|
@ -265,17 +265,17 @@ public class TimeValue implements Streamable {
|
||||||
long millis;
|
long millis;
|
||||||
String lowerSValue = sValue.toLowerCase(Locale.ROOT).trim();
|
String lowerSValue = sValue.toLowerCase(Locale.ROOT).trim();
|
||||||
if (lowerSValue.endsWith("ms")) {
|
if (lowerSValue.endsWith("ms")) {
|
||||||
millis = (long) (Double.parseDouble(lowerSValue.substring(0, lowerSValue.length() - 2)));
|
millis = parse(lowerSValue, 2, 1);
|
||||||
} else if (lowerSValue.endsWith("s")) {
|
} else if (lowerSValue.endsWith("s")) {
|
||||||
millis = (long) Double.parseDouble(lowerSValue.substring(0, lowerSValue.length() - 1)) * 1000;
|
millis = parse(lowerSValue, 1, 1000);
|
||||||
} else if (lowerSValue.endsWith("m")) {
|
} else if (lowerSValue.endsWith("m")) {
|
||||||
millis = (long) (Double.parseDouble(lowerSValue.substring(0, lowerSValue.length() - 1)) * 60 * 1000);
|
millis = parse(lowerSValue, 1, 60 * 1000);
|
||||||
} else if (lowerSValue.endsWith("h")) {
|
} else if (lowerSValue.endsWith("h")) {
|
||||||
millis = (long) (Double.parseDouble(lowerSValue.substring(0, lowerSValue.length() - 1)) * 60 * 60 * 1000);
|
millis = parse(lowerSValue, 1, 60 * 60 * 1000);
|
||||||
} else if (lowerSValue.endsWith("d")) {
|
} else if (lowerSValue.endsWith("d")) {
|
||||||
millis = (long) (Double.parseDouble(lowerSValue.substring(0, lowerSValue.length() - 1)) * 24 * 60 * 60 * 1000);
|
millis = parse(lowerSValue, 1, 24 * 60 * 60 * 1000);
|
||||||
} else if (lowerSValue.endsWith("w")) {
|
} else if (lowerSValue.endsWith("w")) {
|
||||||
millis = (long) (Double.parseDouble(lowerSValue.substring(0, lowerSValue.length() - 1)) * 7 * 24 * 60 * 60 * 1000);
|
millis = parse(lowerSValue, 1, 7 * 24 * 60 * 60 * 1000);
|
||||||
} else if (lowerSValue.equals("-1")) {
|
} else if (lowerSValue.equals("-1")) {
|
||||||
// Allow this special value to be unit-less:
|
// Allow this special value to be unit-less:
|
||||||
millis = -1;
|
millis = -1;
|
||||||
|
@ -292,6 +292,10 @@ public class TimeValue implements Streamable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long parse(String s, int suffixLength, long scale) {
|
||||||
|
return (long) (Double.parseDouble(s.substring(0, s.length() - suffixLength)) * scale);
|
||||||
|
}
|
||||||
|
|
||||||
static final long C0 = 1L;
|
static final long C0 = 1L;
|
||||||
static final long C1 = C0 * 1000L;
|
static final long C1 = C0 * 1000L;
|
||||||
static final long C2 = C1 * 1000L;
|
static final long C2 = C1 * 1000L;
|
||||||
|
|
Loading…
Reference in New Issue