Parsing Natural Language Date Strings in PHP
Published Friday July 3, 2020
My family uses Cozi Family Organizer to do our meal planning and make sure that at least one adult is scheduled to be in the same state as the children every day (less of a problem in the age of covid). Their web app has a really nice open text add to calendar feature that very accurately parses sentences into calendar events.
I use this feature dozens of times a week and every time I do I wish I could give my users the same experience. This week I reached my pain threshold and decided to do something about it. I definitely have not duplicated what Cozi's interface offers, but I do have a pretty good jumping off point for letting people enter date and time in a natural, keyboard-only manner.
On Thursday I built Sundial, a natural language date and time parser that does a pretty good job of pulling dates and times out of blocks of text. It currently works with absolute dates and times (June 11th at 4:15 pm), with relative dates and times (next thursday at noon) limited to strings that strtotime() can parse on its own. This minimum viable package meets the core need I have at work. But I'm hoping that with a little help from the community we can take it WAY furhter.
Did you find a mistake? Have something to add? This article is on GitHub. Send me a PR!