Repository navigation
Conversation
|
I think having a function that returns all this data is necessary for some use cases. My first instinct would be to return an object, though, instead of a dictionary. We could create a custom class (e.g. |
|
It might be also useful to add self.missing = [field for field in ('day', 'month', 'year', 'time')
if not getattr(self, field)]So you know if the time is coming from parsed hour/minute. For instance, both |
|
I added the |
|
Hi looks like (#778) got merged, is there any chance to have this change merged? |
I did a proof of concept to add the missing parts ("year", "month" or "day") to the result of
DateDataParser.get_date_data().This could be a fix for #424, #553 and #700.
Of course tests are not passing, it's just a PoC to discuss it.
Precedents:
Sometimes there is a part of a date that it's missing: "22 may", "1994", etc. and there are people interested in knowing the missing part/s to be able to print / handle the result. Examples coming from the issues:
When doing:
to be able to print just:
and when doing
to be able to print:
Feasibility
As
dateparser.parse()returns adatetimeobject, and it's not possible to return those parts with zero (example from the mentioned issues:datetime.datetime(2015, 12, 0, 0, 0)), we can't just do it.However, as we can use directly the
DateDataParser.get_date_data()method and it returns more information (locale,period, etc.), we could add another field with the missing parts (if applicable).I added an
extrafield containing themissingfield. We could probably simplify this, adding themissingfield directly.Code snippets with the implementation from this PR:
This:
will print:
{'date_obj': datetime.datetime(2020, 5, 22, 0, 0), 'period': 'day', 'extra': {'missing': ['year']}, 'locale': 'en'}And this:
will print:
{'date_obj': datetime.datetime(1999, 6, 26, 0, 0), 'period': 'year', 'extra': {'missing': ['day', 'month']}, 'locale': 'en'}With this, we could just do something like:
Feedback
This PR can't be merged as-is, we should work on the tests and add more scenarios. Apart from that, it should be merged after merging this: #715 (and we should fix the conflicts)
Let me know what you think about this approach and if you see any blocker.