You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.2 KiB
88 lines
2.2 KiB
const React = require('react'); |
|
const dayjs = require('dayjs'); |
|
|
|
export const TimeBetweenRows = ({ row, nextRow }) => { |
|
if (nextRow) { |
|
const firstDate = dayjs(row.timestamp); |
|
const secondDate = dayjs(nextRow.timestamp); |
|
const theDiff = firstDate.diff(secondDate); |
|
const theSeconds = theDiff / 1000; |
|
const theMinutes = theSeconds / 60; |
|
const theHours = theMinutes / 60; |
|
const theDays = theHours / 24; |
|
|
|
// console.log(theDiff, theSeconds, theMinutes, theHours, theDays); |
|
|
|
const renderSecs = <>{theSeconds === 1 ? 'sec' : 'secs'}</>; |
|
const renderMins = <>{theMinutes === 1 ? 'min ' : 'mins '}</>; |
|
const renderHrs = <>{theHours === 1 ? 'hr ' : 'hrs '}</>; |
|
const renderDays = <>{theDays === 1 ? 'day ' : 'days '}</>; |
|
|
|
return ( |
|
<> |
|
{/* secs */} |
|
{theSeconds < 60 ? ( |
|
<> |
|
{Math.round(theSeconds)} |
|
{renderSecs} |
|
</> |
|
) : null} |
|
|
|
{/* mins secs */} |
|
{theMinutes > 1 && theMinutes < 60 ? ( |
|
<> |
|
<> |
|
{Math.round(theMinutes)} |
|
{renderMins} |
|
</> |
|
<> |
|
{Math.round((theMinutes % 1) * 60)} |
|
{renderSecs} |
|
</> |
|
</> |
|
) : null} |
|
|
|
{/* hrs mins secs */} |
|
{theHours > 1 && theHours < 24 ? ( |
|
<> |
|
<> |
|
{Math.round(theHours)} |
|
{renderHrs} |
|
</> |
|
<> |
|
{Math.round((theHours % 1) * 60)} |
|
{renderMins} |
|
</> |
|
<> |
|
{Math.round((theMinutes % 1) * 60)} |
|
{renderSecs} |
|
</> |
|
</> |
|
) : null} |
|
|
|
{/* days hrs mins secs */} |
|
{theDays > 1 ? ( |
|
<> |
|
<> |
|
{Math.round(theDays)} |
|
{renderDays} |
|
</> |
|
<> |
|
{Math.round((theDays % 1) * 24)} |
|
{renderHrs} |
|
</> |
|
<> |
|
{Math.round((theHours % 1) * 60)} |
|
{renderMins} |
|
</> |
|
<> |
|
{Math.round((theMinutes % 1) * 60)} |
|
{renderSecs} |
|
</> |
|
</> |
|
) : null} |
|
</> |
|
); |
|
} |
|
return false; |
|
};
|
|
|