Skip to content

Commit a798726

Browse files
committed
fix: date picker components value parser
1 parent d55f030 commit a798726

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ 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,7 @@ export const DateInput: React.FC<StringInputProps<DateProps>> = ({
2222
}) => {
2323
const {value, onChange, onBlur, onFocus} = input;
2424
const dateInput = spec.viewSpec.dateInput;
25+
const timeZone = dateInput?.timeZone || 'UTC';
2526
const outputFormat = dateInput?.outputFormat;
2627

2728
const onUpdate = useCallback(
@@ -63,11 +64,14 @@ export const DateInput: React.FC<StringInputProps<DateProps>> = ({
6364
onBlur: onBlur as (e: React.FocusEvent<HTMLElement>) => void,
6465
onFocus: onFocus as (e: React.FocusEvent<HTMLElement>) => void,
6566
value: value
66-
? dateTimeParse((value as any).seconds ? (value as any).seconds * 1000 : value) || null
67+
? dateTimeParse((value as any).seconds ? (value as any).seconds * 1000 : value, {
68+
timeZone,
69+
}) || null
6770
: null,
6871
onUpdate,
6972
disabled: spec.viewSpec.disabled,
7073
placeholder: spec.viewSpec.placeholder,
74+
timeZone,
7175
};
7276

7377
return <DatePicker className={b()} data-qa={name} {...props} />;

0 commit comments

Comments
 (0)