<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. 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;

function setupScoreboardLocale() {
  if (isLocaleConfigured) return;

  moment.defineLocale('scoreboard', {
    // tslint complains that M should be before m. And m should be before M.
    // tslint:disable: object-literal-sort-keys
    relativeTime: {
      future: '',
      past: osu.trans('common.scoreboard_time.past'),
      s: osu.trans('common.scoreboard_time.s'),
      m: osu.trans('common.scoreboard_time.m'),
      mm: osu.trans('common.scoreboard_time.mm'),
      h: osu.trans('common.scoreboard_time.h'),
      hh: osu.trans('common.scoreboard_time.hh'),
      d: osu.trans('common.scoreboard_time.d'),
      dd: osu.trans('common.scoreboard_time.dd'),
      M: osu.trans('common.scoreboard_time.M'),
      MM: osu.trans('common.scoreboard_time.MM'),
      y: osu.trans('common.scoreboard_time.y'),
      yy: osu.trans('common.scoreboard_time.yy'),
    },
    // tslint:enable: object-literal-sort-keys
  });

  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><commit_msg>looks like defineLocale also changes the current locale...<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. 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;

function setupScoreboardLocale() {
  if (isLocaleConfigured) return;

  const previousLocale = moment.locale();

  moment.defineLocale('scoreboard', {
    // tslint complains that M should be before m. And m should be before M.
    // tslint:disable: object-literal-sort-keys
    relativeTime: {
      future: '',
      past: osu.trans('common.scoreboard_time.past'),
      s: osu.trans('common.scoreboard_time.s'),
      m: osu.trans('common.scoreboard_time.m'),
      mm: osu.trans('common.scoreboard_time.mm'),
      h: osu.trans('common.scoreboard_time.h'),
      hh: osu.trans('common.scoreboard_time.hh'),
      d: osu.trans('common.scoreboard_time.d'),
      dd: osu.trans('common.scoreboard_time.dd'),
      M: osu.trans('common.scoreboard_time.M'),
      MM: osu.trans('common.scoreboard_time.MM'),
      y: osu.trans('common.scoreboard_time.y'),
      yy: osu.trans('common.scoreboard_time.yy'),
    },
    // tslint:enable: object-literal-sort-keys
  });

  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>
{'fraction_non_alphanumeric': 0.1414141414141414, 'fraction_numerical': 0.0012626262626262627, 'mean_word_length': 3.674041297935103, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '355584', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1018, 'n_words': 228}