From 45418da791df9876d8a55621a9f5bd11dc4bec92 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Tue, 1 Mar 2022 11:34:15 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B8=20=D0=B4=D0=B8=D0=B0=D0=BF=D0=BE=D0=B7=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B4=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/DateRangeWrapper.tsx | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/components/Table/DateRangeWrapper.tsx diff --git a/src/components/Table/DateRangeWrapper.tsx b/src/components/Table/DateRangeWrapper.tsx new file mode 100644 index 0000000..506879f --- /dev/null +++ b/src/components/Table/DateRangeWrapper.tsx @@ -0,0 +1,34 @@ +import { memo } from 'react' +import { DatePicker, } from 'antd' +import moment, { Moment } from 'moment' +import { RangeValue } from 'rc-picker/lib/interface' +import { RangePickerSharedProps } from 'rc-picker/lib/RangePicker' + +import { defaultFormat } from '@utils' + +const { RangePicker } = DatePicker + +export type DateRangeWrapperProps = RangePickerSharedProps & { + value: RangeValue, + onChange: (date: RangeValue) => any + isUTC?: boolean +} + +const normalizeDates = (value: RangeValue, isUTC?: boolean): RangeValue => value && [ + value[0] ? (isUTC ? moment.utc(value[0]).local() : moment(value[0])) : null, + value[1] ? (isUTC ? moment.utc(value[1]).local() : moment(value[1])) : null, +] + +export const DateRangeWrapper = memo(({ value, onChange, isUTC, ...other }) => ( + onChange(date)} + value={normalizeDates(value)} + {...other} + /> +)) + +export default DateRangeWrapper