diff --git a/web/client/components/data/featuregrid/editors/DateTimeEditor.jsx b/web/client/components/data/featuregrid/editors/DateTimeEditor.jsx index 7e15feb058..1b5b99f1d3 100644 --- a/web/client/components/data/featuregrid/editors/DateTimeEditor.jsx +++ b/web/client/components/data/featuregrid/editors/DateTimeEditor.jsx @@ -3,7 +3,8 @@ import AttributeEditor from "./AttributeEditor"; import React from "react"; import DateTimePicker from "../../../misc/datetimepicker"; import utcDateWrapper from "../../../misc/enhancers/utcDateWrapper"; -import {dateFormats} from "../../../../utils/FeatureGridUtils"; + +import {getDateTimeFormat} from "../formatters"; /** * Date time picker enhanced with UTC and timezone offset @@ -27,6 +28,7 @@ class DateTimeEditor extends AttributeEditor { static propTypes = { value: PropTypes.string, inputProps: PropTypes.object, + rowData: PropTypes.object, dataType: PropTypes.string, minValue: PropTypes.number, maxValue: PropTypes.number, @@ -75,13 +77,13 @@ class DateTimeEditor extends AttributeEditor { }; render() { - const {dataType, calendar, time} = this.props; - const { value } = this.props; + const {dataType, calendar, time, value, rowData} = this.props; return (); } // when we are using the popover we are using a portal diff --git a/web/client/components/data/featuregrid/enhancers/editor.js b/web/client/components/data/featuregrid/enhancers/editor.js index 94ce025f5f..c5a3635344 100644 --- a/web/client/components/data/featuregrid/enhancers/editor.js +++ b/web/client/components/data/featuregrid/enhancers/editor.js @@ -114,7 +114,8 @@ const featuresToGrid = compose( get: key => { return (key === "geometry" || key === "_new") ? result[key] : result.properties && result.properties[key]; }, - dateFormats: props.dateFormats + dateFormats: props.dateFormats, + useUTCOffset: props.useUTCOffset })) }) ), diff --git a/web/client/components/data/featuregrid/formatters/index.js b/web/client/components/data/featuregrid/formatters/index.js index 0bc3a92a82..9c38b1c92a 100644 --- a/web/client/components/data/featuregrid/formatters/index.js +++ b/web/client/components/data/featuregrid/formatters/index.js @@ -23,10 +23,10 @@ export const StringFormatter = ({value} = {}) => !isNil(value) ? reactStringRepl export const NumberFormatter = ({value} = {}) => !isNil(value) ? : null; const DEFAULT_DATE_PART = "1970-01-01"; const DATE_INPUT_FORMAT = "YYYY-MM-DD[Z]"; -export const DateTimeFormatter = ({value, format, type}) => { +export const DateTimeFormatter = ({value, format, type, useUTCOffset = true}) => { return !isNil(value) ? moment.utc(value).isValid() // geoserver sometimes returns UTC for time. - ? moment.utc(value).format(format) + ? useUTCOffset ? moment.utc(value).format(format) : moment(value).format(format) : type === 'time' ? moment(`${DEFAULT_DATE_PART}T${value}`).utc().format(format) // time format append default date part : type === "date" && value?.toLowerCase()?.endsWith("z") // in case: date format and value ends with z @@ -39,13 +39,14 @@ const EnhancedStringFormatter = handleLongTextEnhancer(StringFormatter); const EnhancedNumberFormatter = handleLongTextEnhancer(NumberFormatter); const enhancedDateTimeFormatter = handleLongTextEnhancer(DateTimeFormatter); -const getDateTimeFormat = (dateFormats, localType) => get(dateFormats, localType) ?? defaultDateFormats[localType]; +export const getDateTimeFormat = (dateFormats, localType) => get(dateFormats, localType) ?? defaultDateFormats[localType]; const createEnhancedDateTimeFormatterComponent = (type) => (props) => { - const { dateFormats } = props?.row || {}; + const { dateFormats, useUTCOffset } = props?.row || {}; const format = getDateTimeFormat(dateFormats, type); return enhancedDateTimeFormatter({ ...props, + useUTCOffset, format, type }); @@ -98,7 +99,7 @@ export const getFormatter = (desc, {featureGridFormatter} = {}) => { return Formatter; } return (props) => { - return ; + return ; }; } // we should avoid to create component in formatters diff --git a/web/client/components/misc/enhancers/utcDateWrapper.js b/web/client/components/misc/enhancers/utcDateWrapper.js index 2e6c688c1d..b798e208f1 100644 --- a/web/client/components/misc/enhancers/utcDateWrapper.js +++ b/web/client/components/misc/enhancers/utcDateWrapper.js @@ -32,7 +32,11 @@ const DEFAULT_TIME_PART = "00:00:00"; * actual timezone */ -export default ({dateTypeProp = "type", dateProp = 'date', setDateProp = 'onSetDate'} = {}) => compose( +export default ({ + dateTypeProp = "type", + dateProp = 'date', + setDateProp = 'onSetDate' +} = {}) => compose( withPropsOnChange([dateProp], ({ [dateProp]: date, [dateTypeProp]: type, useUTCOffset = true }) => { let dateToParse = date; let datePart = DEFAULT_DATE_PART; diff --git a/web/client/plugins/FeatureEditor.jsx b/web/client/plugins/FeatureEditor.jsx index 0f141132e2..32d274a216 100644 --- a/web/client/plugins/FeatureEditor.jsx +++ b/web/client/plugins/FeatureEditor.jsx @@ -77,6 +77,7 @@ import {isViewportFilterActive} from "../selectors/featuregrid"; * @prop {array} cfg.snapConfig.additionalLayers Array of additional layers to include into snapping layers list. Provides a way to include layers from "state.additionallayers". * @prop {array} cfg.filterByViewport Activate filter by viewport tool by default. * @prop {array} cfg.showFilterByViewportTool Show button to toggle filter by viewport in toolbar. + * @prop {boolean} cfg.useUTCOffset avoid using UTC dates in attribute table and datetime editor, should be kept consistent with dateFormats * @prop {object} cfg.dateFormats Allows to specify custom date formats ( in [ISO_8601](https://en.wikipedia.org/wiki/ISO_8601) format) to use to display dates in the table. `date` `date-time` and `time` are the supported entries for the date format. Example: * @prop {boolean} cfg.showPopoverSync default false. Hide the popup of map sync if false, shows the popup of map sync if true * ``` diff --git a/web/client/plugins/featuregrid/FeatureEditor.jsx b/web/client/plugins/featuregrid/FeatureEditor.jsx index 0873b815e6..6479667a0a 100644 --- a/web/client/plugins/featuregrid/FeatureEditor.jsx +++ b/web/client/plugins/featuregrid/FeatureEditor.jsx @@ -95,6 +95,7 @@ const Dock = connect(createSelector( * @prop {number} cfg.snapConfig.maxFeatures defines features limit for request that loads vector data of WMS layer. * @prop {array} cfg.snapConfig.additionalLayers Array of additional layers to include into snapping layers list. Provides a way to include layers from "state.additionallayers" * @prop {object} cfg.dateFormats object containing custom formats for one of the date/time attribute types. Following keys are supported: "date-time", "date", "time" + * @prop {boolean} cfg.useUTCOffset avoid using UTC dates in attribute table and datetime editor, should be kept consistent with dateFormats, default is true * @prop {boolean} cfg.showPopoverSync default false. Hide the popup of map sync if false, shows the popup of map sync if true * * @classdesc @@ -138,7 +139,8 @@ const Dock = connect(createSelector( * "date-time": "YYYY-MM-DDTHH:mm:ss[Z]", * "date": "YYYY-MM-DD[Z]", * "time": "HH:mm:ss[Z]" - * } + * }, + * "useUTCOffset": true * } * } * ``` @@ -245,6 +247,7 @@ const FeatureDock = (props = { size={props.size} actionOpts={{maxZoom}} dateFormats={props.dateFormats} + useUTCOffset={props.useUTCOffset} /> }