Many common human-readable datetimes can be parsed using datetime.strptime()
, for example:
'15 March 2019 13:00'
And I know of several Python packages that parse "fuzzy" human-readable datetimes into Python datetime objects, such as dateparser and parsedatetime, which can parse strings such as:
'yesterday'
'next week'
But is there a Python library that can parse common human-readable datetime durations into start and end datetime objects. For example:
'5 March 2019 13:00-18:30'
'5 March 2019 1:00-5:30pm'
'15-18 March 2019'
'2nd to 22nd March 2019'
into:
[datetime.datetime(2019, 3, 5, 13, 0), datetime.datetime(2019, 3, 5, 18, 30)]
[datetime.datetime(2019, 3, 5, 13, 0), datetime.datetime(2019, 3, 5, 18, 30)]
[datetime.datetime(2019, 3, 15, 0, 0), datetime.datetime(2019, 3, 18, 0, 0)]
[datetime.datetime(2019, 3, 2, 0, 0), datetime.datetime(2019, 3, 22, 0, 0)]
or take a string like:
'15-17 March 2019'
and return a list of inclusive dates?
[datetime.datetime(2019, 3, 15, 0, 0), datetime.datetime(2019, 3, 16, 0, 0), datetime.datetime(2019, 3, 17, 0, 0)]
Note that I'm interested in parsing specific dates and times rather than non-calendar-based durations such as '2 days'
or 'three weeks'
.