Skip to main content

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
Promise<boolean>
Returns true if service is open, false if closed
Behavior
  • 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"
returns
string
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
Date | null
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();
returns
Promise<void>
Async function that updates ACTIVE_SERVICE_HOURS and STORE_STATUS
Side Effects
  • 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
returns
object
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}`);
}
returns
object
Store status object

Configuration

DEFAULT_SERVICE_HOURS

Default service hours configuration object.
import { DEFAULT_SERVICE_HOURS } from '@/config/serviceHours';

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>
  );
};

Build docs developers (and LLMs) love