From 7f7aa49af787e823320f9ee6a8acd8e93779d360 Mon Sep 17 00:00:00 2001 From: Victoria Zhizhonkova Date: Tue, 5 Nov 2024 18:17:47 +0700 Subject: [PATCH] fix: use date-fns functions --- packages/vkui/src/components/DateInput/DateInput.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/vkui/src/components/DateInput/DateInput.tsx b/packages/vkui/src/components/DateInput/DateInput.tsx index d0f39585b2..42e493704a 100644 --- a/packages/vkui/src/components/DateInput/DateInput.tsx +++ b/packages/vkui/src/components/DateInput/DateInput.tsx @@ -3,6 +3,7 @@ import * as React from 'react'; import { Icon16Clear, Icon20CalendarOutline } from '@vkontakte/icons'; import { classNames } from '@vkontakte/vkjs'; +import { startOfDay, startOfMinute } from 'date-fns'; import { useAdaptivity } from '../../hooks/useAdaptivity'; import { useDateInput } from '../../hooks/useDateInput'; import { useExternRef } from '../../hooks/useExternRef'; @@ -175,13 +176,9 @@ export const DateInput = ({ } if (isMatch(formattedValue, mask)) { + const now = new Date(); onChange?.( - parse( - formattedValue, - mask, - value ?? - new Date(enableTime ? new Date().setSeconds(0, 0) : new Date().setHours(0, 0, 0, 0)), - ), + parse(formattedValue, mask, value ?? (enableTime ? startOfMinute(now) : startOfDay(now))), ); } },