How to figure out which parts of the date were not provided?
Hey thanks for the great library!
I would like to see if there is a reliable way to figure out which parts of the date were not provided directly in the input string but rather inferred?
For example,
- the input string was
May 13th, so I would like to know that month/day was provided while year was missed. - the input string was
1997, so I would like to know that month/day were missed and only year was provided.
I believe Period was supposed to be the answer, but it gives me Day for May 13th meaning that it's confident in year -> month -> day? But it can't be confident in year in this case as it was not provided.
Another question: is it possible to figure that which parsed date was relative? E.g. last week, yesterday, in 3 days, etc.
My use cases are a bunch of little functionalities around scheduling/reminding:
- If someone wants to record May 13th as someone's birthday, then we shouldn't show how old that person is since we don't know the year they were born.
- If relative date was provided, we need to "fix" it in time by turning into an exact timestamp vs keeping incomplete absolute dates as is.
Period describes precision, rather than which components were supplied. The current exported date.Date contains only Locale, Period, and Time, so it cannot distinguish an explicit year from a defaulted year after parsing.
There is already useful information internally: the absolute parser builds missingParts from ComponentValues before applying defaults. A provenance extension could copy that into a supplied-component mask and carry a parse kind from the successful strategy, such as absolute versus relative. Capture this before filling the date; comparing the result with CurrentTime cannot distinguish an explicitly entered current year from an omitted one.
Useful fixtures are May 13th, May 13th 2026 with a 2026 reference, 1997, yesterday, and in 3 days. Store a birthday as month/day with a nullable year; store a relative reminder with its resolved timestamp and reference zone.
I maintain DateParser Kotlin. Its inherited-clock fixture illustrates the same distinction between returned values and supplied fields; it also lacks a public supplied-component mask, so switching parsers would not itself solve this requirement.