Method Deck / timezones

Convert a time between fixed UTC offsets

Converts a wall-clock time and date from one fixed UTC offset to another, handling the date rollover if any.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Parse date and time into a day-number (Hinnant days_from_civil, cited above) and seconds-since-midnight.
  2. Parse from_offset and to_offset as signed HH:MM offsets from UTC, in seconds.
  3. utc_seconds_total = day_number * 86400 + local_seconds - from_offset_seconds.
  4. target_seconds_total = utc_seconds_total + to_offset_seconds.
  5. result_day_number = floor(target_seconds_total / 86400); seconds_into_day = target_seconds_total - result_day_number * 86400.
  6. Convert result_day_number back to a civil date (civil_from_days) and seconds_into_day back to HH:MM:SS.
  7. day_shift = result_day_number - original_day_number.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"date":"2026-09-30","time":"23:30:00","from_offset":"-05:00","to_offset":"+01:00"}2026-10-01 05:30:00 (+1 day)
test vector: rolls to the previous day{"date":"2026-01-01","time":"00:15:00","from_offset":"+09:00","to_offset":"-08:00"}2025-12-31 07:15:00 (-1 day)
test vector: same day, no rollover{"date":"2026-06-15","time":"10:00:00","from_offset":"+00:00","to_offset":"+02:00"}2026-06-15 12:00:00 (same day)

Published card