diff --git a/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx b/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx index 00e6dce9..497b07ac 100644 --- a/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx +++ b/spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx @@ -308,6 +308,13 @@ export default function ProcessInstanceListTable({ return titleizeString((value || '').replaceAll('_', ' ')); }; + const formatDurationForDisplayForTable = (_row: any, value: any) => { + return DateAndTimeService.formatDurationForDisplay(value); + }; + const formatDateTimeForTable = (_row: any, value: any) => { + return DateAndTimeService.formatDateTime(value); + }; + const formatSecondsForDisplay = (_row: ProcessInstance, seconds: any) => { return DateAndTimeService.convertSecondsToFormattedDateTime(seconds) || '-'; }; @@ -330,8 +337,8 @@ export default function ProcessInstanceListTable({ last_milestone_bpmn_name: formatLastMilestone, }; const displayTypeFormatters: Record = { - date_time: DateAndTimeService.formatDateTime, - duration: DateAndTimeService.formatDurationForDisplay, + date_time: formatDateTimeForTable, + duration: formatDurationForDisplayForTable, }; const columnAccessor = column.accessor as keyof ProcessInstance; const formatter = column.display_type diff --git a/spiffworkflow-frontend/src/services/DateAndTimeService.test.tsx b/spiffworkflow-frontend/src/services/DateAndTimeService.test.tsx index ae6fb488..6eb38828 100644 --- a/spiffworkflow-frontend/src/services/DateAndTimeService.test.tsx +++ b/spiffworkflow-frontend/src/services/DateAndTimeService.test.tsx @@ -6,21 +6,17 @@ test('it can keep the correct date when converting seconds to date', () => { expect(dateString).toEqual('2022-10-21'); }); test('it can properly format a duration', () => { - expect(DateAndTimeService.formatDurationForDisplay(null, '0')).toEqual('0s'); - expect(DateAndTimeService.formatDurationForDisplay(null, '60')).toEqual('1m'); - expect(DateAndTimeService.formatDurationForDisplay(null, '65')).toEqual( - '1m 5s' - ); - expect(DateAndTimeService.formatDurationForDisplay(null, 65)).toEqual( - '1m 5s' - ); - expect(DateAndTimeService.formatDurationForDisplay(null, 86500)).toEqual( + expect(DateAndTimeService.formatDurationForDisplay('0')).toEqual('0s'); + expect(DateAndTimeService.formatDurationForDisplay('60')).toEqual('1m'); + expect(DateAndTimeService.formatDurationForDisplay('65')).toEqual('1m 5s'); + expect(DateAndTimeService.formatDurationForDisplay(65)).toEqual('1m 5s'); + expect(DateAndTimeService.formatDurationForDisplay(86500)).toEqual( '1d 1m 40s' ); - expect(DateAndTimeService.formatDurationForDisplay(null, 2629746)).toEqual( + expect(DateAndTimeService.formatDurationForDisplay(2629746)).toEqual( '30d 10h 29m 6s' ); - expect(DateAndTimeService.formatDurationForDisplay(null, 31536765)).toEqual( + expect(DateAndTimeService.formatDurationForDisplay(31536765)).toEqual( '365d 12m 45s' ); }); diff --git a/spiffworkflow-frontend/src/services/DateAndTimeService.tsx b/spiffworkflow-frontend/src/services/DateAndTimeService.tsx index eb973229..107d21f5 100644 --- a/spiffworkflow-frontend/src/services/DateAndTimeService.tsx +++ b/spiffworkflow-frontend/src/services/DateAndTimeService.tsx @@ -147,7 +147,7 @@ const secondsToDuration = (secNum: number) => { return duration; }; -const formatDurationForDisplay = (_row: any, value: any) => { +const formatDurationForDisplay = (value: any) => { if (value === undefined) { return undefined; } @@ -171,7 +171,7 @@ const formatDurationForDisplay = (_row: any, value: any) => { return durationTimes.join(' '); }; -const formatDateTime = (_row: any, value: any) => { +const formatDateTime = (value: any) => { if (value === undefined || value === null) { return value; } diff --git a/spiffworkflow-frontend/src/services/FormattingService.test.tsx b/spiffworkflow-frontend/src/services/FormattingService.test.tsx new file mode 100644 index 00000000..55c02b91 --- /dev/null +++ b/spiffworkflow-frontend/src/services/FormattingService.test.tsx @@ -0,0 +1,26 @@ +import FormattingService from './FormattingService'; + +test('it can convert date string to date for display', () => { + const markdown = + 'HEY SPIFF_FORMAT:::convert_date_to_date_for_display(2024-03-01)'; + expect(FormattingService.checkForSpiffFormats(markdown)).toEqual( + 'HEY 2024-03-01' + ); +}); + +// timezones for the lose +// test('it can convert seconds to date time for display', () => { +// const markdown = +// 'HEY SPIFF_FORMAT:::convert_seconds_to_date_time_for_display(10000)'; +// expect(FormattingService.checkForSpiffFormats(markdown)).toEqual( +// 'HEY 1969-12-31 21:46:40' +// ); +// }); + +test('it can convert seconds to duration time for display', () => { + const markdown = + 'HEY SPIFF_FORMAT:::convert_seconds_to_duration_for_display(10000)'; + expect(FormattingService.checkForSpiffFormats(markdown)).toEqual( + 'HEY 2h 46m 40s' + ); +}); diff --git a/spiffworkflow-frontend/src/services/FormattingService.tsx b/spiffworkflow-frontend/src/services/FormattingService.tsx index 07faa8e6..8d83fe81 100644 --- a/spiffworkflow-frontend/src/services/FormattingService.tsx +++ b/spiffworkflow-frontend/src/services/FormattingService.tsx @@ -4,6 +4,8 @@ const spiffFormatFunctions: { [key: string]: Function } = { convert_seconds_to_date_time_for_display: DateAndTimeService.formatDateTime, convert_seconds_to_duration_for_display: DateAndTimeService.formatDurationForDisplay, + convert_date_to_date_for_display: + DateAndTimeService.ymdDateStringToConfiguredFormat, }; const checkForSpiffFormats = (markdown: string) => { @@ -13,7 +15,7 @@ const checkForSpiffFormats = (markdown: string) => { originalValue: string ) => { if (spiffFormat in spiffFormatFunctions) { - return spiffFormatFunctions[spiffFormat](undefined, originalValue); + return spiffFormatFunctions[spiffFormat](originalValue); } console.warn( `attempted: ${match}, but ${spiffFormat} is not a valid conversion function`