question 206 Dates Numbers & Regex · medium
Fix the same-day dispatch cut-off
Orders placed before 17:00 local time in the warehouse's zone ship the same day. same_day_dispatch crashes with TypeError: can't compare offset-naive and offset-aware datetimes. Fix it so it answers correctly for any zone, all year.
Function
same_day_dispatch(placed_utc, cutoff_hour, zone_name)placed_utcISO text in UTC, like
2025-03-03T20:30:00ZReturns
True when the order was placed before cutoff_hour:00 on the warehouse clock that day, else FalseRulean order at exactly the cut-off misses it
Examples
callsame_day_dispatch('2025-03-03T20:30:00Z', 17, 'America/New_York')returnsTrue
callsame_day_dispatch('2025-03-03T22:30:00Z', 17, 'America/New_York')returnsFalse
callsame_day_dispatch('2025-03-04T03:00:00Z', 17, 'America/New_York')returnsFalse