I would like to parse free-text time intervals like the following, using Python:
- 1 second
- 2 minutes
- 3 hours
- 4 days
- 5 weeks
- 6 months
- 7 years
Is there a painless way to do this, ideally by simply calling a library function?
I have tried:
dateutil.parser.parse(), which understands seconds through hours but not days or more.mx.DateTime.DateTimeDeltaFrom(), which understands through days but fails on weeks or higher, and silently (e.g., it might create an interval of length 0, or parse “2 months” as 2 minutes).
This one is new to me, but based on some googling have you tried whoosh?
Edit: There’s also parsedatetime:
Output