Merge pull request 'fix(web-ui): תצוגת זמנים אנושית דטרמיניסטית ב-Asia/Jerusalem (אחסון נשאר UTC) — INV-UI9 (#210)' (#367) from worktree-agent-a441570a4556d14e5 into main
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 46s
G12 Leak-Guard / leak-guard (push) Successful in 4s
Lint — undefined names / undefined-names (push) Successful in 11s

This commit was merged in pull request #367.
This commit is contained in:
2026-06-30 17:20:35 +00:00
32 changed files with 384 additions and 235 deletions

View File

@@ -105,13 +105,36 @@ TanStack Query — *Important Defaults* (staleTime/refetch) (https://tanstack.co
**אכיפה:** `halacha_backlog` מרונדר ב-/operations (לא נזרק); `findings_approved` (review_status, צרכן אמיתי)
החליף את `findings_applied` (דגל מת); מוני-סוכנים מסמנים "חלקי" כשחברה לא-נטענה (גל-1 #130).
### INV-UI9: זמן-מאוחסן ב-UTC · תצוגה אנושית דטרמיניסטית ב-Asia/Jerusalem
**כלל:** **האחסון נשאר UTC** מקצה-לקצה — Postgres `TIMESTAMPTZ`, וה-API מחזיר ISO-UTC; אין נרמול-tz
בשכבת-האחסון/ה-API. **שכבת-התצוגה בלבד** ממירה, ובאופן **דטרמיניסטי**: כל חותמת-זמן אנושית מרונדרת
ב-`timeZone: "Asia/Jerusalem"` (locale `he-IL`), בלי תלות ב-tz של ה-host/קונטיינר/דפדפן. כיוון
שהקונטיינר רץ ב-UTC, פירמוט ad-hoc (`new Date(iso).toLocaleDateString("he-IL")`, `.getHours()`,
`toISOString().slice(0,10)`) מציג UTC תחת SSR (ושוב UTC בכל runtime לא-ישראלי) → drift. נעיצת
`Asia/Jerusalem` מבטיחה ש-SSR והדפדפן מסכימים. **פורמט-התצוגה (צורת התאריך/שעה) נשמר זהה — רק ה-tz
מנורמל.** מופע של [G2](00-constitution.md#inv-g2-מקור-אמת-יחיד--אין-מסלולים-מקבילים-מתפצלים)
(מפרמט-תאריך **יחיד**, אין פירמוט-זמן מקביל-מפוזר) בשכבת-התצוגה.
**מקורות:** ECMAScript Internationalization API — `Intl.DateTimeFormat` `timeZone` option
(https://tc39.es/ecma402/#datetimeformat-objects) · MDN — *Intl.DateTimeFormat* (IANA time zones)
(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) ·
Next.js — *Rendering* (SSR משתמש בשעון-השרת אם לא ננעץ)
(https://nextjs.org/docs/app/building-your-application/rendering) | סטטוס: verified
**אכיפה:** מפרמט-תאריך יחיד ב-[web-ui/src/lib/format-date.ts](../../web-ui/src/lib/format-date.ts)
(`formatDate`/`formatDateShort`/`formatDateLong`/`formatDateTime`/`formatDateTimeFull`/`formatTime`/
`formatIsoDate`/`formatRelative` + עוזרי-Israel `getIsraelYear`/`israelDayKey`/`israelMidnightMs`/
`israelParts`), כולם נעוצים ל-`Asia/Jerusalem`; כל משטחי-ה-UI מייבאים ממנו ולא מפרמטים tz ad-hoc.
פירמוט-**מספרים** (`n.toLocaleString`) מחוץ-לתחום (אינו חותמת-זמן). **חריג מוצהר:** קלט
`<input type="datetime-local">` (בקרת-burst ב-`/operations`) הוא ערך הניתן-לכתיבה ע"י המפעיל, לא תצוגת-
מאוחסן — נשאר בנייה מקומית. **אודיט-נלווה (לא מיושם):** הגדרת `TZ=Asia/Jerusalem` בקונטיינר בטוחה רק
אם אף לוגיקה עסקית אינה תלויה בשעון-ה-process כ-UTC.
---
## 3. כללי-עיצוב (Design Rules) — נגזרים מה-invariants
- **SSoT ל-enums/תוויות/tones:** כל enum (CaseStatus, PracticeArea, AppealSubtype, DocType, outcome) +
תוויותיו + צבעיו מוגדרים **פעם אחת** ונצרכים מיבוא — לא משוכפלים בין דפים/רכיבים (מופע UI1/G2).
- **helpers משותפים:** פירמוט-תאריך, builder ל-FormData (העלאות), רכיב-שגיאה, query-config (intervals) —
משותפים, לא מועתקים.
- **helpers משותפים:** פירמוט-תאריך (מפרמט-יחיד נעוץ-Asia/Jerusalem ב-[format-date.ts](../../web-ui/src/lib/format-date.ts),
INV-UI9), builder ל-FormData (העלאות), רכיב-שגיאה, query-config (intervals) — משותפים, לא מועתקים.
- **חוזי-טופס:** ראה INV-UI6 ([X8](X8-field-provenance.md)).
הממצאים הקונקרטיים (כפילויות, הגדרות-שגויות, redundancy) ב-[ui-audit.md](ui-audit.md); התיקון — **FU-10**.

View File

@@ -9,6 +9,7 @@ import {
type ApprovalCategory,
type ApprovalSeverity,
} from "@/lib/api/chair";
import { formatDateLong } from "@/lib/format-date";
/**
* מרכז אישורים — דפנה (INV-G10).
@@ -35,18 +36,7 @@ const SEVERITY_RAIL: Record<ApprovalSeverity, string> = {
ok: "border-s-success",
};
function formatDate(iso?: string | null): string {
if (!iso) return "";
try {
return new Date(iso).toLocaleDateString("he-IL", {
day: "numeric",
month: "long",
year: "numeric",
});
} catch {
return "";
}
}
const formatDate = (iso?: string | null) => formatDateLong(iso);
function ApprovalCard({ cat }: { cat: ApprovalCategory }) {
const cleared = cat.count === 0;

View File

@@ -28,19 +28,7 @@ import {
import { useCases, useRestoreCase, type Case } from "@/lib/api/cases";
import { subtypeOf } from "@/components/cases/appeal-type-bars";
import { APPEAL_SUBTYPE_LABELS, type AppealSubtype } from "@/lib/practice-area";
function formatDate(iso?: string | null) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL", {
day: "2-digit",
month: "2-digit",
year: "numeric",
});
} catch {
return iso;
}
}
import { formatDate, getIsraelYear } from "@/lib/format-date";
// type chip styling per mockup 05 (.t-lic / .t-bet / .t-comp)
const TYPE_CHIP: Record<string, string> = {
@@ -177,8 +165,8 @@ export default function ArchivePage() {
const set = new Set<string>();
for (const c of rows) {
if (!c.archived_at) continue;
const y = new Date(c.archived_at).getFullYear();
if (!Number.isNaN(y)) set.add(String(y));
const y = getIsraelYear(c.archived_at);
if (y !== null) set.add(String(y));
}
return [...set].sort((a, b) => Number(b) - Number(a));
}, [rows]);
@@ -209,7 +197,7 @@ export default function ArchivePage() {
if (yearFilter !== "all") {
all = all.filter((r) => {
const iso = r.original.archived_at;
return iso != null && String(new Date(iso).getFullYear()) === yearFilter;
return iso != null && String(getIsraelYear(iso)) === yearFilter;
});
}
return all;

View File

@@ -16,6 +16,7 @@ import {
type ChairFeedback,
type FeedbackCategory,
} from "@/lib/api/feedback";
import { formatDateLong } from "@/lib/format-date";
/**
* מרכז הערות יו"ר — הדף המרכזי לטיפול בכל הערות דפנה שנרשמו על טיוטות
@@ -33,18 +34,7 @@ const CAT_CHIP: Record<FeedbackCategory, string> = {
other: "bg-rule-soft text-ink-soft",
};
function formatDate(iso?: string | null): string {
if (!iso) return "";
try {
return new Date(iso).toLocaleDateString("he-IL", {
day: "numeric",
month: "long",
year: "numeric",
});
} catch {
return "";
}
}
const formatDate = (iso?: string | null) => formatDateLong(iso);
function FeedbackCard({ fb }: { fb: ChairFeedback }) {
const resolve = useResolveFeedback();

View File

@@ -36,6 +36,7 @@ import {
type SubscriptionUsage,
type UsageWindow,
} from "@/lib/api/operations";
import { formatTime, israelParts } from "@/lib/format-date";
function mb(bytes: number): string {
return `${Math.round((bytes || 0) / 1024 / 1024)}MB`;
@@ -46,8 +47,7 @@ function mb(bytes: number): string {
// and resumes on its own when a window resets.
function usageResetLabel(iso: string | null): string {
if (!iso) return "—";
const d = new Date(iso);
return `איפוס ${d.toLocaleTimeString("he-IL", { hour: "2-digit", minute: "2-digit" })}`;
return `איפוס ${formatTime(iso)}`;
}
function UsageMeter({ label, w }: { label: string; w?: UsageWindow | null }) {
@@ -195,8 +195,9 @@ function nextSaturday18(): Date {
}
const HE_DAYS = ["א׳", "ב׳", "ג׳", "ד׳", "ה׳", "ו׳", "ש׳"];
function fmtDeadline(iso: string): string {
const d = new Date(iso);
return `${HE_DAYS[d.getDay()]} ${pad2(d.getDate())}/${pad2(d.getMonth() + 1)} ${pad2(d.getHours())}:${pad2(d.getMinutes())}`;
const p = israelParts(iso);
if (!p) return "—";
return `${HE_DAYS[p.weekday]} ${pad2(p.day)}/${pad2(p.month)} ${pad2(p.hour)}:${pad2(p.minute)}`;
}
function BurstControl({ s }: { s: OpsService }) {

View File

@@ -26,6 +26,7 @@ import {
useRunScript,
type ScriptRunResult,
} from "@/lib/api/scripts";
import { formatDateLong } from "@/lib/format-date";
/*
* /scripts — catalog of everything under scripts/, rendered as the
@@ -354,11 +355,7 @@ export default function ScriptsPage() {
const lastModified =
data?.last_modified != null
? new Date(data.last_modified * 1000).toLocaleDateString("he-IL", {
year: "numeric",
month: "long",
day: "numeric",
})
? formatDateLong(data.last_modified * 1000)
: null;
const giteaBase = data?.gitea_url ?? null;

View File

@@ -19,6 +19,7 @@ import {
type DriftEntry,
type PaperclipAgent,
} from "@/lib/api/paperclip-agents";
import { formatDateShort } from "@/lib/format-date";
const ROLE_LABEL: Record<string, string> = {
ceo: "CEO",
@@ -211,7 +212,7 @@ function PairCard({ pair }: { pair: AgentPair }) {
</Button>
{pair.master?.updated_at && (
<span className="text-[0.7rem] text-ink-light">
עודכן: {new Date(pair.master.updated_at).toLocaleDateString("he-IL")}
עודכן: {formatDateShort(pair.master.updated_at)}
</span>
)}
</div>

View File

@@ -13,6 +13,7 @@ import {
TableRow,
} from "@/components/ui/table";
import { useSkills, type Skill } from "@/lib/api/skills";
import { formatIsoDate } from "@/lib/format-date";
function formatChars(skill: Skill): string {
// Mockup column = "גודל (תווים)" — the DB markdown char count, grouped.
@@ -21,13 +22,8 @@ function formatChars(skill: Skill): string {
}
function formatUpdated(iso: string | null): string {
if (!iso) return "—";
try {
// ISO-style date to match the mockup (2026-06-09), tabular.
return new Date(iso).toISOString().slice(0, 10);
} catch {
return "—";
}
// ISO-style date to match the mockup (2026-06-09), tabular — Israel-time day.
return formatIsoDate(iso);
}
/**

View File

@@ -17,6 +17,7 @@ import type {
InteractionTask,
PaperclipComment,
} from "@/lib/api/agents";
import { formatRelative } from "@/lib/format-date";
import { toast } from "sonner";
import {
Bot,
@@ -83,15 +84,7 @@ function issueStatusLabel(status: string) {
/* ── Time formatting ─────────────────────────────────────────── */
function timeAgo(iso: string | null): string {
if (!iso) return "";
const diff = Date.now() - new Date(iso).getTime();
const mins = Math.floor(diff / 60_000);
if (mins < 1) return "עכשיו";
if (mins < 60) return `לפני ${mins} דק׳`;
const hours = Math.floor(mins / 60);
if (hours < 24) return `לפני ${hours} שע׳`;
const days = Math.floor(hours / 24);
return `לפני ${days} ימים`;
return formatRelative(iso, { units: "short", fallback: "" });
}
/* ── Issue identifier → find matching identifier ─────────────── */

View File

@@ -4,6 +4,7 @@ import Link from "next/link";
import { Loader2, CheckCircle2, Clock } from "lucide-react";
import { useAgentActivity } from "@/lib/api/agents";
import type { PaperclipIssue } from "@/lib/api/agents";
import { formatRelative } from "@/lib/format-date";
const STATUS_DOT: Record<string, string> = {
in_progress: "bg-gold",
@@ -22,13 +23,7 @@ const STATUS_LABEL: Record<string, string> = {
};
function timeAgo(iso: string | null): string {
if (!iso) return "—";
const diffMs = Date.now() - new Date(iso).getTime();
const m = Math.floor(diffMs / 60_000);
if (m < 60) return `לפני ${m}ד'`;
const h = Math.floor(m / 60);
if (h < 24) return `לפני ${h}ש'`;
return `לפני ${Math.floor(h / 24)} ימים`;
return formatRelative(iso, { units: "tight", fallback: "—" });
}
function IssueRow({ issue }: { issue: PaperclipIssue }) {

View File

@@ -10,21 +10,9 @@ import {
APPEAL_SUBTYPE_LABELS,
isBlamSubtype,
} from "@/lib/practice-area";
import { formatDate } from "@/lib/format-date";
import type { CaseDetail } from "@/lib/api/cases";
function formatDate(iso?: string | null) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL", {
day: "2-digit",
month: "2-digit",
year: "numeric",
});
} catch {
return iso ?? "—";
}
}
function partiesLine(data?: CaseDetail): string | null {
const appellant = data?.appellants?.filter(Boolean) ?? [];
const respondent = data?.respondents?.filter(Boolean) ?? [];

View File

@@ -24,32 +24,16 @@ import {
import { StatusBadge } from "@/components/cases/status-badge";
import { isBlamSubtype } from "@/lib/practice-area";
import type { Case } from "@/lib/api/cases";
import { formatDate, israelMidnightMs, todayIsraelMidnightMs } from "@/lib/format-date";
function formatDate(iso?: string) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL", {
day: "2-digit",
month: "2-digit",
year: "numeric",
});
} catch {
return iso;
}
}
/** Midnight today, in ms — the pivot between an upcoming and a past hearing. */
/** Midnight today in Israel time, in ms — pivot between an upcoming and a past hearing. */
function startOfToday() {
const d = new Date();
d.setHours(0, 0, 0, 0);
return d.getTime();
return todayIsraelMidnightMs();
}
/** Day-precision ms for a hearing date, or null when absent/unparseable. */
/** Day-precision ms (Israel time) for a hearing date, or null when absent/unparseable. */
function hearingMs(iso?: string | null): number | null {
if (!iso) return null;
const t = new Date(iso).setHours(0, 0, 0, 0);
return Number.isNaN(t) ? null : t;
return israelMidnightMs(iso);
}
type HearingClass = "soon" | "upcoming" | "past" | "none";

View File

@@ -17,6 +17,7 @@ import {
type BlockStatus,
} from "@/lib/api/decision-blocks";
import { BLOCK_LABELS } from "@/lib/api/feedback";
import { formatTime } from "@/lib/format-date";
import { AlertTriangle, Pencil, FileText } from "lucide-react";
/* ── status badge styling ─────────────────────────────── */
@@ -233,10 +234,7 @@ function SaveIndicator({ state }: { state: SaveState }) {
return <span className="text-[0.72rem] text-ink-muted"> שומר</span>;
}
if (state.kind === "saved") {
const time = state.at.toLocaleTimeString("he-IL", {
hour: "2-digit",
minute: "2-digit",
});
const time = formatTime(state.at);
return <span className="text-[0.72rem] text-success"> נשמר {time}</span>;
}
return <span className="text-[0.72rem] text-danger"> {state.message}</span>;

View File

@@ -24,6 +24,7 @@ import { apiRequest } from "@/lib/api/client";
import { casesKeys } from "@/lib/api/cases";
import type { CaseDetail, CaseDocument } from "@/lib/api/cases";
import { DocumentTypeEditor } from "@/components/cases/document-type-editor";
import { formatDateShort as formatDate } from "@/lib/format-date";
/*
* Document list for the case detail "מסמכים" tab. Uses the real document
@@ -76,15 +77,6 @@ function StatusIcon({ status }: { status: string }) {
}
}
function formatDate(iso: string) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL");
} catch {
return iso;
}
}
function filenameFromPath(path: string): string {
const parts = path.split("/");
return parts[parts.length - 1] || path;

View File

@@ -38,6 +38,7 @@ import {
import { useCaseCitations } from "@/lib/api/citations";
import { learningKeys } from "@/lib/api/learning";
import { LearningStatusBadges } from "@/components/cases/learning-status-badges";
import { formatDateTime, formatDateShort } from "@/lib/format-date";
import type { CaseStatus } from "@/lib/api/cases";
import { toast } from "sonner";
import {
@@ -72,13 +73,7 @@ function formatSize(bytes: number): string {
}
function formatDate(epoch: number): string {
return new Date(epoch * 1000).toLocaleDateString("he-IL", {
day: "numeric",
month: "short",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
});
return formatDateTime(epoch * 1000);
}
/* ── Main component ─────────────────────────────────── */
@@ -568,9 +563,7 @@ export function DraftsPanel({
</Badge>
)}
<span className="text-[0.65rem] text-ink-muted me-auto">
{fb.created_at
? new Date(fb.created_at).toLocaleDateString("he-IL")
: ""}
{fb.created_at ? formatDateShort(fb.created_at) : ""}
</span>
</div>
<p className="text-sm leading-relaxed">{fb.feedback_text}</p>

View File

@@ -6,6 +6,7 @@ import { StatusChanger } from "@/components/cases/status-changer";
import { StatusGuide } from "@/components/cases/status-guide";
import { AgentStatusWidget } from "@/components/cases/agent-status-widget";
import { expectedOutcomes } from "@/lib/schemas/case";
import { formatDate } from "@/lib/format-date";
import type { CaseDetail } from "@/lib/api/cases";
/*
@@ -21,19 +22,6 @@ const EXPECTED_OUTCOME_LABELS: Record<string, string> = Object.fromEntries(
expectedOutcomes.map((o) => [o.value, o.label]),
);
function formatDate(iso?: string | null): string {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL", {
day: "2-digit",
month: "2-digit",
year: "numeric",
});
} catch {
return iso ?? "—";
}
}
function phaseIndexOf(status?: CaseStatus): number {
if (!status) return -1;
return PHASES.findIndex((p) => p.statuses.includes(status));

View File

@@ -2,17 +2,7 @@
import { useGitStatus } from "@/lib/api/cases";
import { CheckCircle2, AlertCircle, Clock, CloudOff } from "lucide-react";
function formatRelative(iso: string): string {
const diff = Date.now() - new Date(iso).getTime();
const mins = Math.floor(diff / 60_000);
if (mins < 1) return "עכשיו";
if (mins < 60) return `לפני ${mins} דק׳`;
const hours = Math.floor(mins / 60);
if (hours < 24) return `לפני ${hours} שע׳`;
const days = Math.floor(hours / 24);
return `לפני ${days} ימים`;
}
import { formatRelative } from "@/lib/format-date";
export function SyncIndicator({ caseNumber }: { caseNumber?: string }) {
const { data, isLoading } = useGitStatus(caseNumber);

View File

@@ -2,6 +2,7 @@
import { useEffect, useRef, useState } from "react";
import { useSaveChairPosition } from "@/lib/api/research";
import { formatTime } from "@/lib/format-date";
/*
* Chair-position editor for a single threshold claim or issue.
@@ -87,10 +88,7 @@ function SaveIndicator({ state }: { state: SaveState }) {
return <span className="text-[0.72rem] text-ink-muted"> שומר</span>;
}
if (state.kind === "saved") {
const time = state.at.toLocaleTimeString("he-IL", {
hour: "2-digit",
minute: "2-digit",
});
const time = formatTime(state.at);
return <span className="text-[0.72rem] text-success"> נשמר {time}</span>;
}
return <span className="text-[0.72rem] text-danger"> {state.message}</span>;

View File

@@ -5,15 +5,7 @@ import type { ReactNode } from "react";
import { Badge } from "@/components/ui/badge";
import { practiceAreaLabel } from "@/components/precedents/practice-area";
import type { Digest } from "@/lib/api/digests";
function formatDate(iso: string | null) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL");
} catch {
return iso;
}
}
import { formatDateShort as formatDate } from "@/lib/format-date";
/**
* Presentational card for a single digest ("כל יום" radar entry).

View File

@@ -26,6 +26,7 @@ import {
} from "@/components/ui/select";
import type { GraphFacets } from "@/lib/api/graph";
import type { ColorBy, SizeBy } from "@/components/graph/graph-canvas";
import { getIsraelYear } from "@/lib/format-date";
export type GraphControls = {
practiceArea: string;
@@ -51,7 +52,7 @@ const ALL = "__all__";
// Floor covers the oldest dated precedent in the corpus (currently ע"א 725/81 →
// 1982); ceiling tracks the current year so the range never ages out.
const YEAR_FLOOR = 1980;
const CURRENT_YEAR = new Date().getFullYear();
const CURRENT_YEAR = getIsraelYear(new Date()) ?? new Date().getFullYear();
const YEARS = Array.from(
{ length: CURRENT_YEAR - YEAR_FLOOR + 1 },
(_, i) => CURRENT_YEAR - i,

View File

@@ -20,15 +20,7 @@ import {
type MissingPrecedentStatus,
} from "@/lib/api/missing-precedents";
import { MissingPrecedentDetailDrawer } from "./missing-precedent-detail-drawer";
function formatDate(iso: string | null) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL");
} catch {
return iso;
}
}
import { formatDateShort as formatDate } from "@/lib/format-date";
/** Status chip — mockup 09 tones (open=warn, uploaded=info, closed=success,
* irrelevant=muted). Pill-shaped, whitespace-nowrap. */

View File

@@ -14,6 +14,7 @@ import { Card, CardContent } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Skeleton } from "@/components/ui/skeleton";
import { useDiagnostics, type DiagDoc } from "@/lib/api/system";
import { formatDateShort, formatRelative } from "@/lib/format-date";
const TABLE_LABELS: Record<string, string> = {
cases: "תיקים",
@@ -25,16 +26,10 @@ const TABLE_LABELS: Record<string, string> = {
function formatRelativeTime(iso: string | null) {
if (!iso) return "—";
const then = new Date(iso);
const diffMs = Date.now() - then.getTime();
const min = Math.floor(diffMs / 60000);
if (min < 1) return "עכשיו";
if (min < 60) return `לפני ${min} דקות`;
const hr = Math.floor(min / 60);
if (hr < 24) return `לפני ${hr} שעות`;
const days = Math.floor(hr / 24);
if (days < 30) return `לפני ${days} ימים`;
return then.toLocaleDateString("he-IL");
const min = Math.floor((Date.now() - new Date(iso).getTime()) / 60000);
// Past 30 days, fall back to an absolute Israel-time date.
if (min >= 30 * 24 * 60) return formatDateShort(iso);
return formatRelative(iso, { units: "long" });
}
function DocRow({ doc, tone }: { doc: DiagDoc; tone: "danger" | "warn" }) {

View File

@@ -15,6 +15,7 @@ import {
type Halacha, type CanonicalInstance,
} from "@/lib/api/precedent-library";
import { AuthorityBadge, ruleTypeLabel } from "./halacha-meta";
import { formatDateShort as formatDate } from "@/lib/format-date";
/** #81 strict-rubric flags — why an item was held back from auto-approval. */
const QUALITY_FLAG_LABELS: Record<string, string> = {
@@ -28,15 +29,6 @@ const QUALITY_FLAG_LABELS: Record<string, string> = {
nevo_preamble_leak: "דליפת רציו נבו",
};
function formatDate(iso: string | null | undefined) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL");
} catch {
return iso;
}
}
/* Strip Unicode bidi marks that render as zero-width but shift visual position. */
function cleanCitation(s: string | null | undefined): string {
if (!s) return "—";

View File

@@ -31,15 +31,7 @@ import {
FormattedCitation,
CitationCopyButton,
} from "./formatted-citation";
function formatDate(iso: string | null) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL");
} catch {
return iso;
}
}
import { formatDateShort as formatDate } from "@/lib/format-date";
function cleanCitation(s: string | null | undefined): string {
if (!s) return "—";

View File

@@ -14,15 +14,7 @@ import {
} from "@/lib/api/precedent-library";
import { PRACTICE_AREAS, PRECEDENT_LEVELS } from "./practice-area";
import { AuthorityBadge } from "./halacha-meta";
function formatDate(iso: string | null) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL");
} catch {
return iso;
}
}
import { formatDateShort as formatDate } from "@/lib/format-date";
/** Score chip — boxed, gold-deep, tabular (mockup 07 `.score`). Sits at the
* end of the meta row via `ms-auto`. White fill on gold-wash halacha cards. */

View File

@@ -23,6 +23,7 @@ import {
} from "@/lib/api/precedent-library";
import { ApiError } from "@/lib/api/client";
import { useProgress } from "@/lib/api/documents";
import { formatDateShort } from "@/lib/format-date";
import {
PRACTICE_AREAS, PRECEDENT_LEVELS, SOURCE_TYPES,
} from "./practice-area";
@@ -192,7 +193,7 @@ export function PrecedentUploadSheet({ open, onOpenChange }: Props) {
{conflict.citation}
{conflict.case_name && `${conflict.case_name}`}
{conflict.court && ` · ${conflict.court}`}
{conflict.date && ` · ${new Date(conflict.date).toLocaleDateString("he-IL")}`}
{conflict.date && ` · ${formatDateShort(conflict.date)}`}
</p>
{conflict.halacha_extraction_status && (
<p className="text-danger/60 text-[0.72rem]">

View File

@@ -41,6 +41,7 @@ import {
useDeleteChat,
type ChatMessage,
} from "@/lib/api/training";
import { formatDateShort } from "@/lib/format-date";
import { useQueryClient } from "@tanstack/react-query";
export function ChatPanel() {
@@ -200,7 +201,7 @@ function ConversationsSidebar({
<span className="tabular-nums">{c.message_count}</span>
<MessageSquare className="w-3 h-3" />
<span className="grow text-end">
{new Date(c.last_message_at).toLocaleDateString("he-IL")}
{formatDateShort(c.last_message_at)}
</span>
<button
onClick={(e) => { e.stopPropagation(); onDelete(c.id); }}

View File

@@ -11,6 +11,7 @@ import { Badge } from "@/components/ui/badge";
import { Skeleton } from "@/components/ui/skeleton";
import { useCorpus, useDeleteCorpusEntry, type CorpusDecision } from "@/lib/api/training";
import { CorpusDetailDrawer } from "./corpus-detail-drawer";
import { formatDateShort as formatDate } from "@/lib/format-date";
/*
* Corpus tab: table of all decisions currently in the style corpus.
@@ -30,15 +31,6 @@ function formatChars(n: number) {
return `${(n / 1000).toFixed(1)}K`;
}
function formatDate(iso: string) {
if (!iso) return "—";
try {
return new Date(iso).toLocaleDateString("he-IL");
} catch {
return iso;
}
}
function Row({
item, onOpen,
}: { item: CorpusDecision; onOpen: () => void }) {

View File

@@ -32,6 +32,7 @@ import { Skeleton } from "@/components/ui/skeleton";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Markdown } from "@/components/ui/markdown";
import { formatDateShort, formatDateTimeFull } from "@/lib/format-date";
import {
useCuratorPrompt,
useCuratorStats,
@@ -256,7 +257,7 @@ function RecentFindings() {
)}
<span className="grow text-ink-muted text-end">
<Clock className="w-3 h-3 inline me-1" />
{new Date(f.created_at).toLocaleDateString("he-IL")}
{formatDateShort(f.created_at)}
</span>
</div>
<p className="text-sm text-ink leading-relaxed">{f.lesson_text}</p>
@@ -291,7 +292,7 @@ function CuratorPromptCard() {
<h3 className="text-navy font-semibold">{data.filename}</h3>
<p className="text-[0.72rem] text-ink-muted">
{data.bytes.toLocaleString("he-IL")} בייטים ·
עודכן: {new Date(data.last_modified * 1000).toLocaleString("he-IL")}
עודכן: {formatDateTimeFull(data.last_modified * 1000)}
</p>
</div>
<Button asChild variant="outline" size="sm">

View File

@@ -9,6 +9,7 @@ import {
useReconciliationLedger, useStyleDistance, usePairDetail, usePromoteLearning,
type DraftFinalPair,
} from "@/lib/api/learning";
import { formatDateShort as fmtDate } from "@/lib/format-date";
/**
* /training "למידה" tab (T6/T13) — the reconciliation ledger (INV-LRN4): every
@@ -28,11 +29,6 @@ const STATUS_CLASS: Record<string, string> = {
lessons_folded: "bg-emerald-50 text-emerald-800 border-emerald-300/60",
};
function fmtDate(iso: string | null) {
if (!iso) return "—";
try { return new Date(iso).toLocaleDateString("he-IL"); } catch { return iso; }
}
function StyleDistanceDetail({ caseNumber }: { caseNumber: string }) {
const { data, isPending, error } = useStyleDistance(caseNumber);
if (isPending) return <Loader2 className="w-4 h-4 animate-spin text-ink-muted" />;

View File

@@ -37,6 +37,7 @@ import {
usePatchLesson,
type DecisionLesson,
} from "@/lib/api/training";
import { formatDateShort } from "@/lib/format-date";
const CATEGORIES = [
{ value: "general", label: "כללי" },
@@ -224,7 +225,7 @@ function LessonItem({
{reviewBadge.label}
</Badge>
<span className="grow text-ink-muted tabular-nums">
{new Date(lesson.created_at).toLocaleDateString("he-IL")}
{formatDateShort(lesson.created_at)}
</span>
</div>

View File

@@ -0,0 +1,296 @@
/**
* Central date/time formatting — pinned to Israel time (Asia/Jerusalem).
*
* WHY THIS EXISTS (INV-UI9 / G2):
* Storage stays UTC end-to-end (Postgres TIMESTAMPTZ, API returns ISO-UTC).
* Only the *display* layer is localized, and it is localized **deterministically**:
* every human-facing timestamp renders in `Asia/Jerusalem`, regardless of the
* host/container/browser timezone. The legal-ai container runs in UTC, so an
* ad-hoc `new Date(iso).toLocaleDateString("he-IL")` shows UTC under SSR (and
* UTC again on any non-Israel runtime) — that drift is exactly what this module
* removes. Pinning `timeZone: "Asia/Jerusalem"` makes SSR and the browser agree.
*
* This is the ONE date formatter for the UI. Do not format timestamps ad-hoc
* with `new Date(...).toLocaleDateString(...)` / `.toLocaleString(...)` /
* `.getHours()` rendering elsewhere — route through these helpers so the tz is
* always Israel and nothing drifts.
*
* Number formatting (e.g. `n.toLocaleString("he-IL")`) is NOT a timestamp and is
* intentionally out of scope here.
*/
const TZ = "Asia/Jerusalem";
const LOCALE = "he-IL";
/** Coerce an ISO string / epoch-ms / Date into a valid Date, or null. */
function toDate(value: string | number | Date | null | undefined): Date | null {
if (value == null) return null;
const d = value instanceof Date ? value : new Date(value);
return Number.isNaN(d.getTime()) ? null : d;
}
/**
* Date only — `dd/MM/yyyy` in Israel time (e.g. "30/06/2026").
* Matches the prior `toLocaleDateString("he-IL", {day,month:"2-digit",year:"numeric"})`.
*/
export function formatDate(
value: string | number | Date | null | undefined,
fallback = "—",
): string {
const d = toDate(value);
if (!d) return fallback;
return new Intl.DateTimeFormat(LOCALE, {
timeZone: TZ,
day: "2-digit",
month: "2-digit",
year: "numeric",
}).format(d);
}
/**
* Date only — long month form (e.g. "30 ביוני 2026") in Israel time.
* Matches the prior `toLocaleDateString("he-IL", {day:"numeric",month:"long",year:"numeric"})`.
*/
export function formatDateLong(
value: string | number | Date | null | undefined,
fallback = "",
): string {
const d = toDate(value);
if (!d) return fallback;
return new Intl.DateTimeFormat(LOCALE, {
timeZone: TZ,
day: "numeric",
month: "long",
year: "numeric",
}).format(d);
}
/**
* Date only — short form, locale default (e.g. "30.6.2026") in Israel time.
* Matches the prior bare `toLocaleDateString("he-IL")`.
*/
export function formatDateShort(
value: string | number | Date | null | undefined,
fallback = "—",
): string {
const d = toDate(value);
if (!d) return fallback;
return new Intl.DateTimeFormat(LOCALE, { timeZone: TZ }).format(d);
}
/**
* Date + time — `d בMMM yyyy, HH:mm` style in Israel time.
* Matches the prior `{day:"numeric",month:"short",year:"numeric",hour,minute}`.
*/
export function formatDateTime(
value: string | number | Date | null | undefined,
fallback = "—",
): string {
const d = toDate(value);
if (!d) return fallback;
return new Intl.DateTimeFormat(LOCALE, {
timeZone: TZ,
day: "numeric",
month: "short",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
}).format(d);
}
/**
* Full date + time — locale default with time, Israel time.
* Matches the prior bare `toLocaleString("he-IL")`.
*/
export function formatDateTimeFull(
value: string | number | Date | null | undefined,
fallback = "—",
): string {
const d = toDate(value);
if (!d) return fallback;
return new Intl.DateTimeFormat(LOCALE, {
timeZone: TZ,
dateStyle: "short",
timeStyle: "short",
}).format(d);
}
/**
* Time only — `HH:mm` in Israel time (e.g. "14:05").
* Matches the prior `toLocaleTimeString("he-IL", {hour,minute})`.
*/
export function formatTime(
value: string | number | Date | null | undefined,
fallback = "—",
): string {
const d = toDate(value);
if (!d) return fallback;
return new Intl.DateTimeFormat(LOCALE, {
timeZone: TZ,
hour: "2-digit",
minute: "2-digit",
}).format(d);
}
/**
* ISO calendar date `YYYY-MM-DD` for the Israel-time day of the instant.
* Deterministic replacement for `new Date(iso).toISOString().slice(0,10)`,
* which yields the UTC day (off-by-one near midnight Israel time).
*/
export function formatIsoDate(
value: string | number | Date | null | undefined,
fallback = "—",
): string {
const d = toDate(value);
if (!d) return fallback;
// en-CA's short date is ISO-shaped (YYYY-MM-DD); pin the tz so it's the Israel day.
return new Intl.DateTimeFormat("en-CA", {
timeZone: TZ,
year: "numeric",
month: "2-digit",
day: "2-digit",
}).format(d);
}
/**
* The calendar year (number) of the Israel-time day for an instant.
* Deterministic replacement for `new Date(iso).getFullYear()` (which uses the
* runtime tz). Returns null when the value is absent/unparseable.
*/
export function getIsraelYear(
value: string | number | Date | null | undefined,
): number | null {
const d = toDate(value);
if (!d) return null;
const y = new Intl.DateTimeFormat("en-CA", { timeZone: TZ, year: "numeric" }).format(d);
const n = Number(y);
return Number.isNaN(n) ? null : n;
}
/**
* The Israel-time calendar day of an instant as a sortable integer YYYYMMDD,
* or null when absent/unparseable. Use this to compare two dates at *day*
* precision in Israel time (e.g. hearing-date vs. today) without runtime-tz drift.
*/
export function israelDayKey(
value: string | number | Date | null | undefined,
): number | null {
const iso = formatIsoDate(value, ""); // "YYYY-MM-DD" or ""
if (!iso) return null;
const n = Number(iso.replace(/-/g, ""));
return Number.isNaN(n) ? null : n;
}
/** Today's Israel-time calendar day as a sortable integer YYYYMMDD. */
export function todayIsraelDayKey(): number {
return israelDayKey(new Date()) as number;
}
/**
* The UTC-ms of midnight (00:00) of the instant's *Israel* calendar day.
* Day-precision pivot for ms-based comparisons/diffs (e.g. hearing date vs.
* today) that must not drift with the runtime timezone. Returns null when the
* value is absent/unparseable. Built from the en-CA YYYY-MM-DD of the Israel day
* combined with the Israel UTC offset at that instant, so two values from the
* same Israel day always reduce to the same ms.
*/
export function israelMidnightMs(
value: string | number | Date | null | undefined,
): number | null {
const d = toDate(value);
if (!d) return null;
const iso = formatIsoDate(d, ""); // YYYY-MM-DD of the Israel day
if (!iso) return null;
const [y, m, day] = iso.split("-").map(Number);
// Israel wall-clock midnight as a UTC instant: take naive UTC midnight of that
// calendar day and subtract Israel's offset (Israel is ahead of UTC).
const naiveUtcMidnight = Date.UTC(y, m - 1, day);
const utc = new Date(d.toLocaleString("en-US", { timeZone: "UTC" }));
const isr = new Date(d.toLocaleString("en-US", { timeZone: TZ }));
const offsetMs = isr.getTime() - utc.getTime();
return naiveUtcMidnight - offsetMs;
}
/** UTC-ms of midnight of *today's* Israel calendar day. */
export function todayIsraelMidnightMs(): number {
return israelMidnightMs(new Date()) as number;
}
/**
* Numeric date/time components of an instant in Israel time. For the rare call
* site that builds a bespoke string from parts (e.g. a custom weekday + dd/MM
* HH:mm deadline label) and must do so in Israel time rather than the runtime
* tz. `weekday` is 0=Sunday … 6=Saturday (matching `Date.getDay()`).
* Returns null when the value is absent/unparseable.
*/
export function israelParts(
value: string | number | Date | null | undefined,
): { year: number; month: number; day: number; hour: number; minute: number; weekday: number } | null {
const d = toDate(value);
if (!d) return null;
const parts = new Intl.DateTimeFormat("en-US", {
timeZone: TZ,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
weekday: "short",
hour12: false,
}).formatToParts(d);
const get = (t: string) => parts.find((p) => p.type === t)?.value ?? "";
const WD: Record<string, number> = { Sun: 0, Mon: 1, Tue: 2, Wed: 3, Thu: 4, Fri: 5, Sat: 6 };
let hour = Number(get("hour"));
if (hour === 24) hour = 0; // some engines emit "24" for midnight under hour12:false
return {
year: Number(get("year")),
month: Number(get("month")),
day: Number(get("day")),
hour,
minute: Number(get("minute")),
weekday: WD[get("weekday")] ?? 0,
};
}
/**
* Relative "time ago" in Hebrew. Timezone-agnostic (it's a diff between two
* absolute instants), but centralized here so all relative rendering lives in
* one place. `units` selects the existing wording per call site so visible text
* is unchanged:
* - "long": עכשיו / לפני N דקות / לפני N שעות / לפני N ימים
* - "short": עכשיו / לפני N דק׳ / לפני N שע׳ / לפני N ימים
* - "tight": לפני Nד' / לפני Nש' / לפני N ימים (no "now" bucket)
*/
export function formatRelative(
value: string | number | Date | null | undefined,
opts: { units?: "long" | "short" | "tight"; fallback?: string } = {},
): string {
const { units = "short", fallback = "" } = opts;
const d = toDate(value);
if (!d) return fallback;
const diffMs = Date.now() - d.getTime();
const mins = Math.floor(diffMs / 60_000);
const hours = Math.floor(mins / 60);
const days = Math.floor(hours / 24);
if (units === "tight") {
if (mins < 60) return `לפני ${mins}ד'`;
if (hours < 24) return `לפני ${hours}ש'`;
return `לפני ${days} ימים`;
}
const now = "עכשיו";
if (units === "long") {
if (mins < 1) return now;
if (mins < 60) return `לפני ${mins} דקות`;
if (hours < 24) return `לפני ${hours} שעות`;
return `לפני ${days} ימים`;
}
// "short"
if (mins < 1) return now;
if (mins < 60) return `לפני ${mins} דק׳`;
if (hours < 24) return `לפני ${hours} שע׳`;
return `לפני ${days} ימים`;
}