| import memoize from "lodash.memoize"; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export function timeDiffDescription( |
| timestamp1: number, |
| timestamp2: number |
| ): string { |
| const diffSecs = (timestamp2 - timestamp1) / 1000; |
| const roundedSecs = Math.round(diffSecs * 10) / 10; |
| const secs = roundedSecs == 1 ? "sec" : "secs"; |
| return ` (${roundedSecs.toFixed(1)} ${secs})`; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| export const formatTimestamp = memoize(function (timestamp: number): string { |
| if (timestamp === 0) { |
| return ""; |
| } |
| |
| const date = new Date(timestamp); |
| |
| const monthString = date.toLocaleString("default", { month: "short" }); |
| const day = date.getDate(); |
| const hour = date.getHours(); |
| |
| const minute = date.getMinutes().toString().padStart(2, "0"); |
| return `${monthString} ${day}, ${hour}:${minute}`; |
| }); |
| |
| |
| |
| |
| |
| |
| export function secsToTime(secs: number): string { |
| const days = Math.floor(secs / 86400); |
| const hours = Math.floor(secs / 3600); |
| const minutes = Math.floor(secs / 60); |
| const seconds = secs % 60; |
|
|
| let timeStr = ""; |
| if (days == 1) { |
| timeStr += "1 day, "; |
| } else if (days > 1) { |
| timeStr += `${days} days, `; |
| } |
|
|
| if (hours == 1) { |
| timeStr += "1 hr, "; |
| } else if (hours > 1) { |
| timeStr += `${hours} hrs, `; |
| } |
|
|
| if (minutes == 1) { |
| timeStr += "1 min, "; |
| } else if (minutes > 1) { |
| timeStr += `${minutes} mins, `; |
| } |
|
|
| if (seconds == 1) { |
| timeStr += "1 sec"; |
| } else { |
| timeStr += `${seconds.toFixed(1)} secs`; |
| } |
|
|
| return timeStr; |
| } |
|
|