Closed lemorage closed 3 weeks ago
I'm trying to fix that, but this is tricky (e.g. parsing "from 5-22" as from 5am to 10pm on the same day is also valid).
Is the hyphenated date (e.g. "5-22") common in your locale? I believe if it's more common "5/22 to 5/28", it should work correctly.
It really took me a while to realize that, 5-22 can be viewed as a time range in a day. At least for my case, I would say it is quite non-intuitive to parse as a time rather than a date. Do u think is there any way I could bypass the time parsing here?
Similar to #570 case, I would suggest removing EnTimeExpressionParser if you know you do not need time (e.g. you are working with date only).
If not, another way is adding a custom refiner to filter out the those specific case:
// Make a custom instance from a normal Chrono (English casual).
const custom = chrono.casual.clone();
// Use `unshift` to filter the results out early before considering combining them with others.
custom.refiners.unshift({
refine: (context, results) => {
return results.filter(
// Filter out '1-22', '12-12' etc
(r) => !r.text.match(/\d+-\d+/) && !r.start.isTimeOnly()
);
}
});
Cool, I'll try it!
I ran the following example test, but got an unexpected output. I thought it should return me 2024-05-22 as the start date, and 2024-05-28 as the end date.
After some time of debugging, I thought this should be due to
EnTimeExpressionParser
being invoked at first. However, I still had no idea why I got this weird output2024-10-07T21:00:00.000Z ~ 2024-10-08T14:00:00.000Z
.