mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-19 19:35:02 +00:00
#19649 Makes m
case sensitive in TimeValue
Makes `m` case sensitive in TimeValue
This commit is contained in:
commit
bab3e766c7
@ -326,7 +326,10 @@ public class TimeValue implements Writeable {
|
|||||||
return new TimeValue(parse(sValue, normalized, 2), TimeUnit.MILLISECONDS);
|
return new TimeValue(parse(sValue, normalized, 2), TimeUnit.MILLISECONDS);
|
||||||
} else if (normalized.endsWith("s")) {
|
} else if (normalized.endsWith("s")) {
|
||||||
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.SECONDS);
|
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.SECONDS);
|
||||||
} else if (normalized.endsWith("m")) {
|
} else if (sValue.endsWith("m")) {
|
||||||
|
// parsing minutes should be case sensitive as `M` is generally
|
||||||
|
// accepted to mean months not minutes. This is the only case where
|
||||||
|
// the upper and lower case forms indicate different time units
|
||||||
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.MINUTES);
|
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.MINUTES);
|
||||||
} else if (normalized.endsWith("h")) {
|
} else if (normalized.endsWith("h")) {
|
||||||
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.HOURS);
|
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.HOURS);
|
||||||
|
@ -92,10 +92,6 @@ public class TimeValueTests extends ESTestCase {
|
|||||||
TimeValue.parseTimeValue("10 m", null, "test"));
|
TimeValue.parseTimeValue("10 m", null, "test"));
|
||||||
assertEquals(new TimeValue(10, TimeUnit.MINUTES),
|
assertEquals(new TimeValue(10, TimeUnit.MINUTES),
|
||||||
TimeValue.parseTimeValue("10m", null, "test"));
|
TimeValue.parseTimeValue("10m", null, "test"));
|
||||||
assertEquals(new TimeValue(10, TimeUnit.MINUTES),
|
|
||||||
TimeValue.parseTimeValue("10 M", null, "test"));
|
|
||||||
assertEquals(new TimeValue(10, TimeUnit.MINUTES),
|
|
||||||
TimeValue.parseTimeValue("10M", null, "test"));
|
|
||||||
|
|
||||||
assertEquals(new TimeValue(10, TimeUnit.HOURS),
|
assertEquals(new TimeValue(10, TimeUnit.HOURS),
|
||||||
TimeValue.parseTimeValue("10 h", null, "test"));
|
TimeValue.parseTimeValue("10 h", null, "test"));
|
||||||
@ -115,6 +111,17 @@ public class TimeValueTests extends ESTestCase {
|
|||||||
assertEquals(new TimeValue(10, TimeUnit.DAYS),
|
assertEquals(new TimeValue(10, TimeUnit.DAYS),
|
||||||
TimeValue.parseTimeValue("10D", null, "test"));
|
TimeValue.parseTimeValue("10D", null, "test"));
|
||||||
|
|
||||||
|
// Time values of months should throw an exception as months are not
|
||||||
|
// supported. Note that this is the only unit that is not case sensitive
|
||||||
|
// as `m` is the only character that is overloaded in terms of which
|
||||||
|
// time unit is expected between the upper and lower case versions
|
||||||
|
expectThrows(ElasticsearchParseException.class, () -> {
|
||||||
|
TimeValue.parseTimeValue("10 M", null, "test");
|
||||||
|
});
|
||||||
|
expectThrows(ElasticsearchParseException.class, () -> {
|
||||||
|
TimeValue.parseTimeValue("10M", null, "test");
|
||||||
|
});
|
||||||
|
|
||||||
final int length = randomIntBetween(0, 8);
|
final int length = randomIntBetween(0, 8);
|
||||||
final String zeros = new String(new char[length]).replace('\0', '0');
|
final String zeros = new String(new char[length]).replace('\0', '0');
|
||||||
assertTrue(TimeValue.parseTimeValue("-" + zeros + "1", null, "test") == TimeValue.MINUS_ONE);
|
assertTrue(TimeValue.parseTimeValue("-" + zeros + "1", null, "test") == TimeValue.MINUS_ONE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user