bear / parsedatetime

Parse human-readable date/time strings
Apache License 2.0
695 stars 106 forks source link

New: Be able to identify text for datetime range #213

Open phoebebright opened 7 years ago

phoebebright commented 7 years ago

This is my use case:

I am parsing long strings for one or many dates, numbers, emails and url. In the case of dates or datetimes, I replace the text in the string so:

Arrange a meeting for monday at 3:30 for 2 hours to discuss stuff

Becomes

Arrange a meeting for 6Mar17 at 3:30 for 2 hours to discuss stuff

This works fine with a single date because the position of the matched text is returned using pcal.nlp(text, now)

However in date ranges, I don’t get the position so can’t change

Arrange a meeting for monday from 3:30-5:30 to discuss stuff

to

Arrange a meeting for 6Mar17 at 3:30 for 2 hours to discuss stuff

Having looked at the code, I can see where to find the position of 3:30-5:30 but not obvious to me how to get the position of the whole "monday from 3:30-5:30” chunk.

Ideally I would like a function that parses text and list of dates with their start/end positions (even if they overlap) and even better, have the option to replace matched datetimes with the format I requested. eg.

Arrange meeting for monday at 3:00 and another one for 23rd May 2017 14:00-16:00 to discuss stuff

Becomes

 Arrange a meeting for 6Mar17 at 3:00 and another one for 23May17 14:00-16:00

and a list with the 3 datetimes referenced.