Skip to content

Commit

Permalink
Merge pull request #1217 from Real-Dev-Squad/develop
Browse files Browse the repository at this point in the history
Dev to Main Sync
  • Loading branch information
iamitprakash authored Jun 20, 2024
2 parents 305dc40 + 0e4fdbf commit 5514543
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ describe('LatestProgressUpdateCard Component', () => {
);

const momentDate = moment(mockGetTaskProgress.data[2].createdAt);
const fullDate = momentDate.format('DD-MM-YY');
const time = momentDate.format('hh:mmA');
const fullDate = momentDate.format(
'dddd, MMMM DD, YYYY, hh:mm A [GMT] Z'
);
const tooltipString = `Updated at ${fullDate}`;

const tooltipString = `Updated at ${fullDate}, ${time}`;
const dateElement = screen.getByTestId(
'latest-progress-update-card-date'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ describe('ProgressUpdateCard Component', () => {
);

const momentDate = moment(mockGetTaskProgress.data[2].createdAt);
const fullDate = momentDate.format('DD-MM-YY');
const time = momentDate.format('hh:mmA');

const tooltipString = `Updated at ${fullDate}, ${time}`;
const fullDate = momentDate.format(
'dddd, MMMM DD, YYYY, hh:mm A [GMT] Z'
);
const tooltipString = `Updated at ${fullDate}`;
const dateElement = screen.getByTestId('progress-update-card-date');

fireEvent.mouseOver(dateElement);
Expand Down
61 changes: 34 additions & 27 deletions src/components/taskDetails/Details.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC } from 'react';
import React, { FC, useState } from 'react';
import moment from 'moment';
import Link from 'next/link';
import { FaReceipt } from 'react-icons/fa6';
import Link from 'next/link';
import Tooltip from '@/components/common/Tooltip/Tooltip';
import setColor from './taskPriorityColors';
import extractRepoName from '@/utils/extractRepoName';
Expand All @@ -19,33 +19,38 @@ const Details: FC<TaskDetailsProps> = ({ detailType, value, url }) => {
return timestamp ? moment(timestamp).fromNow() : 'N/A';
};

const getTooltipText = (timestamp: StringNumberOrUndefined): string => {
return timestamp ? moment(timestamp).format('LLLL') : 'N/A';
};

const isPastDate = (timestamp: StringNumberOrUndefined): boolean => {
return timestamp ? moment(timestamp).isBefore(moment()) : false;
};

/**
* Get human-readable time format from the provided timestamp.
* @param {string | number | undefined} timestamp - The timestamp.
* @returns {string} - The human-readable time format, for example: instead of displaying a timestamp like "2024-02-20T14:30:00", a human-readable format would present it as "February 20, 2024, 2:30 PM
*/
const getHumanReadableTime = (
timestamp: StringNumberOrUndefined
): string => {
const formatDate = (timestamp: StringNumberOrUndefined): string => {
if (!timestamp) return 'N/A';

const now = moment();
const futureTimestamp = moment(timestamp);
let milliseconds: number;

if (futureTimestamp.isAfter(now)) {
return `in ${moment
.duration(futureTimestamp.diff(now))
.humanize()}`;
if (typeof timestamp === 'string') {
// Parse the timestamp string to Date object
const dateObj = new Date(timestamp);

// Check if parsing was successful
if (!isNaN(dateObj.getTime())) {
milliseconds = dateObj.getTime();
} else {
console.error('Invalid timestamp format:', timestamp);
return 'Invalid Date';
}
} else {
milliseconds = (timestamp as number) * 1000;
}
return `${moment.duration(now.diff(futureTimestamp)).humanize()} ago`;

// Format the date as desired
const formattedDate = moment(milliseconds).format(
'dddd, MMM D, YYYY, h:mm A [GMT] Z'
);

return formattedDate;
};

const [tooltipActive, setTooltipActive] = useState(false);

const toggleTooltip = () => {
setTooltipActive((prev) => !prev);
};

const isTimeDetail =
Expand Down Expand Up @@ -80,10 +85,12 @@ const Details: FC<TaskDetailsProps> = ({ detailType, value, url }) => {
</a>
) : isTimeDetail ? (
<Tooltip
content={getTooltipText(value)}
content={formatDate(value)}
tooltipPosition={{ top: '-3.6rem', right: '-4.5rem' }}
>
{getHumanReadableTime(value)}
{tooltipActive
? formatDate(value)
: getRelativeTime(value)}
</Tooltip>
) : (
renderedValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ export default function LatestProgressUpdateCard({
}: LatestProgressUpdateCardProps) {
const momentDate = moment(data?.createdAt);
const dateInAgoFormat = momentDate.fromNow();
const fullDate = momentDate.format('DD-MM-YY');
const time = momentDate.format('hh:mmA');
const tooltipText = `Updated at ${fullDate}, ${time}`;
const fullDate = momentDate.format('dddd, MMMM DD, YYYY, hh:mm A [GMT] Z');
const tooltipText = `Updated at ${fullDate}`;
const charactersToShow = 70;

const dataToShow = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export default memo(function ProgressUpdateCard({
const charactersToShow = 70;
const readMoreTitle = readMoreFormatter(data?.completed, charactersToShow);
const titleToShow = readMoreTitle;
const fullDate = momentDate.format('DD-MM-YY');
const time = momentDate.format('hh:mmA');
const tooltipString = `Updated at ${fullDate}, ${time}`;
const fullDate = momentDate.format('dddd, MMMM DD, YYYY, hh:mm A [GMT] Z');

const tooltipString = `Updated at ${fullDate}`;
const [isExpanded, setIsExpanded] = useState(false);

const dataToShow = [
Expand Down

0 comments on commit 5514543

Please sign in to comment.