diff --git a/api/Application.cfm b/api/Application.cfm index 2ae7d83..a8e0c2f 100644 --- a/api/Application.cfm +++ b/api/Application.cfm @@ -84,6 +84,35 @@ function toISO8601(d) { return dateTimeFormat(utc, "yyyy-MM-dd'T'HH:nn:ss") & "Z"; } +// Get current time in a specific timezone (returns "HH:mm:ss" string) +// Used for schedule filtering (menu availability, business hours) +function getTimeInZone(tz) { + if (isNull(tz) || !len(trim(tz))) tz = "America/Los_Angeles"; + try { + var zoneId = createObject("java", "java.time.ZoneId").of(tz); + var zonedNow = createObject("java", "java.time.ZonedDateTime").now(zoneId); + var formatter = createObject("java", "java.time.format.DateTimeFormatter").ofPattern("HH:mm:ss"); + return zonedNow.format(formatter); + } catch (any e) { + // Fallback to server time if timezone is invalid + return timeFormat(now(), "HH:mm:ss"); + } +} + +// Get current day of week in a specific timezone (returns 1-7, Sunday=1) +function getDayInZone(tz) { + if (isNull(tz) || !len(trim(tz))) tz = "America/Los_Angeles"; + try { + var zoneId = createObject("java", "java.time.ZoneId").of(tz); + var zonedNow = createObject("java", "java.time.ZonedDateTime").now(zoneId); + // Java DayOfWeek: Monday=1, Sunday=7. Convert to CFML: Sunday=1, Monday=2... + var javaDow = zonedNow.getDayOfWeek().getValue(); + return (javaDow mod 7) + 1; // Convert: Mon=2, Tue=3, ..., Sat=7, Sun=1 + } catch (any e) { + return dayOfWeek(now()); + } +} + // Determine request path request._api_scriptName = ""; if (structKeyExists(cgi, "SCRIPT_NAME")) { diff --git a/api/menu/getForBuilder.cfm b/api/menu/getForBuilder.cfm index f728dd4..b92f7f8 100644 --- a/api/menu/getForBuilder.cfm +++ b/api/menu/getForBuilder.cfm @@ -60,13 +60,15 @@ try { // Check for MenuID filter (optional - if provided, only return categories for that menu) menuID = structKeyExists(requestData, "MenuID") ? val(requestData.MenuID) : 0; - // Get business's default menu setting + // Get business's default menu setting and timezone defaultMenuID = 0; + businessTimezone = "America/Los_Angeles"; try { - qBiz = queryTimed("SELECT DefaultMenuID FROM Businesses WHERE ID = :businessID", + qBiz = queryTimed("SELECT DefaultMenuID, Timezone FROM Businesses WHERE ID = :businessID", { businessID: businessID }, { datasource: "payfrit" }); - if (qBiz.recordCount > 0 && !isNull(qBiz.DefaultMenuID)) { - defaultMenuID = val(qBiz.DefaultMenuID); + if (qBiz.recordCount > 0) { + if (!isNull(qBiz.DefaultMenuID)) defaultMenuID = val(qBiz.DefaultMenuID); + if (!isNull(qBiz.Timezone) && len(trim(qBiz.Timezone))) businessTimezone = qBiz.Timezone; } } catch (any e) {} @@ -95,9 +97,9 @@ try { // Auto-select menu based on current time when no specific menu requested if (menuID == 0 && qMenus.recordCount > 1) { - now = timeFormat(now(), "HH:mm"); - dayOfWeek = dayOfWeek(now()); // 1=Sun, 2=Mon, ... 7=Sat - dayBit = 2 ^ (dayOfWeek - 1); // bitmask: 1=Sun, 2=Mon, 4=Tue, etc. + currentTime = left(getTimeInZone(businessTimezone), 5); // "HH:mm" + currentDay = getDayInZone(businessTimezone); // 1=Sun, 2=Mon, ... 7=Sat + dayBit = 2 ^ (currentDay - 1); // bitmask: 1=Sun, 2=Mon, 4=Tue, etc. activeMenuIds = []; for (m = 1; m <= qMenus.recordCount; m++) { @@ -111,7 +113,7 @@ try { if (hasStart && hasEnd) { startT = timeFormat(qMenus.StartTime[m], "HH:mm"); endT = timeFormat(qMenus.EndTime[m], "HH:mm"); - if (now >= startT && now <= endT) { + if (currentTime >= startT && currentTime <= endT) { arrayAppend(activeMenuIds, qMenus.ID[m]); } } else { diff --git a/api/menu/items.cfm b/api/menu/items.cfm index c7610d5..3e42797 100644 --- a/api/menu/items.cfm +++ b/api/menu/items.cfm @@ -48,9 +48,23 @@ - - - + + + + + + + + + + + + +