`mon` and `monday` no longer recognized
ilDon opened this issue · comments
Description
It seems that the inputs mon and monday are no longer recognized as valid date inputs. I encountered this issue today (Tuesday, September 19, 2023). I am currently investigating if the issue is related to the fact that today is a day after Monday. Additionally, adding a custom parser to fix this issue did not work as expected.
Code to Reproduce
const callChrono = (text: string, options = {}) => {
const configuration = chrono.casual.defaultConfig.createCasualConfiguration(false);
const chronoInstance = new chrono.Chrono(configuration);
const forwardFrom = options?.forwardFrom || new Date();
return chronoInstance.parse(text, forwardFrom, options);
}
test('should parse "mon" as a date', () => {
const result = callChrono('do stuff mon', {
forwardDate: true,
startDayHour: 8
});
expect(result.date).toBeInstanceOf(Date);
});
Custom Parser
fixMonday = {
pattern: () => /\b(mon|monday)\b/i,
extract: (context, match) => {
if (match[0] === 'monday' || match[0] === 'mon') {
const today = DateTimeHelper.today();
const daysToNextMonday = 8 - today.getDay();
const nextMonday = DateTimeHelper.addDays(today, daysToNextMonday);
return {
day: nextMonday.getDate(),
month: nextMonday.getMonth() + 1,
year: nextMonday.getFullYear()
};
}
}
};
Expected Behavior
The mon and monday inputs should be recognized as valid date inputs, and the custom parser should correctly identify the next Monday from the current date.
Actual Behavior
The mon and monday inputs are not recognized, and the custom parser does not seem to fix this issue.
Additional Information
I will continue to investigate this issue to determine if it is related to the current date being a day after Monday, and will update this issue with any findings.
chrono version: 2.7.0
Can't reproduce anymore. Not a chrono issue :-)