spatie/google-time-zone
Convert GPS coordinates to a time zone using Google’s Time Zone API. Fetch DST and raw offsets plus timeZoneId and timeZoneName for any latitude/longitude. Works in any PHP project, with optional Laravel config publishing and auto-discovery.
timeZoneId, rawOffset, dstOffset, timeZoneName), enabling downstream use cases like:
Cache::remember). Can be extended via Laravel’s service providers or event system (e.g., TimeZoneUpdated events).Cache::forever() or database storage).GoogleTimeZone::getTimeZoneForCoordinates() for simplicity or inject the service directly for testing.TimeZoneResolved) for side effects (e.g., updating user profiles).Mockery or PHPUnit to stub Google’s API responses in tests.composer.json constraints).composer require spatie/google-time-zone..env (e.g., GOOGLE_TIMEZONE_API_KEY).app/Services/TimeZoneService) for abstraction.Cache::remember).coordinates_hash as a composite key).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Google API downtime | Time zones unavailable | Fallback to cached data or manual overrides. |
| API key quota exceeded | Requests fail | Implement retry logic with exponential backoff. |
| Invalid coordinates | Incorrect time zones | Validate inputs; log and alert on anomalies. |
| Time zone data staleness (e.g., DST) | Outdated time zones | Schedule cache invalidation; monitor updates. |
| High API latency | Slow UI responses | Cache responses; pre-fetch for known locations. |
How can I help you explore Laravel packages today?