Documentation
¶
Overview ¶
Package tzconvert provides foolproof timezone conversion utilities. ALL times in the codebase should be stored in UTC. These functions handle the conversion to/from local time for display only.
Index ¶
- func ConvertRangeLocalToUTC(startLocal, endLocal float64, utcOffset int) (utcStart, utcEnd float64)
- func ConvertRangeUTCToLocal(startUTC, endUTC float64, utcOffset int) (localStart, localEnd float64)
- func LocalToUTC(localHour float64, utcOffset int) float64
- func ParseTimezoneOffset(timezone string) int
- func UTCToLocal(utcHour float64, utcOffset int) float64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertRangeLocalToUTC ¶
ConvertRangeLocalToUTC converts a time range from local to UTC time. Handles ranges that may cross midnight.
Parameters:
- startLocal, endLocal: Start and end hours in local time
- utcOffset: The timezone offset from UTC
Returns: Start and end hours in UTC.
func ConvertRangeUTCToLocal ¶
ConvertRangeUTCToLocal converts a time range from UTC to local time. Handles ranges that may cross midnight.
Parameters:
- startUTC, endUTC: Start and end hours in UTC
- utcOffset: The timezone offset from UTC
Returns: Start and end hours in local time.
func LocalToUTC ¶
LocalToUTC converts a local hour to UTC given a UTC offset. Example: LocalToUTC(11.5, -4) converts 11:30 EDT to 15:30 UTC Example: LocalToUTC(10.0, 8) converts 10:00 CST to 02:00 UTC
Parameters:
- localHour: Hour in local time (0-24, can include fractional hours)
- utcOffset: The timezone offset from UTC (negative for west, positive for east)
Returns: UTC hour (0-24), properly wrapped for day boundaries.
func ParseTimezoneOffset ¶
ParseTimezoneOffset extracts the numeric offset from a timezone string. For IANA timezones, it uses Go's time package to get the current offset. Examples:
- "UTC-4" returns -4
- "UTC+8" returns 8
- "UTC" returns 0
- "America/New_York" returns -4 or -5 depending on DST
- "Pacific/Auckland" returns 12 or 13 depending on DST
- Invalid input returns 0
func UTCToLocal ¶
UTCToLocal converts a UTC hour to local hour given a UTC offset. Example: UTCToLocal(15.5, -4) converts 15:30 UTC to 11:30 EDT (UTC-4) Example: UTCToLocal(2.0, 8) converts 02:00 UTC to 10:00 CST (UTC+8)
Parameters:
- utcHour: Hour in UTC (0-24, can include fractional hours like 15.5 for 15:30)
- utcOffset: The timezone offset from UTC (negative for west, positive for east) Examples: -4 for EDT, -7 for PDT, 0 for GMT, 8 for CST (China)
Returns: Local hour (0-24), properly wrapped for day boundaries.
Types ¶
This section is empty.