Download frontend/src/lib/format.ts from stadv/sipracd: direct link, hf CLI and curl.
- Browser
- Download file 2.95 kB
-
https://huggingface.co/spaces/stadv/sipracd/resolve/main/frontend/src/lib/format.ts
- Command line
-
hf download hf://spaces/stadv/sipracd/frontend/src/lib/format.ts
-
curl -L -o format.ts https://huggingface.co/spaces/stadv/sipracd/resolve/main/frontend/src/lib/format.ts
2.95 kB
| export function formatDate(value?: string | null) { | |
| if (!value) return "Sem data"; | |
| return new Intl.DateTimeFormat("pt-BR", { | |
| day: "2-digit", | |
| month: "2-digit", | |
| year: "numeric", | |
| }).format(new Date(`${value}T12:00:00`)); | |
| } | |
| export function formatMonth(value?: string | null) { | |
| if (!value) return "Sem mês"; | |
| return new Intl.DateTimeFormat("pt-BR", { | |
| month: "2-digit", | |
| year: "numeric", | |
| }).format(new Date(`${value}T12:00:00`)); | |
| } | |
| export function dateValueToMonthInput(value?: string | null) { | |
| if (!value) return ""; | |
| return value.slice(0, 7); | |
| } | |
| export function monthInputToDateValue(value?: string | null) { | |
| if (!value) return null; | |
| return `${value}-01`; | |
| } | |
| export function formatDateTime(value?: string | null) { | |
| if (!value) return "Sem data"; | |
| return new Intl.DateTimeFormat("pt-BR", { | |
| day: "2-digit", | |
| month: "2-digit", | |
| year: "numeric", | |
| hour: "2-digit", | |
| minute: "2-digit", | |
| }).format(new Date(value)); | |
| } | |
| export function formatNumber(value: number) { | |
| return new Intl.NumberFormat("pt-BR", { | |
| minimumFractionDigits: value % 1 === 0 ? 0 : 1, | |
| maximumFractionDigits: 2, | |
| }).format(value); | |
| } | |
| export function statusLabel(status: string) { | |
| const normalized = status.replace(/_/g, " ").trim().toLowerCase(); | |
| const labels: Record<string, string> = { | |
| sem_atribuicao: "Sem atribuição", | |
| "sem atribuicao": "Sem atribuição", | |
| com_avaliador: "Com avaliador", | |
| "com avaliador": "Com avaliador", | |
| pendente_revisao: "Pendente de revisão", | |
| "pendente revisao": "Pendente de revisão", | |
| em_ajuste: "Em ajuste", | |
| "em ajuste": "Em ajuste", | |
| revisado: "Revisado", | |
| pronto: "Pronto", | |
| enviado: "Enviado", | |
| pendente: "Pendente", | |
| ativa: "Ativa", | |
| planejada: "Planejada", | |
| concluido: "Concluído", | |
| concluida: "Concluída", | |
| "sem dado": "Sem dado", | |
| }; | |
| return labels[normalized] ?? normalized.charAt(0).toUpperCase() + normalized.slice(1); | |
| } | |
| export function hasPriority(value?: string | null) { | |
| const normalized = (value ?? "").trim().toLowerCase(); | |
| return Boolean(normalized) && !normalized.startsWith("sem prioridade"); | |
| } | |
| export function goalDifferenceText(planned: number, capacity: number) { | |
| const difference = capacity - planned; | |
| if (difference === 0) return "Carga igual à capacidade"; | |
| if (difference > 0) return `${formatNumber(difference)} dia(s) livres no período`; | |
| return `${formatNumber(Math.abs(difference))} dia(s) acima da capacidade`; | |
| } | |
| export function goalReadingText(planned: number, capacity: number, rawStatus?: string | null) { | |
| const normalized = (rawStatus ?? "").toLowerCase(); | |
| if (normalized.includes("treinamento")) return "Período de treinamento"; | |
| if (!capacity) return "Sem capacidade registrada"; | |
| if (planned > capacity) return "Planejamento acima da capacidade"; | |
| if (planned < capacity) return "Planejamento abaixo da capacidade"; | |
| return "Planejamento igual à capacidade"; | |
| } | |