Skip to content

Commit

Permalink
added number formatting and pluralization for uom times and seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Oct 12, 2021
1 parent 25616ae commit 22a2b92
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions interface/src/project/EMSESPDataForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ type EMSESPDataFormProps = RestFormProps<EMSESPData> &
AuthenticatedContextProps &
WithWidthProps;

const pluralize = (count: number, noun: string, suffix = 's') =>
` ${Intl.NumberFormat().format(count)} ${noun}${count !== 1 ? suffix : ''} `;

export const formatDuration = (duration_min: number) => {
const { days, hours, minutes } = parseMilliseconds(duration_min * 60000);
let formatted = '';
Expand All @@ -119,9 +122,6 @@ export const formatDuration = (duration_min: number) => {
return formatted;
};

const pluralize = (count: number, noun: string, suffix = 's') =>
` ${count} ${noun}${count !== 1 ? suffix : ''} `;

function formatValue(value: any, uom: number, digit: number) {
switch (uom) {
case DeviceValueUOM.HOURS:
Expand All @@ -141,6 +141,9 @@ function formatValue(value: any, uom: number, digit: number) {
' ' +
DeviceValueUOM_s[uom]
);
case DeviceValueUOM.TIMES:
case DeviceValueUOM.SECONDS:
return pluralize(value, DeviceValueUOM_s[uom]);
default:
return (
new Intl.NumberFormat().format(value) + ' ' + DeviceValueUOM_s[uom]
Expand Down

0 comments on commit 22a2b92

Please sign in to comment.