Skip to content

Commit

Permalink
feat: added date time formatter in resource explorer table #2140
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandru-HM authored and diehbria committed Nov 21, 2023
1 parent cea7c30 commit 10137b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type TableProps } from '@cloudscape-design/components/table';
import React from 'react';

import type { AssetTableNameLinkProps } from './assetTableNameLink';
import { getFormattedDateTime } from '~/components/util/dateTimeUtil';

type AssetTableColumnDefinitions = TableProps<AssetSummary>['columnDefinitions'];

Expand Down Expand Up @@ -80,7 +81,7 @@ export class AssetTableColumnDefinitionsFactory {
return {
id: 'creationDate',
header: 'Creation Date',
cell: ({ creationDate }) => creationDate?.toString() ?? '-',
cell: ({ creationDate }) => (creationDate ? getFormattedDateTime(creationDate) : '-'),
sortingField: 'creationDate',
};
}
Expand All @@ -89,7 +90,7 @@ export class AssetTableColumnDefinitionsFactory {
return {
id: 'lastUpdateDate',
header: 'Last Update Date',
cell: ({ lastUpdateDate }) => lastUpdateDate?.toString() ?? '-',
cell: ({ lastUpdateDate }) => (lastUpdateDate ? getFormattedDateTime(lastUpdateDate) : '-'),
sortingField: 'lastUpdateDate',
};
}
Expand Down
6 changes: 6 additions & 0 deletions packages/dashboard/src/components/util/dateTimeUtil.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getFormattedDateTime } from './dateTimeUtil';

it('should format the Date to full Date and Time value', () => {
const rawDate = new Date(1665583620000 + new Date().getTimezoneOffset() * 60000);
expect(getFormattedDateTime(rawDate)).toEqual(`10/12/22 14:07:00`);
});
7 changes: 7 additions & 0 deletions packages/dashboard/src/components/util/dateTimeUtil.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Format Date object to get date and time to display MM/DD/YY HH:MM:SS format
export const getFormattedDateTime = (rawDate: Date) => {
const date = rawDate.getMonth() + 1 + '/' + rawDate.getDate() + '/' + rawDate.getFullYear().toString().slice(-2);
const time = rawDate.toTimeString().split(' ')[0];
const dateTime = date + ' ' + time;
return dateTime;
};

0 comments on commit 10137b7

Please sign in to comment.