resolveDate
This commit is contained in:
parent
2f9218ac47
commit
0a7ceb0aa5
@ -63,10 +63,13 @@ class Resolver {
|
|||||||
|
|
||||||
resolveDate(string) {
|
resolveDate(string) {
|
||||||
let date = null;
|
let date = null;
|
||||||
const matches = string.match(/([0-9]{4}(?:\/|-)[0-9]{1,2}(?:\/|-)[0-9]{1,2})/gimu); //YYYY-MM-DD is REQUIRED.
|
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 (matches && matches.length > 0) {
|
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 {
|
try {
|
||||||
const string = matches[0].replace(/\//giu, '-');
|
|
||||||
date = moment(string);
|
date = moment(string);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user