fix: corrección de errores en mapa y filtros de horarios
This commit is contained in:
@ -39,42 +39,69 @@ function getBusStatus(timeStr: string): 'departing' | 'ontime' | 'upcoming' | 'p
|
||||
return 'upcoming'
|
||||
}
|
||||
|
||||
// ── 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
|
||||
function getScheduleDay(schedule: any): 'today' | 'tomorrow' | 'other' {
|
||||
const now = new Date()
|
||||
const dow = now.getDay() // 0=Dom, 6=Sab
|
||||
const isWeekend = dow === 0 || dow === 6
|
||||
const isTomorrow = (!isWeekend && schedule.schedule_type === 'weekend') ||
|
||||
(isWeekend && schedule.schedule_type === 'weekday')
|
||||
const tomorrow = new Date(now)
|
||||
tomorrow.setDate(now.getDate() + 1)
|
||||
|
||||
const getDayType = (date: Date) => {
|
||||
const dow = date.getDay() // 0=Dom, 6=Sab
|
||||
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 || 'todos'
|
||||
|
||||
const isToday = type === todayType || type === 'todos'
|
||||
const isTomorrow = type === tomorrowType || type === 'todos'
|
||||
|
||||
if (isToday) return 'today'
|
||||
if (isTomorrow) return 'tomorrow'
|
||||
if (schedule.schedule_type === 'holiday') return 'other'
|
||||
return 'today'
|
||||
if (type === 'holiday') return 'other'
|
||||
|
||||
return 'other'
|
||||
}
|
||||
|
||||
function getDayLabel(schedule: any): string {
|
||||
const d = getScheduleDay(schedule)
|
||||
if (d === 'today') return 'Hoy'
|
||||
if (d === 'tomorrow') return 'Mañana'
|
||||
return 'Próximo'
|
||||
const type = schedule.schedule_type || 'todos'
|
||||
const now = new Date()
|
||||
const todayType = (now.getDay() === 0 || now.getDay() === 6) ? 'weekend' : 'weekday'
|
||||
|
||||
if (type === 'todos') return 'Diario'
|
||||
if (type === todayType) return 'Hoy'
|
||||
return 'Mañana'
|
||||
}
|
||||
|
||||
// ── Filtrado de horarios
|
||||
const filteredSchedules = computed(() => {
|
||||
const now = new Date()
|
||||
const hhmmAhora = now.getHours() * 100 + now.getMinutes()
|
||||
|
||||
return scheduleStore.schedules.filter(s => {
|
||||
const d = getScheduleDay(s)
|
||||
const status = getBusStatus(s.departure_time)
|
||||
const [hStr, mStr] = (s.departure_time || '00:00').split(':')
|
||||
const h = parseInt(hStr || '0')
|
||||
const m = parseInt(mStr || '0')
|
||||
const hhmmSched = h * 100 + m
|
||||
const isPassed = hhmmSched < hhmmAhora - 2 // margen de 2 min
|
||||
|
||||
// Filtro Hoy: Solo buses de hoy que NO han pasado
|
||||
// Filtro Hoy: Es hoy Y no ha pasado (o es de los que dice salir en este rango)
|
||||
if (dayFilter.value === 'today') {
|
||||
return d === 'today' && status !== 'passed'
|
||||
return d === 'today' && !isPassed
|
||||
}
|
||||
|
||||
// Filtro Mañana: Solo buses de mañana
|
||||
// Filtro Mañana: Es mañana
|
||||
if (dayFilter.value === 'tomorrow') {
|
||||
return d === 'tomorrow'
|
||||
}
|
||||
|
||||
// Filtro Todos: Mostrar todo
|
||||
// Filtro Todos: Mostrar todo sin importar si pasó o es otro día
|
||||
return true
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user