Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support modern java.time types for getters (first draft) #1351

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hczedik
Copy link
Member

@hczedik hczedik commented Sep 26, 2023

Add a getTemporal(.) method to Attributes which returns one of the modern java.time types (ZonedDateTime, LocalDateTime).

Motivation:

  • The current timezone handling using the legacy Date type is a source of confusion and bugs, because it is unclear whether a timezone corrected date/time or a local date/zime is returned.
  • The new types can store the full microsecond resolution that DICOM supports (no more rounding to millisecond, as it has to be done for the Date type)

@gunterze: This is a draft containing some TODOs. I just want to get your general feedback if you agree with the general design and whether I should continue working on this. Thanks!

if (parent != null)
return parent.getDefaultZoneId();

return null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the different behavior here compared to getDefaultTimezone: It returns null in case nothing is defined and does not fall back to the system default.

@sonarcloud
Copy link

sonarcloud bot commented Sep 26, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 25 Code Smells

66.6% 66.6% Coverage
5.3% 5.3% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

Copy link
Member

@gunterze gunterze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to do not consider the "corresponding" TM/DA attribute for DA/TM attributes.

Instead I propose to return

VR &ZZXX TimeZone DST Class
DT yes * * OffsetDateTime
DT no no n/a LocalDateTime
DT no yes no OffsetDateTime
DT no yes yes ZonedDateTime
DA n/a * * LocalDate
TM n/a no n/a LocalTime
TM n/a yes no OffsetTime
TM n/a yes yes LocalTime

for getTemporal(int tag), where TimeZone falls back to defaultTimeZone,

Alternatively to

VR &ZZXX TimeZone DST Class
TM n/a yes yes LocalTime

you may return

VR &ZZXX TimeZone DST Class
TM n/a yes yes OffsetTime

with setting as offset

  • either the Offset of the TimeZone at current date and time
  • or the Raw (without DST Saving) Offset of the TimeZone

And provide also getTemporal(long datmTag) (datmTag = (daTag << 32) | tmTag) returning

DA TM TimeZone DST Class
no * * * null
yes no * * LocalDate
yes yes no n/a LocalDateTime
yes yes * * OffsetDateTime
yes yes yes no OffsetDateTime
yes yes yes yes ZonedDateTime

Alternatively to

DA TM TimeZone DST Class
no * * * null

you may return

DA TM TimeZone DST Class
no no * * null
no yes no n/a LocalTime
no yes yes no OffsetTime
no yes yes yes LocalTime

and - as above - alternatively to

DA TM TimeZone DST Class
no yes yes yes LocalTime

you may return

DA TM TimeZone DST Class
no yes yes yes OffsetTime

with setting as offset

  • either the Offset of the TimeZone at current date and time
  • or the Raw (without DST Saving) Offset of the TimeZone

@hczedik
Copy link
Member Author

hczedik commented Nov 17, 2023

Hi @gunterze ,

thanks a lot for the detailled feedback on this one. Sorry for the delay now on my side, I am busy with some other stuff at the moment. But I will definitely follow-up on this PR.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants