Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/tools/DateTools.js
Original file line number Diff line number Diff line change
@@ -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" : ""}`)
}
45 changes: 26 additions & 19 deletions src/ui/pages/equipment/components/EquipmentMTFWorkOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -14,26 +15,32 @@ const customCellStyle = {
}

const customCellRenderer = ({ row, columnMetadata, getDisplayValue, CellComponent }) => {
const customRenders = {
"last_repeated_status_color": (
<CellComponent
style={{ backgroundColor: getDisplayValue() }}
/>
),
"mtf_step": (
<CellComponent>
<Link
to={{ pathname: `/workorder/${row["evt_code"]}` }}
>
{getDisplayValue()}
</Link>
</CellComponent>
),
"evt_desc": (
<CellComponent>{getDisplayValue()}</CellComponent>
)
const customRenders = (id) => {
switch (id) {
case "last_repeated_status_color": return (
<CellComponent
style={{ backgroundColor: getDisplayValue() }}
/>
)
case "mtf_step": return (
<CellComponent>
<Link
to={{ pathname: `/workorder/${row["evt_code"]}` }}
>
{getDisplayValue()}
</Link>
</CellComponent>
)
case "evt_desc": return (
<CellComponent>{getDisplayValue()}</CellComponent>
)
case "evt_completed": return (
<CellComponent>{formatConsistentDate(getDisplayValue())}</CellComponent>
)
}

}
return customRenders[columnMetadata.id] || <CellComponent style={customCellStyle}>{getDisplayValue()}</CellComponent>;
return customRenders(columnMetadata.id) || <CellComponent style={customCellStyle}>{getDisplayValue()}</CellComponent>;
}

const headers = {
Expand Down