Enhancement: add duration format to customapi widget (#4549)

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
pull/4571/head
Peder Toftegaard Olsen 3 weeks ago committed by GitHub
parent 3020a2d1fd
commit 6f429a6a4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -62,10 +62,12 @@ widget:
format: size format: size
``` ```
Supported formats for the values are `text`, `number`, `float`, `percent`, `bytes`, `bitrate`, `size`, `date` and `relativeDate`. Supported formats for the values are `text`, `number`, `float`, `percent`, `duration`, `bytes`, `bitrate`, `size`, `date` and `relativeDate`.
The `dateStyle` and `timeStyle` options of the `date` format are passed directly to [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat) and the `style` and `numeric` options of `relativeDate` are passed to [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat). The `dateStyle` and `timeStyle` options of the `date` format are passed directly to [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat) and the `style` and `numeric` options of `relativeDate` are passed to [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat).
The `duration` format expects the duration to be specified in seconds. The `scale` transformation tool can be used if a conversion is required.
The `size` format will return the length of the array or string, or the number of keys in an object. This is then formatted as `number`. The `size` format will return the length of the array or string, or the number of keys in an object. This is then formatted as `number`.
## Example ## Example

@ -78,6 +78,9 @@ function formatValue(t, mapping, rawValue) {
case "percent": case "percent":
value = t("common.percent", { value }); value = t("common.percent", { value });
break; break;
case "duration":
value = t("common.duration", { value });
break;
case "bytes": case "bytes":
value = t("common.bytes", { value }); value = t("common.bytes", { value });
break; break;

Loading…
Cancel
Save