-
Notifications
You must be signed in to change notification settings - Fork 477
fromInfluxDBTimeFormat does not parse milliseconds correct #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
TLDR: When you execute a query using the InfluxDB Java client, always specify the TimeUnit parameter and never parse the RFC3339 date format returned by InfluxDB. This seems to be related with how InfluxDB (in fact, Go lang) uses the RFC3339 for date formatting and how java.text.SimpleDateFormat (used by this library) differs from the first. <short-version>
</short-version> You can test it by yourself:
The time 1497600000030000000 is in nanoseconds and it is the same one provided in the previous comment. Now let's see how InfluxDB is formatting a date using RFC3339. Accordingly with the InfluxDB documentation:
Remember, the issue here is with the milliseconds representation (trimmed to .03). Now try to execute the following code (output added as comment): public class Main {
public static void main(String[] args) {
long time = TimeUnit.NANOSECONDS.toMillis(1497600000030000000L);
// 2017-06-16T10:00:00.30Z
System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S'Z'").format(time));
// 2017-06-16T10:00:00.30Z
System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'").format(time));
// 2017-06-16T10:00:00.030Z
System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(time));
// 2017-06-16T10:00:00.0030Z
System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'").format(time));
// 2017-06-16T10:00:00.00030Z
System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSS'Z'").format(time));
// 2017-06-16T10:00:00.000030Z
System.out.println(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'").format(time));
// SAME REPRESENTATION AS INFLUXDB: 2017-06-16T08:00:00.03Z
DateTimeFormatter rfc3339Format = new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd'T'HH:mm:ss")
.appendFraction(ChronoField.MILLI_OF_SECOND, 0, 6, true)
.appendPattern("X")
.toFormatter();
System.out.println(rfc3339Format.withZone(ZoneOffset.UTC).format(Instant.ofEpochMilli(time)));
}
} |
@majst01 IMO, org.influxdb.impl.TimeUtil should be deprecated and removed later. The developer should be responsible for dealing with date/time conversion. What do you think? Meanwhile, a patch could be applied by replacing SimpleDateFormat with DateTimeFormatterBuilder and fractions of millisecs. |
If a timestamp has a 10-millisecond time (last digit 0), the returned milliseconds time is not correct.
.time(1497600000030L, TimeUnit.MILLISECONDS)
after reading from database:
fromInfluxDBTimeFormat(raw.get(0).toString()) returns "1497600000003"
the database contains "2017-06-16T08:00:00.03Z"
The text was updated successfully, but these errors were encountered: