Skip to content

[partial] Improve fraction retrieval for DicomTime with precision checks #666

Merged
Enet4 merged 5 commits intoEnet4:masterfrom
pongis:DicomTime-varying-in-precision
Oct 1, 2025
Merged

[partial] Improve fraction retrieval for DicomTime with precision checks #666
Enet4 merged 5 commits intoEnet4:masterfrom
pongis:DicomTime-varying-in-precision

Conversation

@pongis
Copy link
Copy Markdown
Contributor

@pongis pongis commented Jul 25, 2025

Hi,
i picked #662 and implemented a solution where leading zeros are not omitted and the value representation of the Date time remains correct. I also added 2 more tests for my change. First time adding to Open Source, hope this helps.

I am not sure if Option<&u32> is the right choice as return type, or if i should create a new error variant if a mismatch between frac and frac_precision occurs.

@Enet4
Copy link
Copy Markdown
Owner

Enet4 commented Jul 25, 2025

Thank you for the initiative! In the meantime I have already merged #665, but this can make a great addition to the 0.9 milestone!

I am not sure if Option<&u32> is the right choice as return type, or if i should create a new error variant if a mismatch between frac and frac_precision occurs.

An enum might be better, as it forcefully narrows down the precision depth to valid cases (10th of a second, 100th of a second, millisecond, ...). But this can stay an implementation detail as long as the API is expressive and flexible enough. Right now there are a few cases where it's still hard to retrieve the fraction of a second, and relaxing it to enable fetching this fraction regardless of precision may be a good step towards that.

Moreover, any method in this module returning Option<&u32> should return Option<u32> instead. In this case there is no added value to returning the reference to the value in the DicomTime, and Option<u32> is more compact and nicer to work with.

@Enet4 Enet4 added breaking change Hint that this may require a major version bump on release A-lib Area: library C-core Crate: dicom-core labels Jul 25, 2025
@Enet4 Enet4 added this to the DICOM-rs 0.9 milestone Jul 25, 2025
@Enet4 Enet4 self-assigned this Sep 17, 2025
pongis and others added 3 commits September 24, 2025 20:25
- remove method fraction as it was ambiguous
- add `fraction_ms()` and `fraction_micro()`
  which are sure to return something unless there is no fraction
- add `fraction_precision()`
- change `fraction_str` so that it returns `String` and document it
@Enet4 Enet4 force-pushed the DicomTime-varying-in-precision branch from 7a3709e to 6e25b7b Compare September 24, 2025 20:29
@Enet4
Copy link
Copy Markdown
Owner

Enet4 commented Sep 24, 2025

I took the liberty of reworking this pull request so that hopefully it will be easier to work with fractions of a second.

  • I have decided to remove the fraction method entirely due to its ambiguity and difficulty of use. The former implementation (pre-PR) was particularly tricky to use because it required the fraction to be precise to the microsecond, which some devices do not even produce. And the implementation originally suggested in this PR would also require the user to consult the precision for it to be useful.
  • So instead, we now have fraction_ms and fraction_micro, which always return at the requested precision, and only return None when the time does not specify any fraction of a second.
  • I also added a few extra methods and trait implementations which make complete sense but were missing for some reason: FromStr for DicomDate and DicomTime.
  • Remove also functions which were deprecated in version 0.7

@Enet4
Copy link
Copy Markdown
Owner

Enet4 commented Oct 1, 2025

Should be good now! Feel free to let me know if you encounter other quirks in this API.

@Enet4 Enet4 merged commit a820a53 into Enet4:master Oct 1, 2025
5 checks passed
@Enet4 Enet4 linked an issue Dec 17, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lib Area: library breaking change Hint that this may require a major version bump on release C-core Crate: dicom-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot read DicomTime value with millisecond precision

2 participants