32 lines
1.3 KiB
Markdown
32 lines
1.3 KiB
Markdown
# Scripts
|
|
|
|
## generate_timezone_table.py
|
|
|
|
Generates `src/location/timezone_offsets.zig` with a lookup table mapping longitude to timezone offset.
|
|
|
|
**How it works:**
|
|
- Samples 360 longitudes (-180° to 179°) at 3 latitudes (0°, 30°N, 30°S)
|
|
- For each longitude, queries `timezonefinder` library for timezone at each latitude
|
|
- Uses the most common timezone offset across the 3 latitudes (handles political boundaries like China)
|
|
- Generates a `[360]i16` array with offsets in minutes from UTC
|
|
|
|
**Usage:**
|
|
```bash
|
|
./scripts/generate_timezone_table.py
|
|
```
|
|
|
|
**Requirements:**
|
|
- Uses `uv` with inline script dependencies (no manual installation needed)
|
|
- Takes ~10-20 seconds to generate
|
|
|
|
**Accuracy:**
|
|
- Works well for mid-latitudes (±30°) where most population lives
|
|
- Can be off by 1-2.5 hours at extreme latitudes (e.g., Russia vs Australia at same longitude)
|
|
- Acceptable for "morning/afternoon/evening/night" weather labels
|
|
- If higher accuracy is needed, modify `getTimezoneOffset()` to use latitude
|
|
|
|
**Why this approach:**
|
|
- O(1) lookup, no complex calculations at runtime
|
|
- Handles political boundaries (e.g., China's UTC+8 across all longitudes)
|
|
- Simple to regenerate with different latitude samples if needed
|
|
- API accepts `Coordinates` (not just longitude) for future improvements
|