hapi-fhir icon indicating copy to clipboard operation
hapi-fhir copied to clipboard

Get rid of java Date

Open doumdoum opened this issue 2 years ago • 3 comments

Describe the issue I've been using some FHIR modules (great job) and i'm facing some issues when having to convert to old java Dates which are used in FHIR. Since Java 8 the Date library has been deprecated in favor of the new java time library which deals nicely with zoned/zoneless datetimes. Would you be interested if i make a contribution to switch to using the java time library ?

doumdoum avatar Aug 16 '22 13:08 doumdoum

We've discussed doing this a few times - For many years HAPI FHIR still supported JDK6 which is why we used the older date structure. This isn't an issue any more since we're officially JDK11 now, but a change like this needs to either:

  • Be done in conjunction with a major version bump
  • Be done in a way that doesn't break the existing API

I'm nervous about the first option - We've discussed doing this a few times, but it's a big change management exercize. There are tons of existing users out there, and even lots of internal API that will break if all of a sudden DateTimeType#getValue() returns a LocalDateTime instead of a Date.

One easy option might be to add things like public LocalDateTime asLocalDateTime() and public static DateTimeType fromLocalDateTime(LocalDateTime theValue) methods while preserving the existing API. This would be useful almost certainly, and we'd certainly be willing to accept such a PR. It would need to be done for each version of the model classes though.

jamesagnew avatar Aug 16 '22 21:08 jamesagnew

Hi @jamesagnew , can't we do it in two phases ? 1 use Temporal in the primitive type and keep getValue unchanged (always a Date) but mark it as Deprecated, and add getRawValue that returns the temporal and getAsDate, so that we don't break compatibility 2 in a later version make the getValue return the temporal

doumdoum avatar Aug 17 '22 10:08 doumdoum

i'm worried about unintended side effects if we change the internal representation. My preference would be to leave that until we're ready to do a major version bump.

jamesagnew avatar Aug 17 '22 17:08 jamesagnew