feat: add date formatting utility and enhance filtering in registro-pontos
- Introduced a new utility function `formatarDataDDMMAAAA` to format dates in DD/MM/AAAA format, supporting various input types. - Updated the `registro-pontos` page to utilize the new date formatting function for displaying dates consistently. - Implemented advanced filtering options for status and location, allowing users to filter records based on their criteria. - Enhanced CSV export functionality to include formatted dates and additional filtering capabilities, improving data management for users.
This commit is contained in:
@@ -122,3 +122,37 @@ export function getProximoTipoRegistro(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formata data no formato DD/MM/AAAA
|
||||
* Suporta strings ISO (YYYY-MM-DD), objetos Date, e timestamps
|
||||
*/
|
||||
export function formatarDataDDMMAAAA(data: string | Date | number): string {
|
||||
if (!data) return '';
|
||||
|
||||
let dataObj: Date;
|
||||
|
||||
if (typeof data === 'string') {
|
||||
// Se for string no formato ISO (YYYY-MM-DD), adicionar hora para evitar problemas de timezone
|
||||
if (data.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
||||
dataObj = new Date(data + 'T12:00:00');
|
||||
} else {
|
||||
dataObj = new Date(data);
|
||||
}
|
||||
} else if (typeof data === 'number') {
|
||||
dataObj = new Date(data);
|
||||
} else {
|
||||
dataObj = data;
|
||||
}
|
||||
|
||||
// Verificar se a data é válida
|
||||
if (isNaN(dataObj.getTime())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const dia = dataObj.getDate().toString().padStart(2, '0');
|
||||
const mes = (dataObj.getMonth() + 1).toString().padStart(2, '0');
|
||||
const ano = dataObj.getFullYear();
|
||||
|
||||
return `${dia}/${mes}/${ano}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user