Template:Category/Workshop itinerary/local-time
From Miniscope
Convert a UTC "HH:MM" time string to a local time string given an offset in hours. Used by Template:Category/Workshop itinerary/session-row to render SMW-normalized UTC times in the workshop's local timezone.
Why pure integer arithmetic on hours and minutes:
- PHP's strtotime doesn't reliably parse "HH:MM +N minutes" across
versions, so chained relative-time additions are flaky.
Error: Invalid time.formats in the server's
timezone, so a server in UTC and a server in PDT would render different output for the same input — silently broken.
- Extracting H and i from the input via
Error: Invalid time.
and Error: Invalid time. is round-trip safe regardless of
server TZ: parse and format both happen in the same zone.
Wraparound: adding 1440 (= 24 * 60) before mod 1440
ensures the result is non-negative for any reasonable offset
(−24 < hours < 24). So 02:00 with offset −4 yields 22:00
cleanly without sign issues in #expr's mod operator.
Why this template wraps verbose math: the formula is computed three times (h, m, m-padding) and would otherwise be inlined in the row template, ballooning every session row. Factoring it out keeps the row template legible.
Parameters:
time— UTC time asHH:MM; pass-through
unchanged when offset is empty
offset— hours from UTC (decimals OK for fractional
zones like 5.75 for Nepal); empty/0 returns the input unchanged