Live location share - set time limit (#8082)
* add mocking helpers for platform peg Signed-off-by: Kerry Archibald <kerrya@element.io> * basic working live duration dropdown Signed-off-by: Kerry Archibald <kerrya@element.io> * add duration format utility Signed-off-by: Kerry Archibald <kerrya@element.io> * add duration dropdown to live location picker Signed-off-by: Kerry Archibald <kerrya@element.io> * adjust style to allow overflow and variable height chin Signed-off-by: Kerry Archibald <kerrya@element.io> * tidy comments Signed-off-by: Kerry Archibald <kerrya@element.io> * arrow fn change Signed-off-by: Kerry Archibald <kerrya@element.io> * lint Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
parent
8418b4fd71
commit
14653d1378
13 changed files with 366 additions and 37 deletions
|
@ -201,3 +201,25 @@ export function formatRelativeTime(date: Date, showTwelveHour = false): string {
|
|||
return relativeDate;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats duration in ms to human readable string
|
||||
* Returns value in biggest possible unit (day, hour, min, second)
|
||||
* Rounds values up until unit threshold
|
||||
* ie. 23:13:57 -> 23h, 24:13:57 -> 1d, 44:56:56 -> 2d
|
||||
*/
|
||||
const MINUTE_MS = 60000;
|
||||
const HOUR_MS = MINUTE_MS * 60;
|
||||
const DAY_MS = HOUR_MS * 24;
|
||||
export function formatDuration(durationMs: number): string {
|
||||
if (durationMs >= DAY_MS) {
|
||||
return _t('%(value)sd', { value: Math.round(durationMs / DAY_MS) });
|
||||
}
|
||||
if (durationMs >= HOUR_MS) {
|
||||
return _t('%(value)sh', { value: Math.round(durationMs / HOUR_MS) });
|
||||
}
|
||||
if (durationMs >= MINUTE_MS) {
|
||||
return _t('%(value)sm', { value: Math.round(durationMs / MINUTE_MS) });
|
||||
}
|
||||
return _t('%(value)ss', { value: Math.round(durationMs / 1000) });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue