nats-io / nats.java

Java client for NATS
Apache License 2.0
569 stars 154 forks source link

NatsJetStreamMetaData timestamp parsed with incorrect timezone unable to convert back to UTC #1125

Closed mrmx closed 6 months ago

mrmx commented 6 months ago

Observed behavior

The timestamp metadata returned to clients shows incorrect timezone offsets when reverting back to UTC (as writting normalized UTC code in server and client side).

Using the long timestamp in the JetStreamTestBase 1605139610113260000 corresponding to a 2020-11-12T00:06:50.113260Z RFC3339 it results to a ZonedDateTime of (ie) 2020-11-12T00:06:50.113260+01:00[Europe/Madrid] returned in the timestamp metadata.

Converting it back to UTC:

ZonedDateTime utcZonedDateTime = timestamp.withZoneSameInstant(ZoneId.of("UTC"));

Gives back a 2020-11-11T23:06:50.113260Z[UTC] which is wrong.

Expected behavior

The above conversion to UTC should be 2020-11-12T00:06:50.113260Z[UTC]

Server and client version

server: Synadia current Cloud NGS service (@connect.ngs.global) client: io.nats:jnats-2.16/17.x

Steps to reproduce

Given a NATS Message's metadata timestamp:

ZonedDateTime timestamp = msg.metaData().timestamp();
ZonedDateTime utcZonedDateTime = timestamp.withZoneSameInstant(ZoneId.of("UTC"));

The converted back to UTC ZonedDateTime timestamp utcZonedDateTime is wrong.

mrmx commented 6 months ago

This relates to #938