-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutil.js
More file actions
34 lines (31 loc) · 967 Bytes
/
util.js
File metadata and controls
34 lines (31 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function utcToDate(utcString) {
const date = new Date(utcString);
return date.toLocaleDateString();
}
function timePassedFromDate(date) {
const now = new Date().getTime(); // account for SGT
const difference = now - date.getTime();
const minutes = Math.round(difference / 60000);
const hours = Math.round(difference / 3600000);
const days = Math.round(difference / 86400000);
console.log('days', days, 'hours', hours, 'minutes', minutes)
if (days === 0 && hours === 0) {
if (minutes > 1) {
return `${minutes} minutes ago`;
}
return "1 minute ago";
}
if (days === 0) {
if (hours > 1) {
return `${hours} hours ago`;
}
return "1 hour ago";
}
if (days > 1) {
return `${days} days ago`;
}
return "1 day ago";
}
const capitalize = (text) =>
text.charAt(0).toUpperCase() + text.slice(1);
module.exports = { timePassedFromDate }