From 2a80c0b38b7fb3f949e04ce00cc96166fa58b8e0 Mon Sep 17 00:00:00 2001 From: Artem Dzhereleiko Date: Wed, 17 Aug 2022 11:19:27 +0300 Subject: [PATCH] UI: Refactoring --- ui-ngx/src/app/shared/adapter/custom-datatime-adapter.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ui-ngx/src/app/shared/adapter/custom-datatime-adapter.ts b/ui-ngx/src/app/shared/adapter/custom-datatime-adapter.ts index 51ba33d9da..50417a5914 100644 --- a/ui-ngx/src/app/shared/adapter/custom-datatime-adapter.ts +++ b/ui-ngx/src/app/shared/adapter/custom-datatime-adapter.ts @@ -17,21 +17,20 @@ import { Injectable } from '@angular/core'; import { NativeDatetimeAdapter } from '@mat-datetimepicker/core'; - @Injectable() export class CustomDateAdapter extends NativeDatetimeAdapter { - parse(value: string): Date { + parse(value: string | number): Date { if (typeof value === 'number') { return new Date(value); } - let newDate = null; + let newDate = value; const formatToParts = Intl.DateTimeFormat(this.locale).formatToParts(); if (formatToParts[0].type.toLowerCase() === 'day') { const literal = formatToParts[1].value; - newDate = value.replace(new RegExp(`(\\d+[${literal}])(\\d+[${literal}])`), '$2$1'); + newDate = newDate.replace(new RegExp(`(\\d+[${literal}])(\\d+[${literal}])`), '$2$1'); } - return value ? new Date(Date.parse(newDate || value)) : null; + return newDate ? new Date(Date.parse(newDate)) : null; } }