Predict the output
What do the two lines print?
from collections.abc import Callable
from datetime import UTC, datetime, timedelta
def is_expired(issued: datetime,
now: Callable[[], datetime]) -> bool:
return now() - issued > timedelta(minutes=15)
issued = datetime(2026, 10, 31, 12, 0, tzinfo=UTC)
print(is_expired(issued, lambda: issued + timedelta(minutes=10)))
print(is_expired(issued, lambda: issued + timedelta(minutes=16)))Hint 1 of 1
Compare each delta with 15 minutes.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A False then True
Correct. 10 minutes is inside 15; 16 is past it.
Passing the clock in as a function lets a test choose 'now' exactly. 10 minutes is under the 15-minute limit and 16 is over, with no sleeps or real time involved.
Why not the others?
- B
TruethenTrue. 10 minutes hasn't expired. - C
FalsethenFalse. 16 minutes exceeds 15. - D A timezone error. Both datetimes are UTC-aware.