fix: calcStatus usa Date.UTC para evitar bug de timezone no vencimento

This commit is contained in:
Junior
2026-03-15 11:21:49 -03:00
parent e6639162df
commit 8c3c56de09

View File

@@ -33,9 +33,11 @@ function tipoLabel(tipo: string): string {
function calcStatus(dataVenc: string | null): 'sem_vencimento' | 'vencida' | 'vencendo' | 'valida' { function calcStatus(dataVenc: string | null): 'sem_vencimento' | 'vencida' | 'vencendo' | 'valida' {
if (!dataVenc) return 'sem_vencimento' if (!dataVenc) return 'sem_vencimento'
const hoje = new Date() const hoje = new Date()
hoje.setHours(0, 0, 0, 0) const hojeMs = Date.UTC(hoje.getFullYear(), hoje.getMonth(), hoje.getDate())
const venc = new Date(dataVenc + 'T00:00:00') const dateStr = dataVenc.split('T')[0] // "YYYY-MM-DD"
const diff = (venc.getTime() - hoje.getTime()) / (1000 * 60 * 60 * 24) const [y, m, d] = dateStr.split('-').map(Number)
const vencMs = Date.UTC(y, m - 1, d)
const diff = (vencMs - hojeMs) / (1000 * 60 * 60 * 24)
if (diff < 0) return 'vencida' if (diff < 0) return 'vencida'
if (diff <= 30) return 'vencendo' if (diff <= 30) return 'vencendo'
return 'valida' return 'valida'