-
Notifications
You must be signed in to change notification settings - Fork 389
/
scoreboard-time.tsx
53 lines (41 loc) · 1.15 KB
/
scoreboard-time.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.
import * as moment from 'moment';
import * as React from 'react';
interface Props {
dateTime: string;
}
let isLocaleConfigured = false;
const translatedUnits = {
d: 'd',
dd: 'dd',
h: 'h',
hh: 'hh',
m: 'm',
mm: 'mm',
month: 'M',
months: 'MM',
past: 'past',
s: 's',
y: 'y',
yy: 'yy',
};
function setupScoreboardLocale() {
if (isLocaleConfigured) return;
const previousLocale = moment.locale();
const relativeTime: Partial<Record<string, string>> = { future: '' };
for (const [key, unit] of Object.entries(translatedUnits)) {
relativeTime[unit] = osu.trans(`common.scoreboard_time.${key}`);
}
moment.defineLocale('scoreboard', { relativeTime });
moment.locale(previousLocale);
isLocaleConfigured = true;
}
export default function ScoreboardTime(props: Props) {
setupScoreboardLocale();
return (
<time className='js-tooltip-time' title={props.dateTime}>
{moment(props.dateTime).locale('scoreboard').fromNow()}
</time>
);
}