project-husky / husky

Health Usability Key
https://project-husky.github.io/husky/
Eclipse Public License 1.0
17 stars 8 forks source link

Bad handling of timezones in DateTimes #164

Closed qligier closed 2 months ago

qligier commented 3 months ago

The utility DateTimes class is badly handling timezones in different methods.

https://github.com/project-husky/husky/blob/5bdc53a5b2870574fc1098e6a9684e38d6eb7cab/husky-common/husky-common-gen/src/main/java/org/projecthusky/common/utils/time/DateTimes.java#L33-L46 The formatters are set to the local zone.


https://github.com/project-husky/husky/blob/5bdc53a5b2870574fc1098e6a9684e38d6eb7cab/husky-common/husky-common-gen/src/main/java/org/projecthusky/common/utils/time/DateTimes.java#L233-L235 Europe/Zurich is hard-coded. I think the method should be renamed to getLocalZonedDateTime, and use ZoneId.systemDefault() instead.


https://github.com/project-husky/husky/blob/5bdc53a5b2870574fc1098e6a9684e38d6eb7cab/husky-common/husky-common-gen/src/main/java/org/projecthusky/common/utils/time/DateTimes.java#L244-L246 The local zone is assumed. While HL7 says that a DTM without timezone defaults to the local timezone:

Note: If the time zone is not included, the time zone defaults to that of the local time zone of the sender

DTMs used in IHE profiles often (always?) are expressed in UTC.

This should either take a zone, or be split into toLocalHl7Dtm and toUtcHl7Dtm.


https://github.com/project-husky/husky/blob/5bdc53a5b2870574fc1098e6a9684e38d6eb7cab/husky-common/husky-common-gen/src/main/java/org/projecthusky/common/utils/time/DateTimes.java#L256-L260

https://github.com/project-husky/husky/blob/5bdc53a5b2870574fc1098e6a9684e38d6eb7cab/husky-common/husky-common-gen/src/main/java/org/projecthusky/common/utils/time/DateTimes.java#L269-L273

Same thing here.

qligier commented 2 months ago

Some of these methods javadoc did mention (wrongly) UTC was assumed.