diff --git a/docs/spec.md b/docs/spec.md index d2b3e8c5..66f4f57f 100644 --- a/docs/spec.md +++ b/docs/spec.md @@ -166,10 +166,11 @@ type Spec = ArraySpec | BooleanSpec | NumberSpec | ObjectSpec | StringSpec; #### DateInput -| Property | Type | Required | Description | -| :----------- | :--------------------------------------------------- | :------: | :-------------------------------------------------------------------------------------------------------------- | -| outputFormat | `string` \| string \| date \| timestamp \| date_time | | Format returning string (for backend and logic). [Available formats](https://day.js.org/docs/en/display/format) | -| printFormat | `string` | | Format print string (for view in read form). [Available formats](https://day.js.org/docs/en/display/format) | +| Property | Type | Required | Description | +| :----------- | :--------------------------------------------------- | :------: | :------------------------------------------------------------------------------------------------------------------- | +| outputFormat | `string` \| string \| date \| timestamp \| date_time | | Format returning string (for backend and logic). [Available formats](https://day.js.org/docs/en/display/format) | +| printFormat | `string` | | Format print string (for view in read form). [Available formats](https://day.js.org/docs/en/display/format) | +| timeZone | `string` | | Sets the time zone. [Learn more about time zones](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List) | 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). diff --git a/package-lock.json b/package-lock.json index d954233d..4674de00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,8 +11,8 @@ "dependencies": { "@bem-react/classname": "^1.6.0", "@gravity-ui/components": "^3.0.0", - "@gravity-ui/date-components": "^2.4.0", - "@gravity-ui/date-utils": "^2.4.0", + "@gravity-ui/date-components": "^2.10.3", + "@gravity-ui/date-utils": "^2.5.5", "@gravity-ui/i18n": "^1.2.0", "@gravity-ui/icons": "^2.8.1", "lodash": "^4.17.20" @@ -3661,25 +3661,25 @@ } }, "node_modules/@gravity-ui/date-components": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/date-components/-/date-components-2.4.0.tgz", - "integrity": "sha512-S2csYch90OT6SvvjxzO1TtkGR0BEF8mGdxJzQ/5mbm1Tpk6ilHAjZ2dlAvzYQxdHNKqqmfA92NV+GjyfgsuGBg==", + "version": "2.10.3", + "resolved": "https://registry.npmjs.org/@gravity-ui/date-components/-/date-components-2.10.3.tgz", + "integrity": "sha512-hGcXSnDIKA1YDr/6k/xGXJJv/AcA2xi5jFB1nYWakz5umvB11/yqudfSBndFfDbfBINtREPjlYzTIzGqz5TEbg==", "dependencies": { "@bem-react/classname": "^1.6.0", - "@gravity-ui/date-utils": "^2.0.1", + "@gravity-ui/date-utils": "^2.5.3", "@gravity-ui/icons": "^2.2.0", "tslib": "^2.6.2" }, "peerDependencies": { "@gravity-ui/uikit": "^6.0.0", - "react": "^17.0.0 || ^18.0.0", - "react-dom": "^17.0.0 || ^18.0.0" + "react": ">=17.0.0", + "react-dom": ">=17.0.0" } }, "node_modules/@gravity-ui/date-utils": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/date-utils/-/date-utils-2.4.0.tgz", - "integrity": "sha512-Bm2s4tsrRoNeBjc1Jxz16xRouR4OljADkPUE1aRAf+aQqZfS1hog/sHnXX802B/LrseoYJbxgLE98aNm5cryZg==", + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/@gravity-ui/date-utils/-/date-utils-2.5.5.tgz", + "integrity": "sha512-82IzJwmOaDqrJVa7IXOhWqI60epNx63gseiRhUOMDfAza+ra4tRORfTNa9ofV/lGYW5DVqoWJulMNpzDU0cM2g==", "dependencies": { "dayjs": "1.11.10", "lodash": "^4.17.0" @@ -31511,20 +31511,20 @@ } }, "@gravity-ui/date-components": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/date-components/-/date-components-2.4.0.tgz", - "integrity": "sha512-S2csYch90OT6SvvjxzO1TtkGR0BEF8mGdxJzQ/5mbm1Tpk6ilHAjZ2dlAvzYQxdHNKqqmfA92NV+GjyfgsuGBg==", + "version": "2.10.3", + "resolved": "https://registry.npmjs.org/@gravity-ui/date-components/-/date-components-2.10.3.tgz", + "integrity": "sha512-hGcXSnDIKA1YDr/6k/xGXJJv/AcA2xi5jFB1nYWakz5umvB11/yqudfSBndFfDbfBINtREPjlYzTIzGqz5TEbg==", "requires": { "@bem-react/classname": "^1.6.0", - "@gravity-ui/date-utils": "^2.0.1", + "@gravity-ui/date-utils": "^2.5.3", "@gravity-ui/icons": "^2.2.0", "tslib": "^2.6.2" } }, "@gravity-ui/date-utils": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/@gravity-ui/date-utils/-/date-utils-2.4.0.tgz", - "integrity": "sha512-Bm2s4tsrRoNeBjc1Jxz16xRouR4OljADkPUE1aRAf+aQqZfS1hog/sHnXX802B/LrseoYJbxgLE98aNm5cryZg==", + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/@gravity-ui/date-utils/-/date-utils-2.5.5.tgz", + "integrity": "sha512-82IzJwmOaDqrJVa7IXOhWqI60epNx63gseiRhUOMDfAza+ra4tRORfTNa9ofV/lGYW5DVqoWJulMNpzDU0cM2g==", "requires": { "dayjs": "1.11.10", "lodash": "^4.17.0" diff --git a/package.json b/package.json index 24262ef1..d32e09e0 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,8 @@ "dependencies": { "@bem-react/classname": "^1.6.0", "@gravity-ui/components": "^3.0.0", - "@gravity-ui/date-components": "^2.4.0", - "@gravity-ui/date-utils": "^2.4.0", + "@gravity-ui/date-components": "^2.10.3", + "@gravity-ui/date-utils": "^2.5.5", "@gravity-ui/i18n": "^1.2.0", "@gravity-ui/icons": "^2.8.1", "lodash": "^4.17.20" diff --git a/src/lib/core/types/specs.ts b/src/lib/core/types/specs.ts index 02aa0ce7..611e2bff 100644 --- a/src/lib/core/types/specs.ts +++ b/src/lib/core/types/specs.ts @@ -182,6 +182,7 @@ export interface StringSpec< dateInput?: { outputFormat?: string; printFormat?: string; + timeZone?: string; }; copy?: boolean; selectParams?: { diff --git a/src/lib/kit/components/Inputs/DateInput/DateInput.tsx b/src/lib/kit/components/Inputs/DateInput/DateInput.tsx index d765b594..d3d1fe87 100644 --- a/src/lib/kit/components/Inputs/DateInput/DateInput.tsx +++ b/src/lib/kit/components/Inputs/DateInput/DateInput.tsx @@ -2,12 +2,12 @@ import React, {useCallback} from 'react'; import {DatePicker, DatePickerProps} from '@gravity-ui/date-components'; import {StringInputProps} from '../../../../core'; -import {DateTime, dateTimeParse} from '@gravity-ui/date-utils'; +import {DateTime, dateTimeParse, isValidTimeZone} from '@gravity-ui/date-utils'; import {block} from '../../../utils'; import './DateInput.scss'; -export const DEFAULT_DATE_FORMAT = 'DD-MM-YYYY'; +export const DEFAULT_DATE_FORMAT = 'DD.MM.YYYY HH:mm'; const b = block('date-input'); @@ -22,6 +22,8 @@ export const DateInput: React.FC> = ({ }) => { const {value, onChange, onBlur, onFocus} = input; const dateInput = spec.viewSpec.dateInput; + const timeZone = + dateInput?.timeZone && isValidTimeZone(dateInput.timeZone) ? dateInput.timeZone : undefined; const outputFormat = dateInput?.outputFormat; const onUpdate = useCallback( @@ -63,11 +65,15 @@ export const DateInput: React.FC> = ({ onBlur: onBlur as (e: React.FocusEvent) => void, onFocus: onFocus as (e: React.FocusEvent) => void, value: value - ? dateTimeParse((value as any).seconds ? (value as any).seconds * 1000 : value) || null + ? dateTimeParse((value as any).seconds ? (value as any).seconds * 1000 : value, { + format: dateInput?.outputFormat, + timeZone, + }) || null : null, onUpdate, disabled: spec.viewSpec.disabled, placeholder: spec.viewSpec.placeholder, + timeZone, }; return ; diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-chromium-linux.png index 23acce14..7d284e3c 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-webkit-linux.png index 287a8d0b..b3420ccc 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-dark-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-chromium-linux.png index c56aa2cb..390abf8a 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-webkit-linux.png index a54662cd..9eafb868 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-light-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-dark-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-dark-chromium-linux.png index 988d8ceb..055e3467 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-dark-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-dark-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-dark-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-dark-webkit-linux.png index 95d774c5..3ab0385b 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-dark-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-dark-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-light-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-light-chromium-linux.png index 008e2f93..03397c0f 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-light-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-light-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-light-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-light-webkit-linux.png index 87c1ef86..2d9362b7 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-light-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-default-value-light-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-chromium-linux.png index 933cb011..30dbdf05 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-webkit-linux.png index 51637c73..db9e40fe 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-dark-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-chromium-linux.png index 2bb57b7a..1ba8f704 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-webkit-linux.png index 1ae5e767..254a8cf2 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-full-light-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-chromium-linux.png index 13c174fb..f94f17f6 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-webkit-linux.png index 124d65d2..c5d8cbaf 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-dark-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-light-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-light-chromium-linux.png index d81d4d78..ce540f70 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-light-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-light-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-light-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-light-webkit-linux.png index 101e2925..696db7e9 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-light-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-layout-transparent-light-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-chromium-linux.png index 25788930..c93310df 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-webkit-linux.png index 4681e9f4..d9f72a7f 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-dark-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-chromium-linux.png index b3df7fd2..22ab2468 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-webkit-linux.png index dbbe6337..56d5da0e 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-row-verbose-light-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-chromium-linux.png index ea07a5e0..3cd90f61 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-webkit-linux.png index 40a440e6..06747913 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-dark-webkit-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-light-chromium-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-light-chromium-linux.png index dd41b137..b9eb5557 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-light-chromium-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-light-chromium-linux.png differ diff --git a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-light-webkit-linux.png b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-light-webkit-linux.png index 53ab422f..c3d37a78 100644 Binary files a/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-light-webkit-linux.png and b/src/lib/kit/components/Inputs/DateInput/__snapshots__/DateInput.visual.test.tsx-snapshots/DateInput-view-default-light-webkit-linux.png differ diff --git a/src/lib/kit/components/Views/DateView/DateView.tsx b/src/lib/kit/components/Views/DateView/DateView.tsx index ec23a7eb..84a65121 100644 --- a/src/lib/kit/components/Views/DateView/DateView.tsx +++ b/src/lib/kit/components/Views/DateView/DateView.tsx @@ -1,10 +1,9 @@ import React from 'react'; -import {StringSpec, StringViewProps} from '../../../../core'; +import {StringViewProps} from '../../../../core'; import {BaseView, DEFAULT_DATE_FORMAT} from '../../../components'; import {dateTimeParse} from '@gravity-ui/date-utils'; import isObject from 'lodash/isObject'; -import {DatePickerProps} from '@gravity-ui/date-components/dist/esm/components/DatePicker/DatePicker'; interface Timestamp { seconds: string; @@ -12,18 +11,24 @@ interface Timestamp { } export const DateView: React.FC = ({value, spec, ...restProps}) => { - let formatedValue = - value && isObject(value) && (value as object as Timestamp).seconds - ? (value as any)?.seconds * 1000 - : value; + const { + printFormat = DEFAULT_DATE_FORMAT, + outputFormat, + timeZone, + } = spec.viewSpec.dateInput || {}; - const localSpec = (spec as StringSpec)!.viewSpec; + let formatedValue: string | number | undefined = value; - const format = - localSpec.inputProps?.format || localSpec.dateInput?.printFormat || DEFAULT_DATE_FORMAT; + if (isObject(value) && (value as Timestamp).seconds) { + formatedValue = Number((value as unknown as Timestamp).seconds) * 1000; + } + + if (formatedValue) { + const date = dateTimeParse(formatedValue, {format: outputFormat, timeZone}); - if (formatedValue && format) { - formatedValue = dateTimeParse(formatedValue)?.format(format) || formatedValue; + if (date) { + formatedValue = date.format(printFormat); + } } return ; diff --git a/src/stories/components/InputPreview/constants.ts b/src/stories/components/InputPreview/constants.ts index 0ddd8eb0..af589c9f 100644 --- a/src/stories/components/InputPreview/constants.ts +++ b/src/stories/components/InputPreview/constants.ts @@ -549,6 +549,10 @@ const dateInput: ObjectSpec = { type: SpecTypes.String, viewSpec: {type: 'base', layout: 'row', layoutTitle: 'Print format'}, }, + timeZone: { + type: SpecTypes.String, + viewSpec: {type: 'base', layout: 'row', layoutTitle: 'Time zone'}, + }, }, viewSpec: { type: 'base',