fix(schedules): check dias_operacion in SchedulesView and update types
This commit is contained in:
@ -63,6 +63,7 @@ export interface BusSchedule {
|
||||
schedule_type: ScheduleType
|
||||
is_active: boolean
|
||||
is_published: boolean
|
||||
dias_operacion?: string[] | null
|
||||
notes?: string
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
@ -48,28 +48,45 @@ function getBusStatus(timeStr: string): 'departing' | 'ontime' | 'upcoming' | 'p
|
||||
|
||||
// ── Calcular si el horario es "hoy" o "mañana" según tipo de día
|
||||
// ── Calcular si el horario es "hoy" o "mañana" según tipo de día
|
||||
const normalizar = (s: string | null | undefined) => (s || "").toLowerCase().trim().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||
|
||||
function getScheduleDay(schedule: any): 'today' | 'tomorrow' | 'other' {
|
||||
const now = new Date()
|
||||
const tomorrow = new Date(now)
|
||||
tomorrow.setDate(now.getDate() + 1)
|
||||
|
||||
const dias = ['domingo', 'lunes', 'martes', 'miercoles', 'jueves', 'viernes', 'sabado']
|
||||
const hoyStr = normalizar(dias[now.getDay()])
|
||||
const mañanaStr = normalizar(dias[tomorrow.getDay()])
|
||||
|
||||
const diasOP = schedule.dias_operacion as string[] | null
|
||||
if (diasOP && Array.isArray(diasOP) && diasOP.length > 0) {
|
||||
const isToday = diasOP.some(d => {
|
||||
const dNorm = normalizar(d)
|
||||
return dNorm === 'todos' || dNorm === hoyStr
|
||||
})
|
||||
if (isToday) return 'today'
|
||||
|
||||
const isTomorrow = diasOP.some(d => {
|
||||
const dNorm = normalizar(d)
|
||||
return dNorm === 'todos' || dNorm === mañanaStr
|
||||
})
|
||||
if (isTomorrow) return 'tomorrow'
|
||||
|
||||
return 'other'
|
||||
}
|
||||
|
||||
const getDayType = (date: Date) => {
|
||||
const dow = date.getDay() // 0=Dom, 6=Sab
|
||||
const dow = date.getDay()
|
||||
return (dow === 0 || dow === 6) ? 'weekend' : 'weekday'
|
||||
}
|
||||
|
||||
const todayType = getDayType(now)
|
||||
const tomorrowType = getDayType(tomorrow)
|
||||
|
||||
// Comparar con el tipo del horario
|
||||
// Nota: Si el horario es 'todos', cuenta para hoy y mañana (pero priorizamos hoy si pides hoy)
|
||||
const type = (schedule.schedule_type as string) || 'todos'
|
||||
|
||||
const isToday = type === todayType || type === 'todos'
|
||||
const isTomorrow = type === tomorrowType || type === 'todos'
|
||||
|
||||
if (isToday) return 'today'
|
||||
if (isTomorrow) return 'tomorrow'
|
||||
if (type === todayType || type === 'todos') return 'today'
|
||||
if (type === tomorrowType || type === 'todos') return 'tomorrow'
|
||||
if (type === 'holiday') return 'other'
|
||||
|
||||
return 'other'
|
||||
@ -94,12 +111,7 @@ const filteredSchedules = computed(() => {
|
||||
const hhmmAhora = now.getHours() * 100 + now.getMinutes()
|
||||
|
||||
return scheduleStore.schedules.filter(s => {
|
||||
const type = (s.schedule_type as string) || 'todos'
|
||||
const todayType = (now.getDay() === 0 || now.getDay() === 6) ? 'weekend' : 'weekday'
|
||||
const tomorrowType = (tomorrow.getDay() === 0 || tomorrow.getDay() === 6) ? 'weekend' : 'weekday'
|
||||
|
||||
const isActuallyToday = type === todayType || type === 'todos'
|
||||
const isActuallyTomorrow = type === tomorrowType || type === 'todos'
|
||||
const dayStatus = getScheduleDay(s)
|
||||
|
||||
// Filtro Hoy: Es hoy Y no ha pasado (o es de los que dice salir en este rango)
|
||||
if (dayFilter.value === 'today') {
|
||||
@ -108,12 +120,12 @@ const filteredSchedules = computed(() => {
|
||||
const m = parseInt(mStr || '0')
|
||||
const hhmmSched = h * 100 + m
|
||||
const isPassed = hhmmSched < hhmmAhora - 2 // margen de 2 min
|
||||
return isActuallyToday && !isPassed
|
||||
return dayStatus === 'today' && !isPassed
|
||||
}
|
||||
|
||||
// Filtro Mañana: Es mañana (sin importar si pasó la hora hoy)
|
||||
if (dayFilter.value === 'tomorrow') {
|
||||
return isActuallyTomorrow
|
||||
return dayStatus === 'tomorrow'
|
||||
}
|
||||
|
||||
// Filtro Todos: Mostrar todo
|
||||
|
||||
Reference in New Issue
Block a user