andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.54k stars 305 forks source link

Date.create to find a date in complex string #676

Open MeloJR opened 3 years ago

MeloJR commented 3 years ago

Hi! I have tried the Date.create function with severals date patterns and it works perfectly but I found that it only works if the string only includes the date. If the string has other parts before/after the date, it fails. I think the problem is the way the format RegEx are built: https://github.com/andrewplummer/Sugar/blob/3ca57818332473b601434001ac1445552d7753ff/lib/date.js#L2297 I want to be able to parse a date from the string "New York, 22 August" the same way as from the string "22 August". Is there a way to solve my problem with Sugar?

Thank you in advance.