in frontend/src/js/util/parseDate.js [55:109]
export function parseDateNoFallback(text, mode) {
// Date parser mode will chose either the from start of your date or the end
// This is because if you say, "Give me all documents from after 2018" you don't want the
// calculation to be from the first of January because you'd get results from all of 2018
//
// For example from_start '2018' returns 2018-01-01T00:00:00, from_end returns 2018-12-31T24:00:00
if (mode !== 'from_start' && mode !== 'from_end') {
throw new Error('Invalid date parsing mode');
}
let year, month, day;
// Check if we can just parse the text text as a single year
year = Number(text);
if (!isNaN(year)) {
// Check if we can just parse the text text as a single year
if (mode === 'from_end') {
year += 1;
}
return Date.UTC(year, 0);
}
const monthYear = monthYearDateRegex.exec(text);
if (monthYear !== null && monthYear.length === 3 && validateMonth(monthYear[1]) && validateYear(monthYear[2])) {
year = Number(monthYear[2]);
month = getMonthIndex(monthYear[1]);
if (mode === 'from_end') {
month += 1;
return Date.UTC(year, month);
} else {
return Date.UTC(year, month);
}
}
const dayMonthYear = dayMonthYearDateRegex.exec(text);
if (dayMonthYear !== null && dayMonthYear.length === 4 && validateDay(dayMonthYear[1]) && validateMonth(dayMonthYear[2]) && validateYear(dayMonthYear[3])) {
year = Number(dayMonthYear[3]);
month = getMonthIndex(dayMonthYear[2]);
day = Number(dayMonthYear[1]);
if (mode === 'from_end') {
day += 1;
return Date.UTC(year, month, day);
} else {
return Date.UTC(year, month, day);
}
}
return null;
}