display last online time (#1125)

* - if offline calculate and display last online time to address https://github.com/owncast/owncast/issues/1111
- clean up status bar styles

* clean up console
This commit is contained in:
gingervitis
2021-06-20 10:49:16 -07:00
committed by GitHub
parent d19ecab90c
commit c45e43c378
6 changed files with 58 additions and 44 deletions

View File

@@ -156,3 +156,26 @@ export function debounce(fn, time) {
timeout = setTimeout(functionCall, time);
}
}
export function getDiffInDaysFromNow(timestamp) {
const time = typeof timestamp === 'string' ? new Date(timestamp) : timestamp;
return (new Date() - time) / (24 * 3600 * 1000);
}
// "Last live today at [time]" or "last live [date]"
export function makeLastOnlineString(timestamp) {
if (!timestamp) {
return '';
}
let string = '';
const time = new Date(timestamp);
let diffInDays = getDiffInDaysFromNow(time);
if (diffInDays > 1) {
string = time.toLocaleDateString();
} else {
const atTime = time.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
string = `Today ${atTime}`;
}
return `Last live: ${string}`;
}