From f377905005b9f7fc7640549c621f6f33d06d793c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bedn=C3=A1=C5=99?= Date: Thu, 15 Sep 2022 13:56:13 +0200 Subject: [PATCH] feat: add possibility to get time from `Point` (#419) --- CHANGELOG.md | 3 +++ .../main/java/com/influxdb/client/write/Point.java | 8 ++++++++ .../java/com/influxdb/client/write/PointTest.java | 13 +++++++++++++ 3 files changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdeaadd3974..94c8425526e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 6.6.0 [unreleased] +### Features +1. [#419](https://github.com/influxdata/influxdb-client-java/pull/419): Add possibility to get time from `Point` data structure + ### Documentation 1. [#406](https://github.com/influxdata/influxdb-client-java/pull/406): Fix compatibility of the `doclint` between JDK 8 and JDK 18 diff --git a/client/src/main/java/com/influxdb/client/write/Point.java b/client/src/main/java/com/influxdb/client/write/Point.java index 394d288982f..cc0d38c4d25 100644 --- a/client/src/main/java/com/influxdb/client/write/Point.java +++ b/client/src/main/java/com/influxdb/client/write/Point.java @@ -253,6 +253,14 @@ public Point time(@Nullable final Long time, @Nonnull final WritePrecision preci return time((Number) time, precision); } + /** + * @return the data point timestamp + */ + @Nullable + public Number getTime() { + return time; + } + /** * @return the data point precision */ diff --git a/client/src/test/java/com/influxdb/client/write/PointTest.java b/client/src/test/java/com/influxdb/client/write/PointTest.java index 5b7adcc300f..2f5c9f68b82 100644 --- a/client/src/test/java/com/influxdb/client/write/PointTest.java +++ b/client/src/test/java/com/influxdb/client/write/PointTest.java @@ -293,6 +293,19 @@ void timeInstantNull() { Assertions.assertThat(point.toLineProtocol()).isEqualTo("h2o,location=europe level=2i"); } + @Test + void timeGetTime() { + + Instant time = Instant.parse("2022-06-12T10:26:03.800123456Z"); + + Point point = Point.measurement("h2o") + .addTag("location", "europe") + .addField("level", 2) + .time(time, WritePrecision.NS); + + Assertions.assertThat(point.getTime()).isEqualTo(BigInteger.valueOf(1655029563800123456L)); + } + @Test void defaultTags() {