Offset in minutes to round (can be fractional)
Maximum distance (in minutes) from a valid timezone to accept. Defaults to Settings.maxValidOffsetMinutes.
Nearest valid offset in minutes, or undefined if too far from any valid timezone
// Exact matches
inferLikelyOffsetMinutes(480) // 480 (UTC+8, exact)
inferLikelyOffsetMinutes(-300) // -300 (UTC-5, exact)
// Rounding within default threshold (30 minutes)
inferLikelyOffsetMinutes(485) // 480 (UTC+8, rounded from 485)
inferLikelyOffsetMinutes(-295) // -300 (UTC-5, rounded from -295)
inferLikelyOffsetMinutes(330.5) // 330 (UTC+5:30, rounded)
// GPS-based inference with clock drift (within 30 min default)
const gpsTime = "2023:01:15 19:30:45" // UTC
const localTime = "2023:01:15 11:32:12" // Local with 1.5min drift
const deltaMinutes = 480 + 1.5 // ~481.5 minutes
inferLikelyOffsetMinutes(deltaMinutes) // 480 (UTC+8)
// GPS lag up to 23 minutes still works (within 30 min threshold)
inferLikelyOffsetMinutes(443) // 420 (UTC-7, ~23 min from actual)
// Beyond threshold returns undefined
inferLikelyOffsetMinutes(100) // undefined (not near any valid offset)
// Custom threshold
inferLikelyOffsetMinutes(495, 30) // 480 (UTC+8 with 30min threshold)
inferLikelyOffsetMinutes(495, 15) // undefined (beyond 15min threshold)
// Adjust global default
Settings.maxValidOffsetMinutes.value = 15 // Stricter matching
inferLikelyOffsetMinutes(443) // undefined (beyond 15min threshold)
Round an arbitrary offset to the nearest valid timezone offset.
This is error-tolerant timezone inference, useful for:
By default, uses Settings.maxValidOffsetMinutes (30 minutes) as the maximum distance from a valid timezone. This threshold handles GPS acquisition lag and clock drift while preventing false matches.
Respects Settings for archaic offsets, Baker Island time, and max offset tolerance.