diff --git a/src/tools/DateTools.js b/src/tools/DateTools.js new file mode 100644 index 00000000..4582d88e --- /dev/null +++ b/src/tools/DateTools.js @@ -0,0 +1,33 @@ +import {format, parse, parseISO} from 'date-fns' + +/** + * + * @param {string | number | Date} date if string, must be of ISO format, YYYY-MM-DD HH:mm:ss (Infor format), or of UNIX timestamp as string + * @param {boolean | undefined} showTime optional, include time in returned date + * @returns a date of format DD-LLL-YYYY [HH:mm:ss] eg. 01-Jan-2000 + */ +export const formatConsistentDate = (date, showTime) => { + if (!date) { + return; + } + + let parsedDate = date; + + // If arg is a string + if (typeof date === "string") { + // If arg is a locale formatted date + if (date.indexOf('-') !== -1) { + parsedDate = parse(date, "yyyy-LL-dd' 'HH:mm:ss'.0'", new Date()) + } + else if (date.indexOf('T') !== -1) { + // + parsedDate = parseISO(date) + } + else { + // Assume arg is a UNIX timestamp as a string, and parse to int + parsedDate = parseInt(date) + } + } + + return format(parsedDate, `dd-LLL-yyyy${showTime ? " HH:mm:ss" : ""}`) +} \ No newline at end of file diff --git a/src/ui/pages/equipment/components/EquipmentMTFWorkOrders.js b/src/ui/pages/equipment/components/EquipmentMTFWorkOrders.js index f20d532a..e57b8e4d 100644 --- a/src/ui/pages/equipment/components/EquipmentMTFWorkOrders.js +++ b/src/ui/pages/equipment/components/EquipmentMTFWorkOrders.js @@ -6,6 +6,7 @@ import EAMTableGridRequestAdapter from "eam-components/dist/ui/components/eamtab import compareAsc from 'date-fns/compareAsc' import parse from 'date-fns/parse' import { withCernMode } from '../../../components/CERNMode'; +import { formatConsistentDate } from "../../../../tools/DateTools"; const DATE_FORMAT = "dd-LLL-yyyy"; @@ -14,26 +15,32 @@ const customCellStyle = { } const customCellRenderer = ({ row, columnMetadata, getDisplayValue, CellComponent }) => { - const customRenders = { - "last_repeated_status_color": ( - - ), - "mtf_step": ( - - - {getDisplayValue()} - - - ), - "evt_desc": ( - {getDisplayValue()} - ) + const customRenders = (id) => { + switch (id) { + case "last_repeated_status_color": return ( + + ) + case "mtf_step": return ( + + + {getDisplayValue()} + + + ) + case "evt_desc": return ( + {getDisplayValue()} + ) + case "evt_completed": return ( + {formatConsistentDate(getDisplayValue())} + ) + } + } - return customRenders[columnMetadata.id] || {getDisplayValue()}; + return customRenders(columnMetadata.id) || {getDisplayValue()}; } const headers = {