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:
@@ -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}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user