Skip to content

Locale Date string to Date? #2568

Answered by fturmel
hershkoy asked this question in General
Jul 29, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I don't believe that date-fns can handle natural language date parsing. You would have to pre-determine the expected patterns ahead of time and find a match by trying them all in the parse function.

Fortunately, the scope of your problem makes it somewhat easy to solve with regular expressions. For fun, I've hacked at it a bit while drinking my morning coffee. I hope this sets you on the right path. If others find this useful, maybe this can be the foundation of a new date-fns function. https://codesandbox.io/s/natural-language-date-parsing-demo-6uzkk?file=/src/index.js

If you want something more robust, Chrono looks pretty cool. There's no Hebrew locale, but maybe that's something you co…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hershkoy
Comment options

Answer selected by hershkoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants