From 0a7ceb0aa563a5472b9e3a66354e420ce92afd80 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Fri, 29 Apr 2022 20:06:10 +0300 Subject: [PATCH] resolveDate --- src/structure/client/Resolver.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/structure/client/Resolver.js b/src/structure/client/Resolver.js index ab90452..758550e 100644 --- a/src/structure/client/Resolver.js +++ b/src/structure/client/Resolver.js @@ -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(/((?[0-9]{4})(?:\/|-)(?[0-9]{1,2})(?:\/|-)(?[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;