feat: exibir tempo médio em horas e minutos

This commit is contained in:
Esdras Renan 2025-11-17 09:10:45 -03:00
parent b33cb6c89a
commit 87f729b80f
2 changed files with 16 additions and 2 deletions

View file

@ -12,7 +12,7 @@ import { api } from "@/convex/_generated/api"
import type { Id } from "@/convex/_generated/dataModel"
import { useAuth } from "@/lib/auth-client"
import { DEFAULT_TENANT_ID } from "@/lib/constants"
import { cn, formatDateDM, formatDateDMY } from "@/lib/utils"
import { cn, formatDateDM, formatDateDMY, formatMinutesHuman } from "@/lib/utils"
import { Badge } from "@/components/ui/badge"
import {
Card,
@ -205,7 +205,7 @@ export function DashboardHero() {
<CardTitle className="text-3xl font-semibold text-neutral-900 tabular-nums">
{overview?.firstResponse ? (
overview.firstResponse.averageMinutes !== null ? (
`${overview.firstResponse.averageMinutes.toFixed(1)} min`
formatMinutesHuman(overview.firstResponse.averageMinutes)
) : (
"—"
)

View file

@ -17,6 +17,20 @@ export function formatHoursCompact(value: number, locale: string = "pt-BR"): str
return `${nf.format(hours)} h`
}
// Format minutes to h/m when reaching the 1h mark; below that keep 1 decimal minute precision.
// Examples: 45.3 -> "45,3 min"; 60 -> "1h"; 185 -> "3h5m"
export function formatMinutesHuman(value: number, locale: string = "pt-BR"): string {
const minutes = Number.isFinite(value) ? Math.max(value, 0) : 0
if (minutes < 60) {
const nf = new Intl.NumberFormat(locale, { minimumFractionDigits: 1, maximumFractionDigits: 1 })
return `${nf.format(minutes)} min`
}
const rounded = Math.round(minutes)
const hours = Math.floor(rounded / 60)
const remainingMinutes = rounded % 60
return remainingMinutes === 0 ? `${hours}h` : `${hours}h${remainingMinutes}m`
}
// Format date to dd/MM or dd/MM/yyyy. Accepts Date or ISO-like string (YYYY-MM-DD).
export function formatDateDM(value: Date | string | number): string {
const d = typeof value === "string" || typeof value === "number" ? new Date(value) : value