date_utils.py — Date Engine and Power BI Calendar
BCHPR · all projects · 2023 – present
5,220 lines handling the dates that actually arrive: French month names from Francophone Cameroon, Excel serials, paper forms re-entered at the wrong precision, and REDCap fields whose _dmy suffix controls display only — the API returns ISO regardless, so a hand-exported Excel file parses differently from an API pull.
Highlights
- 47 parse formats across a priority / secondary / tertiary fallback chain, with an LRU cache on the scalar path.
- French months and ordinals (janvier, 1er) mapped to English before parsing, so a date resolves identically on a fr_FR workstation and a C-locale cron host.
- Excel's phantom 1900 leap day handled explicitly rather than absorbed as an off-by-one.
- A documented inconsistency closed: parse_date defaulted month-first while safe_to_datetime defaulted day-first, so the same ambiguous string returned two different dates depending which function you called.
- Ordered fallback profiles for REDCap precision mismatches — a date-only value in a datetime field, or seconds data in a minute field — deliberately disabled for time-only types, where retrying as a date produces silent garbage.
- A 93-column Power BI date dimension with fiscal periods, Cameroon holidays, and tropical dry / rainy seasons.
- ISO week labels carry a two-digit year because Power BI's sort-by-column rejects a label that maps to two sort values — exactly what 29–31 December does.
Related projects
Data Manager
data_quality_manager.py — Data-Quality Engine
REDCap validates one field at a time, at entry. It cannot express “this specimen date precedes the enrolment date on a different form”, or “these two record IDs are the same participant”. This 14,274-line engine does, and it remembers — every issue it raises has an open date, a close date, and a resolution time.
Data Manager
MANAGER.py — Manager.io Accounting API Client
15,661-line Manager.io API client. Full create / update / delete across 18 document types — sales quotes, orders, invoices, credit notes, delivery notes and receipts; purchase quotes, orders, invoices and debit notes; inventory items, locations, transfers, write-offs, goods receipts, production orders and starting balances; and payments. Customers, suppliers, projects, accounts, assets and tax codes are exposed read-only.
Data Manager
data_utilities.py — Shared DataFrame Toolbox
The dependency root of the library — 9,746 lines that import nothing else in the codebase and that everything else imports. 84 public callables covering REDCap activity-log parsing, data-dictionary recoding, checkbox column expansion, export diffing, and file I/O that survives a SharePoint sync.