[core] Change the date/time API to a more race-unfriendly one#737
[core] Change the date/time API to a more race-unfriendly one#737Enet4 merged 2 commits intoEnet4:masterfrom
Conversation
|
There has been no activity here, so I wonder if it's because the approach is unacceptable. I'm willing to make corrections - I'm aware that returning a DicomDate and a DicomTime element from within the DicomDateTime type may look a bit awkward, for one. However, returning both at the same time encourages using both when both are required, which is probably most of the time, and that'd be race-free, so if parasiting DicomDateTime for that purpose is considered bad design, maybe it can be rewritten as just an isolated function instead of an associated one. Removing that part and leaving only |
There was a problem hiding this comment.
I just have not had a lot of time lately for a more thorough look into the PRs. 😓
I agree that now_* should be dropped from DicomDate and DicomTime, thus forcing users to call DicomDateTime::now_* instead. I would not include separate_date_time_now_local or separate_date_time_now_utc, but rather tell users to call one of the now_* methods and then offer a way to split a DicomDateTime into those two parts (something like pub fn into_separate(self) -> (DicomDate, DicomTime)).
|
I do see issues with It's quite difficult to handle all special cases than can arise in such situations. I guess that such a function could return an error if the DT is not complete at least up to the hours, because if there's no hour at least, there would be no valid In short, a generic function that splits any One way it could be made to work with little effort, however, is to only accept exactly the format produced by |
|
Those are good concerns, but wouldn't the textual ambiguity be located at the parsing level? A It is true that the operation might not succeed or lose some information due to the inherent variable precision of DT, so we would need to adjust the return type accordingly: impl DicomDateTime {
fn into_separated(self) -> (DicomDate, Option<DicomTime>) {
(self.date, self.time)
}
} |
|
You're totally right, of course. I didn't look at the implementation of DicomDateTime at all, I just focused on what the prior PR author did. I wasn't aware that a DicomDateTime was actually a DicomDate + Option<DicomTime> + Option<FixedOffset>; I was under the impression that the value was stored as a string, but if it's already like that, there's no problem in doing what you suggest. I'll work on that, thanks for the feedback. Edit: By the way, wouldn't into_parts() be enough? You can always do something like |
Well yes, that would be enough. I was mostly following up on the idea of having a function which returned a date and time, but |
Per discussion on Enet4#737.
|
So, the patch was actually pretty simple. My only concern is if the documentation for into_parts() is insufficient. |
Enet4
left a comment
There was a problem hiding this comment.
The documentation for into_parts does not have to be extensive, given its simplicity.
I say we're good to merge! Thank you for your continued cooperation!
Fix #691 with a different approach:
DicomDateTimenow implements two methodsseparate_date_time_now_localandseparate_date_time_now_utc, both of which return both aDicomDateand aDicomTimeat the same time, based on the same timestamp. Also,DicomDateTime::now_local()andDicomDateTime::now_utc()are no longer based on separate calls to obtain a date and a time, which was open to races.Add some docs while on it.