Skip to content

Commit ec1be66

Browse files
Add date formatting + remove the load value
1 parent 6a1e896 commit ec1be66

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

frontend/js/src/about/current-status/CurrentStatus.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { useQuery } from "@tanstack/react-query";
22
import React from "react";
33
import { useLocation } from "react-router";
44
import { RouteQuery } from "../../utils/Loader";
5+
import {
6+
fullLocalizedDateFromTimestampOrISODate,
7+
formatSecondsDuration,
8+
} from "../../utils/utils";
9+
510
import UserEvolutionChart, { UserEvolutionData } from "./UserEvolutionChart";
611

712
type CurrentStatusLoaderData = {
@@ -107,31 +112,42 @@ export default function CurrentStatus() {
107112
{serviceStatus && (
108113
<tr>
109114
<td>Last Updated</td>
110-
<td>{new Date(serviceStatus.time * 1000).toISOString()}</td>
115+
<td>
116+
{fullLocalizedDateFromTimestampOrISODate(
117+
new Date(serviceStatus.time * 1000)
118+
)}
119+
</td>
111120
</tr>
112121
)}
113122
{serviceStatus && (
114123
<tr>
115124
<td>Database Dump Age</td>
116-
<td>{serviceStatus.dump_age} seconds</td>
125+
<td>{formatSecondsDuration(serviceStatus.dump_age)}</td>
117126
</tr>
118127
)}
119128
{serviceStatus && (
120129
<tr>
121130
<td>Stats Age</td>
122-
<td>{serviceStatus.stats_age} seconds</td>
131+
<td>{formatSecondsDuration(serviceStatus.stats_age)}</td>
123132
</tr>
124133
)}
125134
{serviceStatus && (
126135
<tr>
127136
<td>Sitewide Stats Age</td>
128-
<td>{serviceStatus.sitewide_stats_age} seconds</td>
137+
<td>
138+
{formatSecondsDuration(serviceStatus.sitewide_stats_age)}
139+
</td>
129140
</tr>
130141
)}
131142
{serviceStatus && (
132143
<tr>
133144
<td>Incoming Listen Count</td>
134-
<td>{serviceStatus.incoming_listen_count} listens</td>
145+
<td>
146+
{new Intl.NumberFormat().format(
147+
serviceStatus.incoming_listen_count
148+
)}{" "}
149+
listens
150+
</td>
135151
</tr>
136152
)}
137153
</tbody>

frontend/js/src/utils/utils.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Rating } from "react-simple-star-rating";
66
import { toast } from "react-toastify";
77
import { Link } from "react-router";
88
import ReactMarkdown from "react-markdown";
9+
import { formatDuration, intervalToDuration } from "date-fns";
910
import SpotifyPlayer from "../common/brainzplayer/SpotifyPlayer";
1011
import YoutubePlayer from "../common/brainzplayer/YoutubePlayer";
1112
import NamePill from "../personal-recommendations/NamePill";
@@ -729,6 +730,11 @@ const preciseTimestamp = (
729730
return `${timeago.ago(listened_at)}`;
730731
}
731732
};
733+
const formatSecondsDuration = (seconds: number): string => {
734+
return formatDuration(intervalToDuration({ start: 0, end: seconds * 1000 }), {
735+
format: ["months", "days", "hours", "minutes"],
736+
});
737+
};
732738
// recieves or unix epoch timestamp int or ISO datetime string
733739
const fullLocalizedDateFromTimestampOrISODate = (
734740
unix_epoch_timestamp: number | string | Date | undefined | null
@@ -1454,6 +1460,7 @@ export {
14541460
getAlbumLink,
14551461
formatWSMessageToListen,
14561462
preciseTimestamp,
1463+
formatSecondsDuration,
14571464
fullLocalizedDateFromTimestampOrISODate,
14581465
convertDateToUnixTimestamp,
14591466
getPageProps,

listenbrainz/webserver/views/index.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ def index():
9393
@index_bp.post("/current-status/")
9494
@web_listenstore_needed
9595
def current_status():
96-
load = "%.2f %.2f %.2f" % os.getloadavg()
97-
9896
service_status = get_service_status()
9997
listen_count = _ts.get_total_listen_count()
10098
try:
@@ -128,7 +126,6 @@ def current_status():
128126
})
129127

130128
data = {
131-
"load": load,
132129
"serviceStatus": service_status,
133130
"listenCount": format(int(listen_count), ",d") if listen_count else "0",
134131
"userCount": user_count,

0 commit comments

Comments
 (0)