Skip to content

Commit

Permalink
Change the milliseconds precision to 3 digits for intervals. (elastic…
Browse files Browse the repository at this point in the history
…#38297)

(cherry picked from commit cea81b1)
  • Loading branch information
astefan committed Feb 5, 2019
1 parent c5bccb1 commit d0fb8dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public static TemporalAmount negate(TemporalAmount interval) {
int MAX_HOUR = 23;
int MAX_MINUTE = 59;
int MAX_SECOND = 59;
int MAX_MILLI = 999999999;
int MAX_MILLI = 999;

char DOT = '.';
char SPACE = ' ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testMinuteInterval() throws Exception {

public void testSecondInterval() throws Exception {
int randomSeconds = randomNonNegativeInt();
int randomMillis = randomBoolean() ? (randomBoolean() ? 0 : 999999999) : randomInt(999999999);
int randomMillis = randomBoolean() ? (randomBoolean() ? 0 : 999) : randomInt(999);
String value = format(Locale.ROOT, "%s%d.%d", sign, randomSeconds, randomMillis);
TemporalAmount amount = parseInterval(EMPTY, value, INTERVAL_SECOND);
assertEquals(maybeNegate(sign, Duration.ofSeconds(randomSeconds).plusMillis(randomMillis)), amount);
Expand Down Expand Up @@ -128,7 +128,7 @@ public void testDayToSecond() throws Exception {
int randomSecond = randomInt(59);

boolean withMillis = randomBoolean();
int randomMilli = withMillis ? randomInt(999999999) : 0;
int randomMilli = withMillis ? randomInt(999) : 0;
String millisString = withMillis ? "." + randomMilli : "";

String value = format(Locale.ROOT, "%s%d %d:%d:%d%s", sign, randomDay, randomHour, randomMinute, randomSecond, millisString);
Expand All @@ -151,7 +151,7 @@ public void testHourToSecond() throws Exception {
int randomSecond = randomInt(59);

boolean withMillis = randomBoolean();
int randomMilli = withMillis ? randomInt(999999999) : 0;
int randomMilli = withMillis ? randomInt(999) : 0;
String millisString = withMillis ? "." + randomMilli : "";

String value = format(Locale.ROOT, "%s%d:%d:%d%s", sign, randomHour, randomMinute, randomSecond, millisString);
Expand All @@ -165,7 +165,7 @@ public void testMinuteToSecond() throws Exception {
int randomSecond = randomInt(59);

boolean withMillis = randomBoolean();
int randomMilli = withMillis ? randomInt(999999999) : 0;
int randomMilli = withMillis ? randomInt(999) : 0;
String millisString = withMillis ? "." + randomMilli : "";

String value = format(Locale.ROOT, "%s%d:%d%s", sign, randomMinute, randomSecond, millisString);
Expand All @@ -186,11 +186,11 @@ public void testYearToMonthTooBig() throws Exception {

public void testMillisTooBig() throws Exception {
int randomSeconds = randomNonNegativeInt();
int millisTooLarge = 1234567890;
int millisTooLarge = 1234;
String value = format(Locale.ROOT, "%s%d.%d", sign, randomSeconds, millisTooLarge);
ParsingException pe = expectThrows(ParsingException.class, () -> parseInterval(EMPTY, value, INTERVAL_SECOND));
assertEquals("line -1:0: Invalid [INTERVAL SECOND] value [" + value + "]: [MILLISECOND] unit has illegal value [" + millisTooLarge
+ "], expected a positive number up to [999999999]", pe.getMessage());
+ "], expected a positive number up to [999]", pe.getMessage());
}

public void testDayToMinuteTooBig() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void testStringInterval() throws Exception {
int randomHour = randomInt(23);
int randomMinute = randomInt(59);
int randomSecond = randomInt(59);
int randomMilli = randomInt(999999999);
int randomMilli = randomInt(999);

String value = format(Locale.ROOT, "INTERVAL '%d %d:%d:%d.%d' DAY TO SECOND", randomDay, randomHour, randomMinute, randomSecond,
randomMilli);
Expand All @@ -163,7 +163,7 @@ public void testNegativeStringInterval() throws Exception {
int randomHour = randomInt(23);
int randomMinute = randomInt(59);
int randomSecond = randomInt(59);
int randomMilli = randomInt(999999999);
int randomMilli = randomInt(999);

String value = format(Locale.ROOT, "INTERVAL -'%d %d:%d:%d.%d' DAY TO SECOND", randomDay, randomHour, randomMinute, randomSecond,
randomMilli);
Expand Down

0 comments on commit d0fb8dc

Please sign in to comment.