feat(shared): add signed percent and percentage-point formatters (WealthLedger/main#54)

This commit is contained in:
2026-11-08 14:20:49 +03:00
parent d910d624d6
commit 010e3ab8af
3 changed files with 39 additions and 0 deletions
+10
View File
@@ -3,12 +3,22 @@ import { describe, expect, it } from "vitest";
import {
formatDate,
formatMoney,
formatPercentagePoints,
formatSignedPercent,
formatSnapshotDay,
formatSnapshotTime,
instrumentLogoUrl,
} from "./display";
describe("shared display helpers", () => {
it("formats signed rates as percentages and percentage points without negative zero", () => {
expect(formatSignedPercent("0.151")).toBe("+15,1 %");
expect(formatSignedPercent("-0.15149")).toBe("−15,1 %");
expect(formatSignedPercent("0")).toBe("0,0 %");
expect(formatSignedPercent("-0.00049")).toBe("0,0 %");
expect(formatPercentagePoints("0.043")).toBe("+4,3 п.п.");
expect(formatPercentagePoints("-0.0435")).toBe("−4,4 п.п.");
});
it("uses padded Russian dates and preserves the UTC date of timestamps", () => {
expect(formatDate("2027-09-10")).toBe("10.09.2027");
expect(formatDate("2024-02-29")).toBe("29.02.2024");