Skip to content

Commit 395eb37

Browse files
authored
fix: date picker components value parser (#243)
1 parent 76998fe commit 395eb37

31 files changed

+55
-38
lines changed

docs/spec.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec;
166166

167167
#### DateInput
168168

169-
| Property | Type | Required | Description |
170-
| :----------- | :--------------------------------------------------- | :------: | :-------------------------------------------------------------------------------------------------------------- |
171-
| outputFormat | `string` \| string \| date \| timestamp \| date_time | | Format returning string (for backend and logic). [Available formats](https://day.js.org/docs/en/display/format) |
172-
| printFormat | `string` | | Format print string (for view in read form). [Available formats](https://day.js.org/docs/en/display/format) |
169+
| Property | Type | Required | Description |
170+
| :----------- | :--------------------------------------------------- | :------: | :------------------------------------------------------------------------------------------------------------------- |
171+
| outputFormat | `string` \| string \| date \| timestamp \| date_time | | Format returning string (for backend and logic). [Available formats](https://day.js.org/docs/en/display/format) |
172+
| printFormat | `string` | | Format print string (for view in read form). [Available formats](https://day.js.org/docs/en/display/format) |
173+
| timeZone | `string` | | Sets the time zone. [Learn more about time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) |
173174

174175
You can provide all props of [original component](https://preview.gravity-ui.com/date-components/?path=/docs/components-datepicker--docs) through [viewSpec.inputProps](./input-props-map.md).
175176

package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"dependencies": {
4747
"@bem-react/classname": "^1.6.0",
4848
"@gravity-ui/components": "^3.0.0",
49-
"@gravity-ui/date-components": "^2.4.0",
50-
"@gravity-ui/date-utils": "^2.4.0",
49+
"@gravity-ui/date-components": "^2.10.3",
50+
"@gravity-ui/date-utils": "^2.5.5",
5151
"@gravity-ui/i18n": "^1.2.0",
5252
"@gravity-ui/icons": "^2.8.1",
5353
"lodash": "^4.17.20"

src/lib/core/types/specs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export interface StringSpec<
182182
dateInput?: {
183183
outputFormat?: string;
184184
printFormat?: string;
185+
timeZone?: string;
185186
};
186187
copy?: boolean;
187188
selectParams?: {

src/lib/kit/components/Inputs/DateInput/DateInput.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React, {useCallback} from 'react';
22

33
import {DatePicker, DatePickerProps} from '@gravity-ui/date-components';
44
import {StringInputProps} from '../../../../core';
5-
import {DateTime, dateTimeParse} from '@gravity-ui/date-utils';
5+
import {DateTime, dateTimeParse, isValidTimeZone} from '@gravity-ui/date-utils';
66
import {block} from '../../../utils';
77

88
import './DateInput.scss';
99

10-
export const DEFAULT_DATE_FORMAT = 'DD-MM-YYYY';
10+
export const DEFAULT_DATE_FORMAT = 'DD.MM.YYYY HH:mm';
1111

1212
const b = block('date-input');
1313

@@ -22,6 +22,8 @@ export const DateInput: React.FC<StringInputProps<DateProps>> = ({
2222
}) => {
2323
const {value, onChange, onBlur, onFocus} = input;
2424
const dateInput = spec.viewSpec.dateInput;
25+
const timeZone =
26+
dateInput?.timeZone && isValidTimeZone(dateInput.timeZone) ? dateInput.timeZone : undefined;
2527
const outputFormat = dateInput?.outputFormat;
2628

2729
const onUpdate = useCallback(
@@ -63,11 +65,15 @@ export const DateInput: React.FC<StringInputProps<DateProps>> = ({
6365
onBlur: onBlur as (e: React.FocusEvent<HTMLElement>) => void,
6466
onFocus: onFocus as (e: React.FocusEvent<HTMLElement>) => void,
6567
value: value
66-
? dateTimeParse((value as any).seconds ? (value as any).seconds * 1000 : value) || null
68+
? dateTimeParse((value as any).seconds ? (value as any).seconds * 1000 : value, {
69+
format: dateInput?.outputFormat,
70+
timeZone,
71+
}) || null
6772
: null,
6873
onUpdate,
6974
disabled: spec.viewSpec.disabled,
7075
placeholder: spec.viewSpec.placeholder,
76+
timeZone,
7177
};
7278

7379
return <DatePicker className={b()} data-qa={name} {...props} />;
Loading
513 Bytes
Loading
991 Bytes
Loading
486 Bytes
Loading
Loading

0 commit comments

Comments
 (0)