Overview
The Service Hours API provides functions to manage store operating hours, check service availability, and load dynamic settings from Edge Config.
Source: src/config/serviceHours.js
Functions
isServiceOpen()
Checks whether the service is currently open based on configured hours, store status, and special closures.
import { isServiceOpen } from '@/config/serviceHours' ;
const checkService = async () => {
const isOpen = await isServiceOpen ();
if ( isOpen ) {
console . log ( 'Service is available' );
} else {
console . log ( 'Service is closed' );
}
};
Returns true if service is open, false if closed
Returns false if store is manually closed or in maintenance mode
Returns true if test mode is enabled
Checks if current date is in closedDates array
Validates weekday/weekend availability
Compares current time against service hours
getServiceHoursText()
Returns a formatted string representation of service hours.
import { getServiceHoursText } from '@/config/serviceHours' ;
const hours = getServiceHoursText ();
console . log ( hours ); // "08:30 - 20:30"
Formatted time range (e.g., “08:30 - 20:30”)
getNextServiceTime()
Calculates the next service opening time.
import { getNextServiceTime } from '@/config/serviceHours' ;
const nextOpen = getNextServiceTime ();
if ( nextOpen ) {
console . log ( `Service opens at: ${ nextOpen . toLocaleString () } ` );
}
Returns a Date object for tomorrow’s opening time, or null if test mode is enabled
loadEdgeConfigSettings()
Loads service configuration from Edge Config and updates active settings.
import { loadEdgeConfigSettings } from '@/config/serviceHours' ;
await loadEdgeConfigSettings ();
Async function that updates ACTIVE_SERVICE_HOURS and STORE_STATUS
Merges Edge Config settings with default settings
Updates global ACTIVE_SERVICE_HOURS variable
Updates global STORE_STATUS variable
Logs loaded settings or warning if loading fails
getActiveServiceHours()
Returns the current active service hours configuration.
import { getActiveServiceHours } from '@/config/serviceHours' ;
const config = getActiveServiceHours ();
console . log ( config . startHour ); // 8
console . log ( config . endHour ); // 20
Service hours configuration object (see DEFAULT_SERVICE_HOURS structure)
getStoreStatus()
Returns the current store status.
import { getStoreStatus } from '@/config/serviceHours' ;
const status = getStoreStatus ();
if ( status . maintenanceMode ) {
console . log ( `Store in maintenance: ${ status . reason } ` );
}
Show Store Status Object Structure
Whether the store is open
Whether the store is temporarily closed
Whether the store is in maintenance mode
Reason for closure (if applicable)
Configuration
DEFAULT_SERVICE_HOURS
Default service hours configuration object.
import { DEFAULT_SERVICE_HOURS } from '@/config/serviceHours' ;
Show Configuration Properties
Service start hour (24-hour format)
Service end hour (24-hour format)
Whether service is available on weekdays (Monday-Friday)
Whether service is available on weekends (Saturday-Sunday)
Array of dates when service is closed (YYYY-MM-DD format)
If true, service is always considered open
Usage Example
import {
isServiceOpen ,
getServiceHoursText ,
getStoreStatus
} from '@/config/serviceHours' ;
const OrderButton = () => {
const [ canOrder , setCanOrder ] = useState ( false );
useEffect (() => {
const checkAvailability = async () => {
const isOpen = await isServiceOpen ();
const status = getStoreStatus ();
setCanOrder ( isOpen && ! status . maintenanceMode );
};
checkAvailability ();
}, []);
return (
< button disabled = { ! canOrder } >
{ canOrder ? 'Place Order' : `Closed - ${ getServiceHoursText () } ` }
</ button >
);
};