I’ve encountered a problem in which I am looking for a good solution.
I uses chrono-node for understanding which date the user is referring to ,
But chrono doesn’t follows a strict rule in parsing month only sentences
EX: const chrono = require(‘chrono-node’);
function testMonthParsing() {
const months = [
‘january’, ‘february’, ‘march’, ‘april’, ‘may’, ‘june’,
‘july’, ‘august’, ‘september’, ‘october’, ‘november’, ‘december’
];
months.forEach(month => {
let date = chrono.parseDate(month);
console.log(${month}: ${date}
);
});
}
testMonthParsing();
ISSUE:
The current month is July 2024
and the output for the above code is
january: Wed Jan 01 2025
february: Thu Feb 01 2024
march: Fri Mar 01 2024
april: Mon Apr 01 2024
may: Wed May 01 2024
june: Sat Jun 01 2024
july: Mon Jul 01 2024
august: Thu Aug 01 2024
september: Sun Sep 01 2024
october: Tue Oct 01 2024
november: Fri Nov 01 2024
december: Sun Dec 01 2024
here only January month is considered as January 2025(next year)
and all other months as this year(2024) months
The thing is
if chrono consider months Before Current Month (as it is already finished) as next year months, it should be applicable for all months before current month, but here that is not followed
Is there any alternative methods or npms for this