2023-01-03 11:55:46 -08:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2020-10-30 15:34:04 -05:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-01-14 13:49:58 -08:00
|
|
|
import { padStart } from 'lodash';
|
|
|
|
|
|
|
|
export function getIncrement(length: number): number {
|
|
|
|
if (length < 0) {
|
|
|
|
return 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Math.ceil(length / 12);
|
|
|
|
}
|
|
|
|
|
2022-04-07 09:58:15 -07:00
|
|
|
export function getTimerBucket(
|
|
|
|
expiration: number | undefined,
|
|
|
|
length: number
|
|
|
|
): string {
|
|
|
|
if (!expiration) {
|
|
|
|
return '60';
|
|
|
|
}
|
|
|
|
|
2019-01-14 13:49:58 -08:00
|
|
|
const delta = expiration - Date.now();
|
|
|
|
if (delta < 0) {
|
|
|
|
return '00';
|
|
|
|
}
|
|
|
|
if (delta > length) {
|
|
|
|
return '60';
|
|
|
|
}
|
|
|
|
|
2020-01-08 12:44:54 -05:00
|
|
|
const bucket = Math.round((delta / length) * 12);
|
2019-01-14 13:49:58 -08:00
|
|
|
|
|
|
|
return padStart(String(bucket * 5), 2, '0');
|
|
|
|
}
|