Action flows: use company timezone for Inspection Time conditionals
Objective
- Make Action Flow condition evaluation use each company’s Settings → Company → Timezone (IANA, e.g.
America/New_York) instead of silently defaulting to Denver (America/Denver). - Fix Inspection Time rules (e.g. overnight windows like 7:00 PM–7:30 AM on Job Confirmed) so Eastern and other non-Mountain companies get correct send/filter behavior.
- Align action-flow time-of-day logic with worklists and the Action Flow UI, which already assume company local time when admins configure conditions.
Background
- Product need: run an action on order confirmation only when inspection time falls in an overnight window (example discussed: 7:00 PM–7:30 AM). That is supported via Job Confirmed + Inspection Time → is between, including overnight ranges when start > end.
- For an Eastern company, the rule can appear correct in the UI but fail or misfire at runtime because server-side evaluation uses Mountain Time.
- Root cause:
checkConditioninconditionsResolver.tscallsevalInspectionTimeCondition(condition, actualValue, undefined)— timezone is never passed, soinspectionTimeMatch.tsfalls back toINSPECTION_TIME_TZ_FALLBACK(America/Denver). - Contrast (working today): Worklists pass
res.locals.company?.timezoneintobuildInspectionTimeMongoMatchinworklist.ts. Action flow send windows inflowEventTriggerer.tsandhandleFlowStart.tsalready load company timezone for delay/window math — only inspection-time conditionals are out of sync. - UI vs runtime mismatch: The condition builder in
ValueConditionInput.tsxuses sessionuseTimezone()(company tz fromtools/layout.tsx); admins configure times in local company time, but BullMQ execution pathhandleEventTriggerdByBull.ts→evaluateConditionsdoes not. - Company schema default timezone is also
America/Denver(companySchema.ts) when unset — separate from this bug, but Eastern companies must have timezone saved correctly for any path that reads it.
Scope
Backend
attik-backend/src/util/functions/actionFlows/conditionsResolver.ts—inspection-timebranch passesundefinedtimezone intoevalInspectionTimeCondition; all callers ofevaluateConditions/checkConditionfor flows (e.g.handleEventTriggerdByBull.ts,handleActionFlowTrigger.ts,flowOnJob.ts, email/SMS render paths) need company IANA tz available when evaluating time-of-day rules.attik-backend/src/util/functions/worklist/inspectionTimeMatch.ts— sharedevalInspectionTimeCondition,parseBetweenHhMm, overnighttime_betweenlogic; worklist path already accepts timezone.attik-backend/src/util/functions/actionFlows/FullPopulatedDataForFlow.ts— inspection payload for flow actions includes_companyId; timezone likely resolved viaCompany(same pattern asflowEventTriggerer.tscompany lookup).attik-backend/src/models/companySchema.ts—timezonefield (defaultAmerica/Denver).attik-backend/tests/unit/worklist.inspectionTimeMatch.test.ts— existing tests for time_between and timezone; extend or add action-flow integration coverage.
Frontend
attik-frontend/src/components/conditions/ValueConditionInput.tsx— time pickers already labeled with company timezone viauseTimezone()/INSPECTION_TZ_FALLBACK.attik-frontend/src/components/conditions/templatingData.ts—inspection-timecondition key (conditionType: 'timeOfDay').attik-frontend/src/app/tools/action-flow/[flow_id]/ActionDrawer.tsx— action-level Conditionals for events likeconfirmed_job.- No UI change strictly required if backend matches company tz; decision needed whether to surface evaluated timezone in flow debug/history for support.
Product / decisions for implementer
- Decision needed: Resolve timezone from flow
_companyId, inspection_companyId, or thread explicit tz throughevaluateConditions— follow existing worklist / send-window patterns. - Decision needed: Whether to use
inspection.property.timeZonewhen present vs company setting only (inspection-time today usesinspection.datetimeonly). - Out of scope unless requested: Changing global
America/Denverschema default onCompany; fixing unrelated datetime condition types that may not pass tz today.
Investigation outcomes (acceptance)
- [ ] Inspection Time conditions on Action Flow actions (e.g. Job Confirmed +
time_betweenovernight) evaluate using the company’s configured timezone. - [ ] Eastern company (
America/New_York): inspection at 8:00 PM local matches “after 7:00 PM” / overnight window; same job does not match when evaluated in Denver-only fallback. - [ ] Worklist behavior unchanged (still uses company timezone).
- [ ] Unit or integration test covers action-flow evaluation with non-Denver company timezone.
- [ ] Document or verify: company timezone must be set in Settings (not left on default) for correct local behavior.
References
attik-backend/src/util/functions/actionFlows/conditionsResolver.tsattik-backend/src/util/functions/worklist/inspectionTimeMatch.tsattik-backend/src/routes/worklist.tsattik-backend/src/util/functions/actionFlows/handleEventTriggerdByBull.tsattik-backend/src/util/functions/actionFlows/flowEventTriggerer.tsattik-frontend/src/components/conditions/ValueConditionInput.tsxattik-backend/tests/unit/worklist.inspectionTimeMatch.test.ts
Status: Completed
Log in to comment and vote
No comments yet
Be the first to share your thoughts.