How do I check if a meeting time is before noon in EK9?
← Operators and Expressions · Ref: Q1187
EK9 Time values use the same comparison operators as every other type. Write time literals as HH:MM or HH:MM:SS.
TIME LITERALS
meetingTime <- 09:30 noon <- 12:00 precise <- 14:30:45
COMPARISON
if meetingTime < noon check if before noon ordering <- meetingTime <=> noon negative = earlier, zero = same, positive = later
COALESCING
earlierTime <- meetingTime <? noon returns whichever is earlier
All comparison operators (< > <= >= == <> <=>) work identically on Time, Date, Integer, String, and any type that implements them.
See Q542 for full temporal comparison. See Q31 for Date and Time basics.
Example
#!ek9 defines module qa.operators.comparetimes defines function <?- Check if a time is before another time. -?> isBeforeTime() as pure -> check as Time against as Time <- rtn as Boolean: check < against <?- Compare two times and return spaceship ordering. -?> compareTimes() as pure -> left as Time right as Time <- rtn as Integer: left <=> right <?- Return the earlier of two times using coalescing min. -?> earlierOf() as pure -> left as Time right as Time <- rtn as Time: left <? right <?- Return the later of two times using coalescing max. -?> laterOf() as pure -> left as Time right as Time <- rtn as Time: left >? right defines program CompareTimesDemo() stdout <- Stdout() // === TIME LITERALS === meetingTime <- 09:30 noon <- 12:00 afternoon <- 14:30:45 // === IS THE MEETING BEFORE NOON? === isMorning <- isBeforeTime(meetingTime, noon) stdout.println(`Meeting is morning: ${isMorning}`) isAfternoonLater <- isBeforeTime(noon, afternoon) stdout.println(`Afternoon after noon: ${isAfternoonLater}`) // === SPACESHIP ORDERING VIA FUNCTION === ordering <- compareTimes(meetingTime, noon) stdout.println(`Meeting <=> noon: ${ordering}`) // === COALESCING: FIND EARLIEST AND LATEST === earlierTime <- earlierOf(meetingTime, noon) laterTime <- laterOf(meetingTime, noon) stdout.println(`Earlier: ${earlierTime}`) stdout.println(`Later: ${laterTime}`) // === SORTED TIME LIST VIA STREAM === times <- List() of Time times += afternoon times += meetingTime times += noon sorted <- cat times | sort | collect as List of Time stdout.println(`Sorted times: ${sorted}`) // === STRING AND ISSET === timeStr <- $meetingTime stdout.println(`Time string: ${timeStr}`) require meetingTime? unsetTime <- Time() require ~unsetTime?
Common mistakes
E50060 — Time has no isBefore() method; compare Time values directly with the < operator. See ek9 -h E50060 for details.
Incorrect:
<- rtn as Boolean: check.isBefore(against)
Correct:
<- rtn as Boolean: check < against
Other ways to ask this
- Compare two Time values to see which is earlier.
- I need to determine whether a scheduled time falls in the morning.
- In Python I compared datetime.time objects — how does EK9 handle this?
Coming from another language?
Java: LocalTime.isBefore(), compareTo(). Python: direct operators on datetime.time. Rust: PartialOrd on chrono::NaiveTime. Go: no built-in time-of-day type, use time.Time methods. EK9: direct < > == operators on Time literals, consistent with all types.
Keywords: afternoon, before, clock, compare, morning, noon, operator, temporal, time