Fix time display and allow date format customisation

This commit is contained in:
soupette 2019-12-26 15:06:01 +01:00
parent 5e120f3836
commit f5bb009fa3
2 changed files with 22 additions and 7 deletions

View File

@ -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;

View File

@ -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 '-';
}