Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(FE): Fix date dashboard #311

Merged
merged 2 commits into from
Sep 28, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Typography } from 'antd';
import convertDateToAmAndPm from 'lib/convertDateToAmAndPm';
import getFormattedDate from 'lib/getFormatedDate';
import React from 'react';

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;
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { Typography } from 'antd';
import convertDateToAmAndPm from 'lib/convertDateToAmAndPm';
import getFormattedDate from 'lib/getFormatedDate';
import React from 'react';

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;
11 changes: 10 additions & 1 deletion frontend/src/container/ListOfDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,22 @@ const ListOfAllDashboard = (): JSX.Element => {
{
title: 'Created By',
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,
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/convertDateToAmAndPm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const convertDateToAmAndPm = (date: Date): string => {
return date.toLocaleString('en-US', {
hour: 'numeric',
hour: '2-digit',
minute: 'numeric',
hour12: true,
});
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/lib/getFormatedDate.ts
Original file line number Diff line number Diff line change
@@ -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;