Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions edge-apps/edge-apps-library/src/utils/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ function isValidLocale(locale: string): boolean {
/**
* Resolve timezone configuration with fallback chain
* Fallback order: override setting (validated) → GPS-based detection → 'UTC'
*
* @param latitude - Optional latitude coordinate (overrides metadata coordinates)
* @param longitude - Optional longitude coordinate (overrides metadata coordinates)
*/
export async function getTimeZone(): Promise<string> {
export async function getTimeZone(
latitude?: number,
longitude?: number,
): Promise<string> {
// Priority 1: Use override setting if provided and valid
const overrideTimezone = getSettingWithDefault<string>(
'override_timezone',
Expand All @@ -83,8 +89,12 @@ export async function getTimeZone(): Promise<string> {
}

try {
const [latitude, longitude] = getMetadata().coordinates
return tzlookup(latitude, longitude)
// Use provided coordinates or fall back to metadata coordinates
const [lat, lng] =
latitude !== undefined && longitude !== undefined
? [latitude, longitude]
: getMetadata().coordinates
return tzlookup(lat, lng)
} catch (error) {
console.warn('Failed to get timezone from coordinates, using UTC:', error)
return 'UTC'
Expand Down