Dates and money
The two kinds of value that punish carelessness hardest. Dates have timezones, month lengths and a calendar that refuses to be arithmetic; money has cents that must not evaporate into floating point. Both turn up in almost every application, and both have a right way that is barely harder than the wrong one.
—Exercises
8 exercises
Days between two dates
date.fromisoformat, timedelta
~15 min
Cents into something readable
divmod on negatives, format specs
~15 min
Read 1h30m as seconds
finditer, consuming the whole string
~25 min
Three minutes ago
ladder of thresholds, rounding a duration
~24 min
Split money without losing a cent
integer cents, divmod
~20 min
Add months to a date
calendar arithmetic, divmod for wrapping
~30 min
Counting the days that count
weekday(), inclusive ranges
~26 min
Collapsing the bookings that touch
sort then sweep, comparing against the last kept item
~26 min