mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	Fix time display and allow date format customisation
This commit is contained in:
		
							parent
							
								
									5e120f3836
								
							
						
					
					
						commit
						f5bb009fa3
					
				@ -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;
 | 
				
			||||||
@ -5,11 +5,12 @@ import { get, isEmpty, isNull, isObject, toLower, toString } from 'lodash';
 | 
				
			|||||||
import moment from 'moment';
 | 
					import moment from 'moment';
 | 
				
			||||||
import { IcoContainer, useGlobalContext } from 'strapi-helper-plugin';
 | 
					import { IcoContainer, useGlobalContext } from 'strapi-helper-plugin';
 | 
				
			||||||
import useListView from '../../hooks/useListView';
 | 
					import useListView from '../../hooks/useListView';
 | 
				
			||||||
 | 
					 | 
				
			||||||
import CustomInputCheckbox from '../CustomInputCheckbox';
 | 
					import CustomInputCheckbox from '../CustomInputCheckbox';
 | 
				
			||||||
import MediaPreviewList from '../MediaPreviewList';
 | 
					import MediaPreviewList from '../MediaPreviewList';
 | 
				
			||||||
 | 
					 | 
				
			||||||
import { ActionContainer, Truncate, Truncated } from './styledComponents';
 | 
					import { ActionContainer, Truncate, Truncated } from './styledComponents';
 | 
				
			||||||
 | 
					import DATE_FORMATS from './DATE_FORMATS';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const dateToUtcTime = date => moment.parseZone(date).utc();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const getDisplayedValue = (type, value, name) => {
 | 
					const getDisplayedValue = (type, value, name) => {
 | 
				
			||||||
  switch (toLower(type)) {
 | 
					  switch (toLower(type)) {
 | 
				
			||||||
@ -28,7 +29,6 @@ const getDisplayedValue = (type, value, name) => {
 | 
				
			|||||||
    case 'boolean':
 | 
					    case 'boolean':
 | 
				
			||||||
      return value !== null ? toString(value) : '-';
 | 
					      return value !== null ? toString(value) : '-';
 | 
				
			||||||
    case 'date':
 | 
					    case 'date':
 | 
				
			||||||
    case 'time':
 | 
					 | 
				
			||||||
    case 'datetime':
 | 
					    case 'datetime':
 | 
				
			||||||
    case 'timestamp': {
 | 
					    case 'timestamp': {
 | 
				
			||||||
      if (value == null) {
 | 
					      if (value == null) {
 | 
				
			||||||
@ -40,10 +40,7 @@ const getDisplayedValue = (type, value, name) => {
 | 
				
			|||||||
          ? JSON.stringify(value)
 | 
					          ? JSON.stringify(value)
 | 
				
			||||||
          : value;
 | 
					          : value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      return moment
 | 
					      return dateToUtcTime(date).format(DATE_FORMATS[type]);
 | 
				
			||||||
        .parseZone(date)
 | 
					 | 
				
			||||||
        .utc()
 | 
					 | 
				
			||||||
        .format('dddd, MMMM Do YYYY');
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    case 'password':
 | 
					    case 'password':
 | 
				
			||||||
      return '••••••••';
 | 
					      return '••••••••';
 | 
				
			||||||
@ -51,6 +48,16 @@ const getDisplayedValue = (type, value, name) => {
 | 
				
			|||||||
    case 'file':
 | 
					    case 'file':
 | 
				
			||||||
    case 'files':
 | 
					    case 'files':
 | 
				
			||||||
      return value;
 | 
					      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:
 | 
					    default:
 | 
				
			||||||
      return '-';
 | 
					      return '-';
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user