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:
Kerry 2022-03-21 12:42:58 +01:00 committed by GitHub
parent 8418b4fd71
commit 14653d1378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 366 additions and 37 deletions

View file

@ -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) });
}