Add uptime to home screen (#425)

This commit is contained in:
mutatrum 2024-12-02 23:45:50 +01:00 committed by GitHub
parent fe4ac7e305
commit 468718abda
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View File

@ -218,6 +218,12 @@
</div>
</div>
<div class="col-12 lg:col-6">
<div class="card" *ngIf="info$ | async as info; else loading">
<h5>Uptime</h5>
{{info.uptimeSeconds | dateAgo}}
</div>
</div>
</div>

View File

@ -9,7 +9,7 @@ export class DateAgoPipe implements PipeTransform {
transform(value: any, args?: any): any {
if (value) {
value = new Date().getTime() - value * 1000;
const seconds = Math.floor((+new Date() - +new Date(value)) / 1000);
let seconds = Math.floor((+new Date() - +new Date(value)) / 1000);
if (seconds < 29) // less than 30 seconds ago will show as 'Just now'
return 'Just now';
const intervals: { [key: string]: number } = {
@ -21,16 +21,21 @@ export class DateAgoPipe implements PipeTransform {
'minute': 60,
'second': 1
};
let counter;
let result = '';
for (const i in intervals) {
counter = Math.floor(seconds / intervals[i]);
const counter = Math.floor(seconds / intervals[i]);
if (counter > 0)
if (counter === 1) {
return counter + ' ' + i + ''; // singular (1 day ago)
if (result) result += ', '
result += counter + ' ' + i + ''; // singular (1 day ago)
seconds -= intervals[i]
} else {
return counter + ' ' + i + 's'; // plural (2 days ago)
if (result) result += ', '
result += counter + ' ' + i + 's'; // plural (2 days ago)
seconds -= intervals[i] * counter
}
}
return result;
}
return value;
}