From 5f2726a6111424786889a8c84530fc9c0f09f411 Mon Sep 17 00:00:00 2001 From: Jan Hajek Date: Mon, 29 Jun 2026 13:16:07 +0200 Subject: [PATCH] Use formatDuration from client-libraries. --- package-lock.json | 8 ++++---- package.json | 2 +- src/components/Duration/Duration.tsx | 20 ++------------------ 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index d587b384..c06ede64 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "@dnd-kit/sortable": "^10.0.0", "@dnd-kit/utilities": "^3.2.2", "@fluentui/react-migration-v8-v9": "^9.6.20", - "@talxis/client-libraries": "1.2606.1", + "@talxis/client-libraries": "^1.2606.2", "@talxis/client-metadata": "^0.0.4", "color": "^4.2.3", "dayjs": "^1.11.10", @@ -2704,9 +2704,9 @@ } }, "node_modules/@talxis/client-libraries": { - "version": "1.2606.1", - "resolved": "https://registry.npmjs.org/@talxis/client-libraries/-/client-libraries-1.2606.1.tgz", - "integrity": "sha512-VdSfczZqWAVSOHhTb2ZYAEV07XwGPq1AzwvR2NxmZ6Aq7+h+lHHLxyvLKY0wWlDZECJf+TbXNsQHRURFhT0HTQ==", + "version": "1.2606.2", + "resolved": "https://registry.npmjs.org/@talxis/client-libraries/-/client-libraries-1.2606.2.tgz", + "integrity": "sha512-xCOowIrjhA+vZkPm2dPWHGUAgqMYvmsXNg2p9t3lKaBBsFMDXb0mkeLfUvqdQW/ZyrtvqX8NVPZzQ6wC/0/KOA==", "license": "MIT", "dependencies": { "@azure/msal-browser": "^2.27.0", diff --git a/package.json b/package.json index b35c44d3..48a95f51 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "@dnd-kit/sortable": "^10.0.0", "@dnd-kit/utilities": "^3.2.2", "@fluentui/react-migration-v8-v9": "^9.6.20", - "@talxis/client-libraries": "1.2606.1", + "@talxis/client-libraries": "^1.2606.2", "@talxis/client-metadata": "^0.0.4", "color": "^4.2.3", "dayjs": "^1.11.10", diff --git a/src/components/Duration/Duration.tsx b/src/components/Duration/Duration.tsx index 873cf398..ed1e1c08 100644 --- a/src/components/Duration/Duration.tsx +++ b/src/components/Duration/Duration.tsx @@ -7,7 +7,7 @@ import numeral from "numeral"; import { getDefaultDurationTranslations } from './translations'; import { durationOptions } from "./durationOptions"; import humanizeDuration, { HumanizerOptions, Unit } from "humanize-duration"; -import { Numeral } from "@talxis/client-libraries"; +import { Formatting, Numeral } from "@talxis/client-libraries"; export const Duration = (props: IDuration) => { const parameters = props.parameters; @@ -15,29 +15,13 @@ export const Duration = (props: IDuration) => { const componentRef = useRef(null); const context = props.context; const formattingInfo = context.userSettings; - //@ts-ignore - locale is part of UserSettings - const language = formattingInfo.locale; const numberFormatting = context.userSettings.numberFormattingInfo; const onOverrideComponentProps = props.onOverrideComponentProps ?? ((props) => props); const hoursPerDay = typeof parameters.HoursPerDay?.raw === 'number' && parameters.HoursPerDay.raw > 0 ? parameters.HoursPerDay.raw : 24; - const minutesPerDay = hoursPerDay * 60; const formatter = (value: number | null) => { - //all duration formatting should happen here if (typeof value === 'number') { - const durationInMilliseconds = value * 60000; - const units: Unit[] = value < 60 ? ['m'] : value >= minutesPerDay ? ['d'] : ['h']; - const options: HumanizerOptions = { - units: units, - maxDecimalPoints: 2, - language: language.slice(0, language.indexOf("-")), - decimal: context.userSettings.numberFormattingInfo.numberDecimalSeparator, - fallbacks: ["en"], - unitMeasures: { - d: minutesPerDay * 60000, - } - }; - return humanizeDuration(durationInMilliseconds, options); + return Formatting.Get().formatDuration(value, hoursPerDay); } return value; };