This commit is contained in:
parent
e9f55389f4
commit
9add35a428
@ -8,19 +8,19 @@ export function timeAgo(input: Date | number) {
|
|||||||
const date = input instanceof Date ? input : new Date(input);
|
const date = input instanceof Date ? input : new Date(input);
|
||||||
const formatter = new Intl.RelativeTimeFormat("en");
|
const formatter = new Intl.RelativeTimeFormat("en");
|
||||||
const ranges: { [key: string]: number } = {
|
const ranges: { [key: string]: number } = {
|
||||||
years: 3600 * 24 * 365,
|
year: 3600 * 24 * 365,
|
||||||
months: 3600 * 24 * 30,
|
month: 3600 * 24 * 30,
|
||||||
weeks: 3600 * 24 * 7,
|
week: 3600 * 24 * 7,
|
||||||
days: 3600 * 24,
|
day: 3600 * 24,
|
||||||
hours: 3600,
|
hour: 3600,
|
||||||
minutes: 60,
|
minute: 60,
|
||||||
seconds: 1,
|
second: 1,
|
||||||
};
|
};
|
||||||
const secondsElapsed = (date.getTime() - Date.now()) / 1000;
|
const secondsElapsed = (date.getTime() - Date.now()) / 1000;
|
||||||
for (let key in ranges) {
|
for (let key in ranges) {
|
||||||
if (ranges[key] < Math.abs(secondsElapsed)) {
|
if (ranges[key] < Math.abs(secondsElapsed)) {
|
||||||
const delta = secondsElapsed / ranges[key];
|
const delta = secondsElapsed / ranges[key];
|
||||||
return formatter.format(Math.round(delta), key);
|
return formatter.format(Math.round(delta), key as Intl.RelativeTimeFormatUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import ScoreSaberPlayerScore from "@/app/common/leaderboard/types/scoresaber/scoresaber-player-score";
|
import ScoreSaberPlayerScore from "@/app/common/leaderboard/types/scoresaber/scoresaber-player-score";
|
||||||
import { timeAgo } from "@/app/common/time-utils";
|
import { timeAgo } from "@/app/common/time-utils";
|
||||||
import { GlobeAmericasIcon } from "@heroicons/react/24/solid";
|
import { GlobeAmericasIcon } from "@heroicons/react/24/solid";
|
||||||
|
import Image from "next/image";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
/**
|
/**
|
||||||
@ -22,7 +23,14 @@ export default function Score({ playerScore }: Props) {
|
|||||||
<p className="text-sm">{timeAgo(new Date(score.timeSet))}</p>
|
<p className="text-sm">{timeAgo(new Date(score.timeSet))}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-3">
|
<div className="flex gap-3">
|
||||||
<img src={leaderboard.coverImage} className="w-16 h-16 rounded-md" />
|
<Image
|
||||||
|
unoptimized
|
||||||
|
src={leaderboard.coverImage}
|
||||||
|
width={64}
|
||||||
|
height={64}
|
||||||
|
alt="Song Artwork"
|
||||||
|
className="rounded-md"
|
||||||
|
/>
|
||||||
<div className="flex">
|
<div className="flex">
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<p>{leaderboard.songName}</p>
|
<p>{leaderboard.songName}</p>
|
||||||
|
Reference in New Issue
Block a user