Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (indexStr !== undefined && indexStr.match(/^\d+$/)) {
dateStr = f.slice(0, -1 * (indexStr.length + 1));
debug(`dateStr is ${dateStr}`);
if (pattern && !dateStr) {
dateStr = indexStr;
indexStr = "0";
}
} else {
indexStr = "0";
}
try {
// Two arguments for new Date() are intentional. This will set other date
// components to minimal values in the current timezone instead of UTC,
// as new Date(0) will do.
const date = format.parse(pattern, dateStr, new Date(0, 0));
p.index = parseInt(indexStr, 10);
p.date = dateStr;
p.timestamp = date.getTime();
return "";
} catch (e) {
//not a valid date, don't panic.
debug(`Problem parsing ${dateStr} as ${pattern}, error was: `, e);
return f;
}
};
n =>
(n.date
? format.parse(this.options.pattern, n.date).valueOf()
: newNow().valueOf()) - n.index
)