Fix(FE): Fix date dashboard (#311)

* chore: getFormatedDate function is added

* fix: date format in the all dashboard is updated to mm/dd/yyyy HH:MM
This commit is contained in:
Palash 2021-09-28 18:32:02 +05:30 committed by GitHub
parent e756cefa75
commit cc91242e9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 9 deletions

View File

@ -1,5 +1,6 @@
import { Typography } from 'antd';
import convertDateToAmAndPm from 'lib/convertDateToAmAndPm';
import getFormattedDate from 'lib/getFormatedDate';
import React from 'react';
import { Data } from '..';
@ -7,11 +8,11 @@ import { Data } from '..';
const Created = (createdBy: Data['createdBy']): JSX.Element => {
const time = new Date(createdBy);
return (
<Typography>{`${time.toLocaleDateString()} ${convertDateToAmAndPm(
time,
)}`}</Typography>
);
const date = getFormattedDate(time);
const timeString = `${date} ${convertDateToAmAndPm(time)}`;
return <Typography>{`${timeString}`}</Typography>;
};
export default Created;

View File

@ -1,4 +1,6 @@
import { Typography } from 'antd';
import convertDateToAmAndPm from 'lib/convertDateToAmAndPm';
import getFormattedDate from 'lib/getFormatedDate';
import React from 'react';
import { Data } from '..';
@ -6,9 +8,13 @@ import { Data } from '..';
const DateComponent = (
lastUpdatedTime: Data['lastUpdatedTime'],
): JSX.Element => {
const date = new Date(lastUpdatedTime).toDateString();
const time = new Date(lastUpdatedTime);
return <Typography>{date}</Typography>;
const date = getFormattedDate(time);
const timeString = `${date} ${convertDateToAmAndPm(time)}`;
return <Typography>{timeString}</Typography>;
};
export default DateComponent;

View File

@ -49,13 +49,22 @@ const ListOfAllDashboard = (): JSX.Element => {
{
title: 'Created At',
dataIndex: 'createdBy',
sorter: (a: Data, b: Data): number => {
const prev = new Date(a.createdBy).getTime();
const next = new Date(b.createdBy).getTime();
return prev - next;
},
render: Createdby,
},
{
title: 'Last Updated Time',
dataIndex: 'lastUpdatedTime',
sorter: (a: Data, b: Data): number => {
return parseInt(a.lastUpdatedTime, 10) - parseInt(b.lastUpdatedTime, 10);
const prev = new Date(a.lastUpdatedTime).getTime();
const next = new Date(b.lastUpdatedTime).getTime();
return prev - next;
},
render: DateComponent,
},

View File

@ -1,6 +1,6 @@
const convertDateToAmAndPm = (date: Date): string => {
return date.toLocaleString('en-US', {
hour: 'numeric',
hour: '2-digit',
minute: 'numeric',
hour12: true,
});

View File

@ -0,0 +1,13 @@
function getFormattedDate(date: Date): string {
const year = date.getFullYear();
let month = (1 + date.getMonth()).toString();
month = month.length > 1 ? month : '0' + month;
let day = date.getDate().toString();
day = day.length > 1 ? day : '0' + day;
return month + '/' + day + '/' + year;
}
export default getFormattedDate;