Skip to content

Commit e287ce4

Browse files
author
Kubit
committed
Improve veridyDate on inputDate
1 parent d6b6d9c commit e287ce4

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/components/inputDate/hooks/useInputDate.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,16 @@ export const useInputDate = ({
270270
? dateValue.split(props.dateSeparator as string)
271271
: dateValue.split(' ');
272272

273-
const firstDate = formatDateToNative(dates[0], props.format);
274-
const secondDate = secondDateExists ? formatDateToNative(dates[1], props.format) : '';
273+
const firstDate = formatDateToNative(dates[0].trim(), props.format, true);
274+
const secondDate = secondDateExists
275+
? formatDateToNative(dates[1].trim(), props.format, true)
276+
: '';
275277

276-
const firstValueAsNumber = firstDate.length && new Date(firstDate).getTime();
277-
const secondValueAsNumber = secondDate.length && new Date(secondDate).getTime();
278+
const firstValueAsNumber = firstDate.length && formatDateToUTC(firstDate).getTime();
279+
const secondValueAsNumber = secondDate.length && formatDateToUTC(secondDate).getTime();
278280

279-
const firstValueAsDate = firstDate.length && new Date(firstDate);
280-
const secondValueAsDate = secondDate.length && new Date(secondDate);
281+
const firstValueAsDate = firstDate.length && formatDateToUTC(firstDate);
282+
const secondValueAsDate = secondDate.length && formatDateToUTC(secondDate);
281283

282284
adaptEvent = {
283285
target: {
@@ -346,14 +348,16 @@ export const useInputDate = ({
346348
? dateValue.split(props.dateSeparator as string)
347349
: dateValue.split(' ');
348350

349-
const firstDate = formatDateToNative(dates[0], props.format);
350-
const secondDate = secondDateExists ? formatDateToNative(dates[1], props.format) : '';
351+
const firstDate = formatDateToNative(dates[0].trim(), props.format, true);
352+
const secondDate = secondDateExists
353+
? formatDateToNative(dates[1].trim(), props.format, true)
354+
: '';
351355

352-
const firstValueAsNumber = firstDate.length && new Date(firstDate).getTime();
353-
const secondValueAsNumber = secondDate.length && new Date(secondDate).getTime();
356+
const firstValueAsNumber = firstDate.length && formatDateToUTC(firstDate).getTime();
357+
const secondValueAsNumber = secondDate.length && formatDateToUTC(secondDate).getTime();
354358

355-
const firstValueAsDate = firstDate.length && new Date(firstDate);
356-
const secondValueAsDate = secondDate.length && new Date(secondDate);
359+
const firstValueAsDate = firstDate.length && formatDateToUTC(firstDate);
360+
const secondValueAsDate = secondDate.length && formatDateToUTC(secondDate);
357361

358362
adaptEvent = {
359363
target: {
@@ -395,10 +399,10 @@ export const useInputDate = ({
395399
let adaptEvent;
396400

397401
if (hasSecondaDate) {
398-
const firstNativeDate = formatDateToNative(getDate(orderedDates[0]), props.format);
399-
const secondNativeDate = formatDateToNative(getDate(orderedDates[1]), props.format);
400-
const firstValueAsNumber = new Date(orderedDates[0]).getTime();
401-
const secondValueAsNumber = new Date(orderedDates[1]).getTime();
402+
const firstNativeDate = formatDateToNative(getDate(orderedDates[0]), props.format, true);
403+
const secondNativeDate = formatDateToNative(getDate(orderedDates[1]), props.format, true);
404+
const firstValueAsNumber = formatDateToUTC(orderedDates[0]).getTime();
405+
const secondValueAsNumber = formatDateToUTC(orderedDates[1]).getTime();
402406

403407
adaptEvent = {
404408
target: {

src/components/inputDate/stories/inputDate.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const commonArgs: IInputDate = {
8888
backToMonthAriaLabel: 'Back to month view',
8989
},
9090
disabledDates: [new Date('2020-01-01'), new Date('2020-01-05')],
91-
errorExecution: ERROR_EXECUTION.ON_BLUR,
91+
errorExecution: ERROR_EXECUTION.ON_CHANGE,
9292
};
9393

9494
export const InputDate: Story = {

src/components/inputDate/utils/verifyDate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const checkLeapYear = (year: number): void => {
88
}
99
};
1010

11-
const splitDate = (
11+
export const splitDate = (
1212
date: string,
1313
format: string,
1414
today: string,

0 commit comments

Comments
 (0)