resolveDate

This commit is contained in:
Erik 2022-04-29 20:06:10 +03:00
parent 2f9218ac47
commit 0a7ceb0aa5
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -63,10 +63,13 @@ class Resolver {
resolveDate(string) {
let date = null;
const matches = string.match(/([0-9]{4}(?:\/|-)[0-9]{1,2}(?:\/|-)[0-9]{1,2})/gimu); //YYYY-MM-DD is REQUIRED.
if (matches && matches.length > 0) {
const match = string.match(/((?<year>[0-9]{4})(?:\/|-)(?<month>[0-9]{1,2})(?:\/|-)(?<day>[0-9]{1,2}))/imu); //YYYY-MM-DD is REQUIRED.
if (match) {
const { groups: { year, month, day } } = match;
const _month = month.length === 1 ? `0${month}` : month;
const _day = day.length === 1 ? `0${day}` : day;
const string = `${year}-${_month}-${_day}`;
try {
const string = matches[0].replace(/\//giu, '-');
date = moment(string);
} catch (error) {
return null;