Jelajahi Sumber

RHL-022 feat(formatters): add German month formatting functions and corresponding tests

Code_Uwe 4 minggu lalu
induk
melakukan
95f79f3e9b

+ 33 - 0
lib/frontend/explorer/formatters.js

@@ -0,0 +1,33 @@
+/**
+ * formatters (German UI)
+ *
+ * These helpers are used purely for user-facing labels.
+ * They remain pure, testable, and independent from React/Next.
+ */
+
+const MONTHS_DE = Object.freeze([
+	"Januar",
+	"Februar",
+	"März",
+	"April",
+	"Mai",
+	"Juni",
+	"Juli",
+	"August",
+	"September",
+	"Oktober",
+	"November",
+	"Dezember",
+]);
+
+export function getGermanMonthName(month) {
+	const m = Number.parseInt(String(month), 10);
+	if (!Number.isInteger(m) || m < 1 || m > 12) return null;
+	return MONTHS_DE[m - 1];
+}
+
+export function formatMonthLabel(month) {
+	const name = getGermanMonthName(month);
+	const mm = String(month).padStart(2, "0");
+	return name ? `${name} (${mm})` : mm;
+}

+ 18 - 0
lib/frontend/explorer/formatters.test.js

@@ -0,0 +1,18 @@
+/* @vitest-environment node */
+
+import { describe, it, expect } from "vitest";
+import { getGermanMonthName, formatMonthLabel } from "./formatters";
+
+describe("lib/frontend/explorer/formatters", () => {
+	it("returns German month names", () => {
+		expect(getGermanMonthName("01")).toBe("Januar");
+		expect(getGermanMonthName("12")).toBe("Dezember");
+		expect(getGermanMonthName("99")).toBe(null);
+	});
+
+	it("formats month label as 'Name (MM)'", () => {
+		expect(formatMonthLabel("01")).toBe("Januar (01)");
+		expect(formatMonthLabel("10")).toBe("Oktober (10)");
+		expect(formatMonthLabel("99")).toBe("99");
+	});
+});