Timezone Handling
HostMetrics has a two-tier timezone system because trip data and toll data come from different sources with different timezone behaviors.The Two Systems
1. Trip Data (UTC Storage)
| Aspect | Detail |
|---|---|
| Source | Turo CSV exports |
| Input timezone | Host’s local time (Turo exports in host’s market timezone) |
| Storage | timestamptz (UTC) in PostgreSQL |
| Display | Converted back to user’s configured timezone via formatDateTime() |
timestamptz columns, Postgres automatically converts them to UTC.
2. Toll Data (Local Storage)
| Aspect | Detail |
|---|---|
| Source | Toll agency CSVs or scraped data |
| Input timezone | Agency’s operating timezone (e.g., NTTA = CST) |
| Storage | Plain date + text columns (NOT timestamptz) |
| Display | Shown as-is (no conversion) |
The Business Timezone Setting
In Settings > Data Sources, hosts configure their business timezone (e.g.,America/Chicago).
This is NOT the user’s browser timezone — it’s “what timezone is my business in.”
| Scenario | Behavior |
|---|---|
| Dallas host in Dallas | CST. Trips and tolls align. |
| Dallas host traveling to NYC | Still CST. Data stays consistent. |
| Dallas host with NY tolls | Tolls in EST, trips in CST. Dates still match (within 1 day). |
Trip-to-Toll Date Matching
When matching tolls to trips (for reconciliation), both dates are compared asYYYY-MM-DD strings:
Critical Rule: Date Parsing
Display Formatting
Key Files
| File | Purpose |
|---|---|
src/lib/formatters.ts | formatDateTime() — UTC to local conversion |
src/lib/db/toll-transactions.ts | Toll date parsing (local components) |
src/app/api/tolls/sync/route.ts | Server-side toll date parsing |