Check if a Time value falls within business hours (09:00 to 17:00).
← Operators and Expressions · Ref: Q1205
EK9 Time supports the 'is in' operator with a range for clean boundary checks. Use named constants for the boundaries.
NAMED BOUNDARIES
businessStart <- 09:00 businessEnd <- 17:00
RANGE CHECK
if currentTime is in businessStart ... businessEnd stdout.println("Within business hours")
The 'is in start ... end' syntax is inclusive on both ends. It works with any comparable type: Time, Date, Integer, Float, etc. Named constants avoid magic literals and make the range self-documenting.
See Q1102 for is in with ranges. See Q1187 for time comparison. See Q1184 for named constants.
Example
defines module qa.operators.timerangecheck defines program TimeRangeCheckDemo() stdout <- Stdout() // === NAMED TIME BOUNDARIES === businessStart <- 09:00 businessEnd <- 17:00 // === WITHIN BUSINESS HOURS === morningMeeting <- 10:30 if morningMeeting is in businessStart ... businessEnd stdout.println(`${morningMeeting} is within business hours`) // === OUTSIDE BUSINESS HOURS === earlyCall <- 07:45 if not (earlyCall is in businessStart ... businessEnd) stdout.println(`${earlyCall} is outside business hours`) // === ON THE BOUNDARY (INCLUSIVE) === nineSharp <- 09:00 fivePm <- 17:00 startInRange <- nineSharp is in businessStart ... businessEnd endInRange <- fivePm is in businessStart ... businessEnd stdout.println(`09:00 in range: ${startInRange}`) stdout.println(`17:00 in range: ${endInRange}`) // === MULTIPLE TIME CHECKS === times <- [08:00, 09:30, 12:00, 16:45, 18:30] for checkTime in times if checkTime is in businessStart ... businessEnd stdout.println(`${checkTime}: office hours`) else stdout.println(`${checkTime}: after hours`)
Other ways to ask this
- Validate that a time is between start and end of business using is in.
- I need to determine whether a meeting time falls within office hours.
- In Java I'd check time.isAfter(start) && time.isBefore(end). What is the EK9 equivalent?
- Given named time boundaries, check if a current time is within the range.
Coming from another language?
Java: !time.isBefore(start) && !time.isAfter(end) — two method calls, easy to get wrong. Python: start <= t <= end — chained comparison. Rust: (start..=end).contains(&t). Go: !t.Before(start) && !t.After(end). EK9: time is in start ... end — one readable expression, inclusive bounds.
Keywords: is in, schedule, boundary, range, business hours, time, check, inclusive, named constant, validate