Overview
TheHorarioAperturaRepositorio defines the contract for managing restaurant business hours, including checking if a restaurant is open at specific times, generating available time slots, and converting between different data formats. The Firestore implementation (HorarioAperturaRepositorioFirestore) provides flexible hour parsing and validation.
Interface
lib/dominio/repositorios/horario_apertura_repositorio.dart
Methods
obtenerHorarioPorNegocio
Retrieves the complete business hours configuration for a restaurant.The unique identifier of the restaurant.
Returns the business hours entity if found, or
null if no schedule is configured.Example Usage
estaAbiertoEn
Checks if a restaurant is open at a specific date and time.The unique identifier of the restaurant.
The date and time to check (includes both date and time components).
Returns
true if the restaurant is open at that time, or false if closed. Returns true if no schedule is configured (default open).- If no schedule exists, assumes the restaurant is always open
- Uses
HorarioApertura.estaAbiertoEn()method for validation - Considers the day of the week and time of day
Example Usage
obtenerMensajeHorarioCerrado
Generates a user-friendly error message when a restaurant is closed.The unique identifier of the restaurant.
The date and time that was requested.
Returns an error message if the restaurant is closed, or an empty string if it’s open. Returns a default message if no schedule is configured.
- “El restaurante está cerrado los lunes”
- “El restaurante cierra a las 15:00. Próximo horario: 20:00 - 23:00”
- “No hay información de horarios disponible.”
Example Usage
obtenerIntervalosDisponibles
Generates a list of available time slots for a specific date based on business hours.The unique identifier of the restaurant.
The date to generate time slots for.
The duration of each time slot in minutes.
Returns a list of formatted time slots (e.g., [“12:00 - 13:00”, “13:00 - 14:00”]). Returns an empty list if closed or no schedule configured.
- Fetches the business hours for the restaurant
- Identifies the day of the week from the date
- Returns empty list if the restaurant is closed that day
- For each open time interval:
- Generates slots starting from the opening time
- Each slot has the specified duration
- Continues until the closing time is reached
- Handles midnight-crossing intervals (e.g., 23:00 - 02:00)
Example Usage
guardarHorario
Saves or updates the business hours for a restaurant.The complete business hours configuration to save.
Returns
true if the save was successful, false otherwise.- Creates a new document if no schedule exists for the business
- Updates the existing document if a schedule already exists
- Uses the
negocioIdfrom theHorarioAperturaobject to identify the restaurant
Example Usage
horarioAMapString
Converts aHorarioApertura entity to a user-friendly string map for UI display.
The business hours configuration to convert.
Returns a map where keys are day names and values are formatted hour strings.
{"lunes": "Cerrado"}{"martes": "12:00 - 15:30"}{"miércoles": "12:00 - 15:30 / 20:00 - 23:30"}{"jueves": "Sin horario"}
Example Usage
mapStringAHorario
Converts a user-edited string map back to aHorarioApertura entity.
The unique identifier of the restaurant.
A map where keys are day names and values are hour strings.
Returns a complete
HorarioApertura entity parsed from the strings.| Input String | Parsed Result |
|---|---|
"Cerrado" | Day marked as closed |
"9-13" | Single interval: 9:00 - 13:00 |
"09:00 - 13:00" | Single interval: 9:00 - 13:00 |
"9 - 13:30" | Single interval: 9:00 - 13:30 |
"12:00 - 15:30 / 20:00 - 23:30" | Two intervals (split shifts) |
"9-13 y 18-22" | Two intervals using “y” separator |
"12 a 15" | Single interval: 12:00 - 15:00 |
"12 hasta 15:30" | Single interval: 12:00 - 15:30 |
- Supports
/oryas interval separators - Supports
-,a, orhastaas range separators - Handles hours with or without minutes (“9” becomes “9:00”)
- Ignores whitespace and normalizes formatting
Example Usage
Firestore Implementation
Collection Structure
Business hours are stored in thehorarios_apertura collection:
Firestore Document
Day Name Mapping
The implementation maps Spanish day names to weekday numbers (ISO 8601):| Spanish Name | Weekday Number |
|---|---|
"lunes" | 1 (Monday) |
"martes" | 2 (Tuesday) |
"miércoles" / "miercoles" | 3 (Wednesday) |
"jueves" | 4 (Thursday) |
"viernes" | 5 (Friday) |
"sábado" / "sabado" | 6 (Saturday) |
"domingo" | 7 (Sunday) |
Midnight-Crossing Intervals
The implementation handles intervals that cross midnight (e.g., 23:00 - 02:00):Related Types
HorarioApertura Entity
HorarioDia Entity
IntervaloHorario Entity
Use Cases
Validating Reservation Times
Building a Time Slot Picker
Admin Schedule Editor
See Also
- NegocioRepositorio - Restaurant business management
- ReservaRepositorio - Should validate against business hours