mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 08:49:52 +03:00
added number formatting and pluralization for uom times and seconds
This commit is contained in:
@@ -104,6 +104,9 @@ type EMSESPDataFormProps = RestFormProps<EMSESPData> &
|
|||||||
AuthenticatedContextProps &
|
AuthenticatedContextProps &
|
||||||
WithWidthProps;
|
WithWidthProps;
|
||||||
|
|
||||||
|
const pluralize = (count: number, noun: string, suffix = 's') =>
|
||||||
|
` ${Intl.NumberFormat().format(count)} ${noun}${count !== 1 ? suffix : ''} `;
|
||||||
|
|
||||||
export const formatDuration = (duration_min: number) => {
|
export const formatDuration = (duration_min: number) => {
|
||||||
const { days, hours, minutes } = parseMilliseconds(duration_min * 60000);
|
const { days, hours, minutes } = parseMilliseconds(duration_min * 60000);
|
||||||
let formatted = '';
|
let formatted = '';
|
||||||
@@ -119,9 +122,6 @@ export const formatDuration = (duration_min: number) => {
|
|||||||
return formatted;
|
return formatted;
|
||||||
};
|
};
|
||||||
|
|
||||||
const pluralize = (count: number, noun: string, suffix = 's') =>
|
|
||||||
` ${count} ${noun}${count !== 1 ? suffix : ''} `;
|
|
||||||
|
|
||||||
function formatValue(value: any, uom: number, digit: number) {
|
function formatValue(value: any, uom: number, digit: number) {
|
||||||
switch (uom) {
|
switch (uom) {
|
||||||
case DeviceValueUOM.HOURS:
|
case DeviceValueUOM.HOURS:
|
||||||
@@ -141,6 +141,9 @@ function formatValue(value: any, uom: number, digit: number) {
|
|||||||
' ' +
|
' ' +
|
||||||
DeviceValueUOM_s[uom]
|
DeviceValueUOM_s[uom]
|
||||||
);
|
);
|
||||||
|
case DeviceValueUOM.TIMES:
|
||||||
|
case DeviceValueUOM.SECONDS:
|
||||||
|
return pluralize(value, DeviceValueUOM_s[uom]);
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
new Intl.NumberFormat().format(value) + ' ' + DeviceValueUOM_s[uom]
|
new Intl.NumberFormat().format(value) + ' ' + DeviceValueUOM_s[uom]
|
||||||
|
|||||||
Reference in New Issue
Block a user