109 lines
2.7 KiB
JavaScript
109 lines
2.7 KiB
JavaScript
const months = [
|
|
"Enero",
|
|
"Febrero",
|
|
"Marzo",
|
|
"Abril",
|
|
"Mayo",
|
|
"Junio",
|
|
"Julio",
|
|
"Agosto",
|
|
"Septiembre",
|
|
"Octubre",
|
|
"Noviembre",
|
|
"Diciembre"
|
|
];
|
|
|
|
const monthsAbr = [
|
|
"Ene",
|
|
"Feb",
|
|
"Mar",
|
|
"Abr",
|
|
"May",
|
|
"Jun",
|
|
"Jul",
|
|
"Ago",
|
|
"Sep",
|
|
"Oct",
|
|
"Nov",
|
|
"Dic"
|
|
];
|
|
|
|
export const getDayMonthYear = (value) => {
|
|
if(value === null) return 'Fecha invalida';
|
|
const year = value.substring(0, 4);
|
|
const month = value.substring(5, 7);
|
|
const day = value.substring(8, 10);
|
|
return `${day}/${month}/${year}`;
|
|
};
|
|
|
|
export const getDateMonthDay = (value) => {
|
|
// Crear una fecha a partir del valor proporcionado
|
|
const date = new Date(value);
|
|
// Ajustar la fecha a la zona horaria de México manualmente
|
|
const utcOffset = -6; // Offset de UTC para la hora estándar de México
|
|
date.setHours(date.getHours() + utcOffset);
|
|
// Convertir la fecha a la hora de México
|
|
const options = {
|
|
timeZone: 'America/Mexico_City',
|
|
month: 'short',
|
|
day: '2-digit',
|
|
year: 'numeric',
|
|
};
|
|
|
|
// Convertir la fecha a una cadena localizada con la zona horaria de México
|
|
const dateString = date.toLocaleString('es-ES', options);
|
|
|
|
return dateString;
|
|
};
|
|
|
|
export const getDateMonthDayEs = (value, isFull = false) => {
|
|
const date = new Date(value)
|
|
// date.setHours(date.getHours());
|
|
let month = '';
|
|
if(isFull) {
|
|
month = months[date.getMonth()];
|
|
} else {
|
|
month = monthsAbr[date.getMonth()]
|
|
}
|
|
return `${month} ${date.getDate()}, ${date.getFullYear()}`;
|
|
}
|
|
|
|
export const getDateTime = (value, hour) => {
|
|
|
|
const date = new Date(value);
|
|
date.setHours(date.getHours() + hour);
|
|
|
|
// Obtener los componentes de la fecha
|
|
const year = date.getFullYear();
|
|
const month = ('0' + (date.getMonth() + 1)).slice(-2);
|
|
const day = ('0' + date.getDate()).slice(-2);
|
|
const hours = ('0' + date.getHours()).slice(-2);
|
|
const minutes = ('0' + date.getMinutes()).slice(-2);
|
|
|
|
// Crear la cadena de fecha formateada
|
|
const dateFormat = `${year}-${month}-${day} ${hours}:${minutes}`;
|
|
|
|
return dateFormat;
|
|
}
|
|
|
|
export const getDateOnly = (value) => {
|
|
|
|
const date = new Date(value);
|
|
date.setHours(date.getHours());
|
|
|
|
// Obtener los componentes de la fecha
|
|
const year = date.getFullYear();
|
|
const month = ('0' + (date.getMonth() + 1)).slice(-2);
|
|
const day = ('0' + date.getDate()).slice(-2);
|
|
|
|
const dateFormat = `${day}/${month}/${year}`;
|
|
|
|
return dateFormat;
|
|
}
|
|
|
|
export const formatOnlyDate = (date) => {
|
|
const year = date.getFullYear();
|
|
const month = String(date.getMonth() + 1).padStart(2, '0'); // Agregar cero si es necesario
|
|
const day = String(date.getDate()).padStart(2, '0'); // Agregar cero si es necesario
|
|
return `${year}/${month}/${day}`;
|
|
} |