Skip to Content
APIClassesClass: OpeningHoursHelper

Class: OpeningHoursHelper

Helper class for opening hours.

Constructors

Constructor

OpeningHoursHelper

Returns

OpeningHoursHelper

Methods

checkDayHasSchedule()

OpeningHours

Checks if a specific day has a schedule defined in the opening hours.

Parameters

openingHours

OpeningHours

An object containing the opening hours for each day of the week.

currentDate?

Date

Optional date to check against. If not provided, uses the current date.

Returns

boolean

true if the day has a schedule defined, false otherwise.

Example

Date

Default

Returns false if an error occurs or invalid opening hours are provided.


convertSingleTimeTo12Hour()

boolean

Converts a 24-hour time format to 12-hour format with AM/PM.

Parameters

time24h

string

The time string in 24-hour format (HH:mm).

Returns

string

Time formatted in 12-hour format with AM/PM.

Example

true

Default

false


flattenOpeningTimes()

false

Flattens an array of OpeningTime objects into a single OpeningTime object, taking the earliest open time and the latest close time.

Parameters

openingTimes

OpeningTime[]

The array of OpeningTime objects to flatten.

Returns

OpeningTime

A single OpeningTime object representing the flattened time range.

Example

string

Default

Returns { open: "00:00", close: "00:00" } if an error occurs or invalid array is provided.


formatCurrentDaySchedule()

string

Formats the opening hours for the current day into a string representation.

Parameters

openingHours

OpeningHours

The opening hours for the store.

Returns

string

A string representing the opening hours for the current day, or an empty string if there are no opening hours for today.

Example

OpeningTime

Default

OpeningTime


formatPreviousDaySchedule()

{ open: "00:00", close: "00:00" }

Formats the opening hours for the previous day into a string representation.

Parameters

openingHours

OpeningHours

The opening hours for the store.

Returns

string

A string representing the opening hours for the previous day, or an empty string if there are no opening hours for yesterday.

Example

OpeningHours

Default

string


formatTimeSchedule()

OpeningHours

Formats an opening time schedule into a readable string.

Parameters

openingTime

OpeningTime

The opening time object containing open and close times.

Returns

string

Formatted time schedule string.

Example

string

Default

OpeningTime


getDay()

string

Gets the day of the week as a two-character string indicator.

Parameters

date

Date

The Date object to extract the day from.

Returns

null | DaysOfTheWeek

A DaysOfTheWeek string representing the day of the week.

Example

Date

Default

null


getDayName()

DaysOfTheWeek

Gets the full day name (localized) for a given day string.

Parameters

day

string

The two-character day string (e.g., “mo”, “tu”).

Returns

string

The localized day name, or an empty string if the day is invalid.

Example

DaysOfTheWeek

Default

string


getDayNumber()

string

Gets the day number (1-7) for a given day string.

Parameters

day

string

The two-character day string (e.g., “mo”, “tu”).

Returns

number

The day number (1-7), or -1 if the day is invalid.

Example

string

Default

number


getDaysRange()

string

Converts an array of day abbreviations to a readable day range string.

Parameters

days

string[]

An array of day abbreviations (e.g., [“Mo”, “Tu”, “We”]).

Returns

string

A string representing the day range (e.g., “Monday - Wednesday” for consecutive days, or just “Monday” for a single day).

Example

string

Default

string


getNextClosestTime()

Date

Finds the next closest time from an array of time strings relative to the current date.

Parameters

times

string[]

An array of time strings in HH:mm format (e.g., [“09:00”, “14:30”, “18:00”]).

currentDate

Date

The current date and time to compare against.

Returns

string

The closest upcoming time string, or empty string if no times are provided.

Example

string

Default

OpeningHours


getNextSchedule()

Date

Gets the next schedule time (opening or closing) for a place in 12-hour format.

Parameters

openingHours

OpeningHours

An object containing the opening hours for each day of the week.

currentDate?

Date

Optional date to check against. If not provided, uses the current date.

Returns

string

The next schedule time in 12-hour format (e.g., “9:00 a.m.” or “6:00 p.m.”).

Example

string

Default

OpeningHours


hasOpeningHoursToday()

boolean

Checks if there are opening times defined for today.

Parameters

openingHours

OpeningHours

The opening hours of a store.

Returns

boolean

true if there are opening times for today, false otherwise.

Example

true

Default

Returns false if an error occurs or invalid opening hours are provided.


isOpenFromPreviousDay()

false

Checks if a store is open from the previous day (for overnight hours).

Parameters

openingHours

OpeningHours

The opening hours of the store.

currentDate?

Date

Optional date to check against. If not provided, uses the current date.

Returns

boolean

true if the store is open from the previous day, false otherwise.

Example

false

Default

Returns false if an error occurs or invalid opening hours are provided.


isPlaceOpen()

OpeningHours

Checks if a place is currently open based on its opening hours.

Parameters

openingHours

OpeningHours

An object containing the opening hours for each day of the week.

currentDate?

Date

Optional date to check against. If not provided, uses the current date.

Returns

boolean

true if the place is currently open, false otherwise.

Example

Date

Default

Returns false if an error occurs or invalid opening hours are provided.


isValidSchedule()

boolean

Checks if the current time is within the specified opening hours.

Parameters

openHour

string

The opening time in HH:mm format (e.g., “09:00”).

closeHour

string

The closing time in HH:mm format (e.g., “18:00”).

currentHour

string

The current time in HH:mm format (e.g., “14:30”).

Returns

boolean

true if the current time is within the opening hours, false otherwise.

Example

true

Default

Returns false if an error occurs or invalid time format is provided.


isValidTime()

false

Checks if a given string is a valid time in HH:mm format.

Parameters

time

string

The string to validate.

Returns

boolean

true if the string is a valid time, false otherwise.

Example

false

Default

Returns false if an error occurs or invalid time format is provided.


isWithinOpeningHours()

OpeningHours

Checks if the current time is within the opening hours defined for the current day.

Parameters

openingHours

OpeningHours

An object containing the opening hours for each day of the week.

currentDate?

Date

Optional date to check against. If not provided, uses the current date.

Returns

boolean

true if the current time is within the opening hours, false otherwise.

Example

Date

Default

Returns false if an error occurs or invalid opening hours are provided.


nextDate()

boolean

Modifies the given Date object to represent the next day.

Parameters

date

Date

The Date object to modify. This object will be mutated.

Returns

void

This function modifies the Date object in place and does not return a value.

Example

true


parseTimeAsDate()

false

Parses a time string (HH:mm) and combines it with a date to create a new Date object.

Parameters

time

string

The time string in HH:mm format (e.g., “14:30”).

date?

Date

An optional Date object to combine with the time. If not provided, the current date is used.

Returns

Date

A new Date object representing the combined date and time.

Example

false

Default

string


parseTimeToDate()

string

Parses a time string (HH:mm) and creates a Date object for today with that time.

Parameters

time

string

The time string in HH:mm format (e.g., “14:30”).

baseDate?

Date

Optional base date to use. If not provided, uses the current date.

Returns

Date

A Date object representing the date with the specified time.

Example

string

Default

boolean


previousDate()

true

Modifies the given Date object to represent the previous day.

Parameters

date

Date

The Date object to modify. This object will be mutated.

Returns

void

This function modifies the Date object in place and does not return a value.

Example

false


sortDays()

false

Sorts the opening hours object by day of the week.

Parameters

openingHours

OpeningHours

The opening hours object to sort.

Returns

Record<string, OpeningTime[]>

A new object with the opening hours sorted by day of the week.

Example

string

Default

boolean


sortOpeningTimesByOpen()

true

Sorts a list of OpeningTime objects in place, based on the ‘open’ property.

This method mutates the array and returns a reference to the same array.

Parameters

openingTimes

OpeningTime[]

The array of OpeningTime objects to sort. This array will be mutated.

Returns

OpeningTime[]

The sorted array of OpeningTime objects (mutated in place).

Example

false

Default

false


toMinutes()

OpeningHours

Converts a time string (HH:mm) to total minutes since midnight.

Parameters

time

string

The time string in HH:mm format (e.g., “14:30”).

Returns

number

The total number of minutes since midnight (e.g., 870 for “14:30”).

Example

Date

Default

boolean

Last updated on