Problem about converting ZonedDateTime entity to a SQL timestamp

Hi all,

I found a problem in our code about converting ZonedDateTime entity to a SQL timestamp:

  • facts
    the class ZonedDateTimeAttributeConverter in our code
    when converting the ZonedDateTime entity convert to a SQL timestamp,
    we used code: Timestamp.from(entityValue.toInstant();

  • problem
    we would get a timestamp, but it was calculated by the current machine’s time zone.

  • solution
    In stock management service,
    we used code:
    Timestamp.valueOf(entityValue.withZoneSameInstant(of("UTC")).toLocalDateTime());

    and we get a timestamp by UTC.

  • potential risk
    if we deployed the application to a machine, its time zone not set to UTC. We would get a wrong timestamp.