-
Notifications
You must be signed in to change notification settings - Fork 103
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
WIP: Added Year, YearMonth and ArbitraryPrecisionDate #173
WIP: Added Year, YearMonth and ArbitraryPrecisionDate #173
Conversation
I don't see why this is a pull request, given how sparse the code is. Could you instead file it as an issue? Some notes in the meantime:
|
I just wanted to develop iteratively with some actual code instead of sending around code snippets.
Sure. A sealed hierarchy would just make it a little bit easier to prevent mistakes. Otherwise you can just wrap everything with a custom sealed hierarchy and introduce formatting, serialization, sorting at that level.
It's useful when you have mixed data. 2020 is before July 2020 which is before July 27th, 2020. I think that's still intuitive behavior from an end-user perspective.
I think it can be useful when implementing a function that can work on such arbitrary things or that wants to use static typing to set a minimum requirement. E.g. you might want to store a full date or a year-month to allow calculating something in a sufficiently meaningful way, but still allow the user some fuzzyness if an event can't exactly be determined/remembered.
The Year / YearMonth / ... hierarchy is a strict ordering from less to more precise time information, it's how medical specs work and I think humans also find this the most useful way. If you had a vaccination in 2016 you can at least say whether you need a booster. If you only know it was in July but don't know the year then there's not much you can usefully do with that information. At least, this hierarchy has real-world use for us and it would be more comfortable to work with if it was implemented within this library instead of us having to wrap everything. |
Still, I think this should be discussed in the issues section. The discussion section for the pull requests is for discussing the code, not the issues. Other people facing the same problem may well decide not to write anything if they see that a pull request for this already exists, thinking that there's some finality already. In any case, there's not much code to discuss, we would just be discussing the issues. |
I'll open an issue later (hopefully today). |
See #177 |
This is just a very quick example of how we could add support for an ArbitraryPrecisionDate that can be a
Year
orYearMonth
orLocalDate
orLocalDateTime
or (later)ZonedDateTime
(which could itself be a sealed class ofOffsetDateTime
andRegionDateTime
).The
ArbitraryPrecisionDate
could provide aparse()
method that returns any of those classes (all of which implement ArbitraryPrecisionDate). At least in the medical space it's pretty common to have flexible date precisions in the official specifications, so you have to support at least these operationsYou might also want to treat the data differently based on its type. Here it helps a lot to have a sealed interface, so you can easily match all possible cases (which is also useful for the formatting and sorting etc. functions).
We could additionally have sealed interfaces for higher level subsets, so you can, for example, parse and work with any static type that contains at least a year-month-day.
What do you think?