diff --git a/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/DATE_FORMATS.js b/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/DATE_FORMATS.js new file mode 100644 index 0000000000..4896778763 --- /dev/null +++ b/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/DATE_FORMATS.js @@ -0,0 +1,8 @@ +const DATE_FORMATS = { + date: 'dddd, MMMM Do YYYY', + datetime: 'dddd, MMMM Do YYYY HH:mm', + time: 'HH:mm A', + timestamp: 'dddd, MMMM Do YYYY', +}; + +export default DATE_FORMATS; diff --git a/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Row.js b/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Row.js index 07379b7f58..1486c55490 100644 --- a/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Row.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Row.js @@ -5,11 +5,12 @@ import { get, isEmpty, isNull, isObject, toLower, toString } from 'lodash'; import moment from 'moment'; import { IcoContainer, useGlobalContext } from 'strapi-helper-plugin'; import useListView from '../../hooks/useListView'; - import CustomInputCheckbox from '../CustomInputCheckbox'; import MediaPreviewList from '../MediaPreviewList'; - import { ActionContainer, Truncate, Truncated } from './styledComponents'; +import DATE_FORMATS from './DATE_FORMATS'; + +const dateToUtcTime = date => moment.parseZone(date).utc(); const getDisplayedValue = (type, value, name) => { switch (toLower(type)) { @@ -28,7 +29,6 @@ const getDisplayedValue = (type, value, name) => { case 'boolean': return value !== null ? toString(value) : '-'; case 'date': - case 'time': case 'datetime': case 'timestamp': { if (value == null) { @@ -40,10 +40,7 @@ const getDisplayedValue = (type, value, name) => { ? JSON.stringify(value) : value; - return moment - .parseZone(date) - .utc() - .format('dddd, MMMM Do YYYY'); + return dateToUtcTime(date).format(DATE_FORMATS[type]); } case 'password': return '••••••••'; @@ -51,6 +48,16 @@ const getDisplayedValue = (type, value, name) => { case 'file': case 'files': return value; + case 'time': { + const [hour, minute, second] = value.split(':'); + const timeObj = { + hour, + minute, + second, + }; + const date = moment().set(timeObj); + return dateToUtcTime(date).format(DATE_FORMATS.time); + } default: return '-'; }