Skip to content

Commit 9647761

Browse files
committed
use duration.formatToParts
1 parent 00fb7c1 commit 9647761

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

components/SponsoredFeedsTableWithData.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,10 @@ const formatTimeUnit = (seconds: number): { value: number; unit: string } => {
4242
durationObj = { seconds };
4343
}
4444

45-
const formatted = duration.format(durationObj);
46-
const match = formatted.match(/^([0-9]+)\s*(.*)$/);
47-
if (match) {
48-
return {
49-
value: parseInt(match[1], 10),
50-
unit: match[2].replace(/[0-9]/g, ""), // Remove any numbers from the unit
51-
};
45+
const parts = duration.formatToParts(durationObj);
46+
const intPart = parts.find((p: any) => p.type === "integer");
47+
if (intPart) {
48+
return { value: Number(intPart.value), unit: intPart.unit };
5249
} else {
5350
// fallback in case formatting fails
5451
return { value: seconds, unit: "second" };

0 commit comments

Comments
 (0)