Reference
referenceConverts the local month boundaries to UTC instants and compares against them.
07 · Statements
Select a month's transactions using midnight in the account's own time zone, converted to UTC.
referenceConverts the local month boundaries to UTC instants and compares against them.
alt_validSelects via local calendar membership rather than comparing UTC interval bounds.
wrong_fixed_offsetKeeps a standard-time offset throughout the year.
wrong_offset_signAdds each local boundary's UTC offset instead of subtracting it when computing the UTC interval.
wrong_utc_monthUses UTC calendar months for every account.
no_id_tiebreakExpect: rejectObserved: rejectedSorts tied timestamps by input order, violating the lexicographic id tie-break.
validates_only_selectedExpect: rejectObserved: rejectedValidates only selected timestamps, violating validation even outside the selected month.
tzinfo_only_aware_checkExpect: rejectObserved: rejectedChecks only tzinfo presence, violating the requirement for a non-None utcoffset.
Each row groups a test’s parameterized cases; any failing case marks the row as Fail. * marks a wrong solution’s declared must_fail test.
| Test | Starter | Reference | Alternative | fixed offset | offset sign | utc month |
|---|---|---|---|---|---|---|
| Local midnight boundaries | Fail | Pass | Pass | Pass | Fail * | Fail * |
| Microsecond boundary | Pass | Pass | Pass | Pass | Pass | Pass |
| Dst months | Fail | Pass | Pass | Fail * | Fail * | Fail |
| Naive and instant order | Fail | Pass | Pass | Pass | Pass | Pass |
| Non none tzinfo with no offset is naive | Pass | Pass | Pass | Pass | Pass | Pass |
| Thirteen month partition | Pass | Pass | Pass | Pass | Pass | Pass |
| Invalid zone month or year raises | Fail | Pass | Pass | Pass | Pass | Pass |
| Supported year range edges | Pass | Pass | Pass | Pass | Pass | Pass |
| Test | Starter | Reference | Alternative | fixed offset | offset sign | utc month |
|---|---|---|---|---|---|---|
| Midmonth utc | Pass | Pass | Pass | Pass | Pass | Pass |
| Ticket worked example toronto january | Fail | Pass | Pass | Pass | Fail | Fail |
| Naive timestamp rejected | Pass | Pass | Pass | Pass | Pass | Pass |
statements.period.period_bounds(account_tz:str,year:int,month:int)->tuple[datetime,datetime] returns aware UTC instants for a half-open interval. select(txns:list[Txn],account_tz,year,month) returns transaction ids sorted by instant, then lexicographic id. Frozen Txn(id:str,at:datetime) is public. IDs are unique and timestamps may have arbitrary aware offsets and microseconds.
The period is the calendar month in the account's IANA timezone: local 00:00 on day 1 inclusive through local 00:00 on day 1 of the next month exclusive, converted to UTC using zoneinfo. An unknown time zone name, a non-int (or bool) year or month, a month outside 1-12 or a year outside 1900-2098 raises ValueError from both functions. Daylight saving rules apply independently to both endpoints. Each input timestamp must be aware with a non-None utcoffset, otherwise select raises ValueError, even when that transaction would be outside the month. Do not mutate inputs. Empty input returns []. Money is not part of this interface.
Worked example: for an America/Toronto account, January 2026 is the interval [2026-01-01T05:00:00Z, 2026-02-01T05:00:00Z) (Toronto is UTC-5 in January). A transaction at 2026-02-01T04:30:00Z is 23:30 on 31 January in Toronto, so it belongs to January; one at 2026-02-01T05:30:00Z is 00:30 on 1 February and belongs to February. So selecting January 2026 for Txn("a", 2026-02-01T04:30Z) and Txn("b", 2026-02-01T05:30Z) returns ["a"].
Run from starter: python -m pytest tests -q. The records are entirely synthetic.