signal-desktop/ts/util/timer.ts

24 lines
475 B
TypeScript
Raw Normal View History

2019-01-14 21:49:58 +00:00
import { padStart } from 'lodash';
export function getIncrement(length: number): number {
if (length < 0) {
return 1000;
}
return Math.ceil(length / 12);
}
export function getTimerBucket(expiration: number, length: number): string {
const delta = expiration - Date.now();
if (delta < 0) {
return '00';
}
if (delta > length) {
return '60';
}
2020-01-08 17:44:54 +00:00
const bucket = Math.round((delta / length) * 12);
2019-01-14 21:49:58 +00:00
return padStart(String(bucket * 5), 2, '0');
}