Skip to main content

Overview

The service hours configuration controls when your water delivery service is available to accept orders. This system supports different hours for weekdays and weekends, special closed dates, and can be overridden remotely via Edge Config.
Service hours can be configured both locally in src/config/serviceHours.js and remotely via Edge Config.

Configuration File

The service hours are defined in src/config/serviceHours.js:4-27.

Configuration Options

startHour
number
default:"8"
Service start hour in 24-hour format (0-23)
startMinute
number
default:"30"
Service start minute (0-59)
endHour
number
default:"20"
Service end hour in 24-hour format (0-23)
endMinute
number
default:"30"
Service end minute (0-59)
weekdaysEnabled
boolean
default:"true"
Enable service on weekdays (Monday-Friday)
weekendsEnabled
boolean
default:"true"
Enable service on weekends (Saturday-Sunday)
closedDates
array
default:"[]"
Array of dates when service is closed, in YYYY-MM-DD formatExample: ['2024-01-01', '2024-12-25']
testMode
boolean
default:"false"
When enabled, service is always considered open regardless of time checks
Only use test mode in development environments. Never enable in production.

Usage Examples

Checking Service Status

src/config/serviceHours.js
import { isServiceOpen, getServiceHoursText } from '@/config/serviceHours';

// Check if service is currently open
const open = await isServiceOpen();
if (!open) {
  console.log('Service is currently closed');
}

// Get formatted service hours text
const hours = getServiceHoursText(); // Returns "08:30 - 20:30"

Getting Active Configuration

import { getActiveServiceHours, getStoreStatus } from '@/config/serviceHours';

// Get current service hours (includes Edge Config overrides)
const serviceHours = getActiveServiceHours();
console.log(serviceHours);
// {
//   startHour: 8,
//   startMinute: 30,
//   endHour: 20,
//   endMinute: 30,
//   weekdaysEnabled: true,
//   weekendsEnabled: true,
//   closedDates: [],
//   testMode: false
// }

// Check store status
const status = getStoreStatus();
console.log(status);
// {
//   isOpen: true,
//   temporarilyClosed: false,
//   maintenanceMode: false,
//   reason: ""
// }

Getting Next Service Time

src/config/serviceHours.js
import { getNextServiceTime } from '@/config/serviceHours';

const nextOpen = getNextServiceTime();
if (nextOpen) {
  console.log(`Service opens next at: ${nextOpen.toLocaleString()}`);
}

Configuration Examples

Standard Business Hours

src/config/serviceHours.js
export const DEFAULT_SERVICE_HOURS = {
  startHour: 8,
  startMinute: 30,
  endHour: 20,
  endMinute: 30,
  weekdaysEnabled: true,
  weekendsEnabled: true,
  closedDates: [],
  testMode: false
};

Weekdays Only

src/config/serviceHours.js
export const DEFAULT_SERVICE_HOURS = {
  startHour: 9,
  startMinute: 0,
  endHour: 18,
  endMinute: 0,
  weekdaysEnabled: true,
  weekendsEnabled: false, // No weekend service
  closedDates: [],
  testMode: false
};

With Holiday Closures

src/config/serviceHours.js
export const DEFAULT_SERVICE_HOURS = {
  startHour: 8,
  startMinute: 0,
  endHour: 22,
  endMinute: 0,
  weekdaysEnabled: true,
  weekendsEnabled: true,
  closedDates: [
    '2024-01-01', // New Year's Day
    '2024-04-23', // National Sovereignty Day
    '2024-05-01', // Labour Day
    '2024-10-29', // Republic Day
  ],
  testMode: false
};

How It Works

The service hours system follows this logic (see src/config/serviceHours.js:74-117):
1

Load Edge Config

First, the system loads any remote configuration from Edge Config that may override local settings.
2

Check Store Status

If the store is manually closed, temporarily closed, or in maintenance mode, return false immediately.
3

Check Test Mode

If test mode is enabled, return true (always open).
4

Check Closed Dates

Compare current date against the closedDates array. If today is in the list, return false.
5

Check Day of Week

Verify if service is enabled for the current day (weekday vs weekend).
6

Check Time Range

Finally, check if current time is within the configured start and end times.

Store Status Control

In addition to time-based rules, service can be controlled via store status flags:
storeStatus.isOpen
boolean
default:"true"
Master switch for the entire store
storeStatus.temporarilyClosed
boolean
default:"false"
Temporarily close the store (e.g., during emergencies)
storeStatus.maintenanceMode
boolean
default:"false"
Enable maintenance mode to prevent all orders
storeStatus.reason
string
default:""
Optional reason for closure (displayed to customers)
Store status can be controlled remotely via Edge Config without deploying code changes. See Edge Config for details.

Build docs developers (and LLMs) love