do not ignore ms in ruby time (#6217)

This commit is contained in:
Himanshu 2018-08-23 14:09:31 -07:00 committed by Gian Merlino
parent 6e73ad6231
commit ddb26f2696
2 changed files with 5 additions and 5 deletions

View File

@ -79,7 +79,6 @@ public class TimestampParser
return numericFun.apply(Long.parseLong(ParserUtils.stripQuotes(input)));
};
} else if ("ruby".equalsIgnoreCase(format)) {
// Numeric parser ignores millis for ruby.
final Function<Number, DateTime> numericFun = createNumericTimestampParser(format);
return input -> {
Preconditions.checkArgument(!Strings.isNullOrEmpty(input), "null timestamp");
@ -103,11 +102,12 @@ public class TimestampParser
final String format
)
{
// Ignore millis for ruby
if ("posix".equalsIgnoreCase(format) || "ruby".equalsIgnoreCase(format)) {
if ("posix".equalsIgnoreCase(format)) {
return input -> DateTimes.utc(TimeUnit.SECONDS.toMillis(input.longValue()));
} else if ("nano".equalsIgnoreCase(format)) {
return input -> DateTimes.utc(TimeUnit.NANOSECONDS.toMillis(input.longValue()));
} else if ("ruby".equalsIgnoreCase(format)) {
return input -> DateTimes.utc(Double.valueOf(input.doubleValue() * 1000).longValue());
} else {
return input -> DateTimes.utc(input.longValue());
}

View File

@ -97,8 +97,8 @@ public class TimestampParserTest
public void testRuby()
{
final Function<Object, DateTime> parser = TimestampParser.createObjectTimestampParser("ruby");
Assert.assertEquals(DateTimes.of("2013-01-16T15:41:47+01:00"), parser.apply("1358347307.435447"));
Assert.assertEquals(DateTimes.of("2013-01-16T15:41:47+01:00"), parser.apply(1358347307.435447D));
Assert.assertEquals(DateTimes.of("2013-01-16T14:41:47.435Z"), parser.apply("1358347307.435447"));
Assert.assertEquals(DateTimes.of("2013-01-16T14:41:47.435Z"), parser.apply(1358347307.435447D));
}
@Test