Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 64b8d6e

Browse files
authored
FF-491 relative timestamps (#220)
* make timestamps relative for current day * update snapshots * fix linting
1 parent 658d6ca commit 64b8d6e

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/__tests__/__snapshots__/storybook.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ exports[`Storyshots Filesystem default 1`] = `
458458
className="col-md-1 col-3"
459459
onClick={[Function]}
460460
>
461-
Modified on
461+
Last Modified
462462
</div>
463463
<div
464464
className="col-md-1 col-3"

src/background/methods/dataTypes/time.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,42 @@ function getTimeStampFromDate(date: Date): number {
66
return Math.round(new Date(date).getTime() / 1000);
77
}
88

9+
function getRelativeTime(ts: number): string {
10+
const diff = Number(new Date()) - ts * 1000;
11+
const minute = 60 * 1000;
12+
const hour = minute * 60;
13+
/* const day = hour * 24;
14+
const month = day * 30;
15+
const year = day * 365;*/
16+
switch (true) {
17+
case diff < minute:
18+
return "just now";
19+
case diff < hour:
20+
const minutes = Math.round(diff / minute);
21+
return `${minutes} minute${minutes > 1 ? "s" : ""} ago`;
22+
/* case diff < day:
23+
const hours = Math.round(diff / hour);
24+
return `${hours} hour${hours > 1 ? "s" : ""} ago`;
25+
case diff < month:
26+
const days = Math.round(diff / day);
27+
return `${days} day${days > 1 ? "s" : ""} ago`;
28+
case diff < year:
29+
const months = Math.round(diff / month);
30+
return `${months} month${months > 1 ? "s" : ""} ago`;
31+
case diff > year:
32+
const years = Math.round(diff / year);
33+
return `${years} year${years > 1 ? "s" : ""} ago`;*/
34+
default:
35+
return "";
36+
}
37+
}
38+
939
function getDateAsStringFromTimestamp(ts: number): string {
40+
const relativeTime = getRelativeTime(ts);
41+
if (relativeTime) {
42+
return relativeTime;
43+
}
44+
1045
let dateFromTs = new Date(ts * 1000);
1146
let year = dateFromTs.getFullYear();
1247
let month = dateFromTs.getMonth() + 1;

src/components/pages/filesytem/FileListHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function FileListHeader(props: TReduxProps): ReactElement {
164164
md={fileListSize.modifiedOn.md}
165165
onClick={() => handleSortClick("lastUpdated")}
166166
>
167-
Modified on
167+
Last Modified
168168
</Col>
169169
{/*Size*/}
170170
<Col

0 commit comments

Comments
 (0)