signal-desktop/ts/util/getMutedUntilText.ts

30 lines
748 B
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2021 Signal Messenger, LLC
2021-08-05 12:35:33 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
import moment from 'moment';
import type { LocalizerType } from '../types/Util';
import { isToday } from './timestamp';
2021-08-05 12:35:33 +00:00
/**
* Returns something like "Muted until 6:09 PM", localized.
*
* Shouldn't be called with `0`.
*/
export function getMutedUntilText(
muteExpiresAt: number,
i18n: LocalizerType
): string {
if (Number(muteExpiresAt) >= Number.MAX_SAFE_INTEGER) {
2023-03-30 00:03:25 +00:00
return i18n('icu:muteExpirationLabelAlways');
2021-08-05 12:35:33 +00:00
}
const expires = moment(muteExpiresAt);
const muteExpirationUntil = isToday(expires)
2021-08-05 12:35:33 +00:00
? expires.format('LT')
: expires.format('L, LT');
2023-03-30 00:03:25 +00:00
return i18n('icu:muteExpirationLabel', {
2023-03-27 23:37:39 +00:00
duration: muteExpirationUntil,
});
2021-08-05 12:35:33 +00:00
}