Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ public static TimeValue parseTimeValue(String sValue, TimeValue defaultValue, St
return new TimeValue(parse(sValue, normalized, 2), TimeUnit.MILLISECONDS);
} else if (normalized.endsWith("s")) {
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);
} else if (normalized.endsWith("h")) {
return new TimeValue(parse(sValue, normalized, 1), TimeUnit.HOURS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ public void testParseTimeValue() {
TimeValue.parseTimeValue("10 m", null, "test"));
assertEquals(new TimeValue(10, TimeUnit.MINUTES),
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),
TimeValue.parseTimeValue("10 h", null, "test"));
Expand All @@ -115,6 +111,17 @@ public void testParseTimeValue() {
assertEquals(new TimeValue(10, TimeUnit.DAYS),
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 String zeros = new String(new char[length]).replace('\0', '0');
assertTrue(TimeValue.parseTimeValue("-" + zeros + "1", null, "test") == TimeValue.MINUS_ONE);
Expand Down