meshflow.utility.forcing_prep.calculate_time_difference

meshflow.utility.forcing_prep.calculate_time_difference(initial_time_zone, target_time_zone)[source]

Calculate the time difference in hours between two IANA time zones.

Parameters:
  • initial_time_zone (str) – IANA time zone name (e.g., ‘America/Toronto’).

  • target_time_zone (str) – IANA time zone name (e.g., ‘UTC’, ‘Europe/London’).

Returns:

Time difference in hours between the two time zones. If the time zones are the same, returns 0.

Return type:

float or int

Raises:
  • AssertionError – If either time zone argument is not a string.

  • ValueError – If the time zone format is incorrect or not valid.

Notes

Time zone naming follows IANA conventions: https://data.iana.org/time-zones/releases/tzdb-2025b.tar.lz

Examples

>>> calculate_time_difference('UTC', 'America/Toronto')
-4.0
>>> calculate_time_difference('America/Edmonton', 'America/Toronto')
2.0