Skip to content

Commit

Permalink
Fix floating-point error when DateProcessor parses UNIX (#24947)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
talevy committed May 30, 2017
1 parent 5bcae91 commit 2a6e686
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Expand Up @@ -38,7 +38,7 @@ Function<String, DateTime> getFunction(String format, DateTimeZone timezone, Loc
Unix {
@Override
Function<String, DateTime> getFunction(String format, DateTimeZone timezone, Locale locale) {
return (date) -> new DateTime((long)(Float.parseFloat(date) * 1000), timezone);
return (date) -> new DateTime((long)(Double.parseDouble(date) * 1000), timezone);
}
},
UnixMs {
Expand Down
Expand Up @@ -50,6 +50,10 @@ public void testParseUnix() {
assertThat(DateFormat.Unix.getFunction(null, DateTimeZone.UTC, null).apply("1000.5").getMillis(), equalTo(1000500L));
}

public void testParseUnixWithMsPrecision() {
assertThat(DateFormat.Unix.getFunction(null, DateTimeZone.UTC, null).apply("1495718015").getMillis(), equalTo(1495718015000L));
}

public void testParseISO8601() {
assertThat(DateFormat.Iso8601.getFunction(null, DateTimeZone.UTC, null).apply("2001-01-01T00:00:00-0800").getMillis(),
equalTo(978336000000L));
Expand Down

0 comments on commit 2a6e686

Please sign in to comment.