Skip to content

Commit 2a6e686

Browse files
authored
Fix floating-point error when DateProcessor parses UNIX (#24947)
DateProcessor's DateFormat UNIX format parser resulted in a floating point rounding error when parsing certain stringed epoch times. Now Double.parseDouble is used, preserving the intented input.
1 parent 5bcae91 commit 2a6e686

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Function<String, DateTime> getFunction(String format, DateTimeZone timezone, Loc
3838
Unix {
3939
@Override
4040
Function<String, DateTime> getFunction(String format, DateTimeZone timezone, Locale locale) {
41-
return (date) -> new DateTime((long)(Float.parseFloat(date) * 1000), timezone);
41+
return (date) -> new DateTime((long)(Double.parseDouble(date) * 1000), timezone);
4242
}
4343
},
4444
UnixMs {

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateFormatTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public void testParseUnix() {
5050
assertThat(DateFormat.Unix.getFunction(null, DateTimeZone.UTC, null).apply("1000.5").getMillis(), equalTo(1000500L));
5151
}
5252

53+
public void testParseUnixWithMsPrecision() {
54+
assertThat(DateFormat.Unix.getFunction(null, DateTimeZone.UTC, null).apply("1495718015").getMillis(), equalTo(1495718015000L));
55+
}
56+
5357
public void testParseISO8601() {
5458
assertThat(DateFormat.Iso8601.getFunction(null, DateTimeZone.UTC, null).apply("2001-01-01T00:00:00-0800").getMillis(),
5559
equalTo(978336000000L));

0 commit comments

Comments
 (0)