tzconvert

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertRangeLocalToUTC

func ConvertRangeLocalToUTC(startLocal, endLocal float64, utcOffset int) (utcStart, utcEnd float64)

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

func ConvertRangeUTCToLocal(startUTC, endUTC float64, utcOffset int) (localStart, localEnd float64)

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

func LocalToUTC(localHour float64, utcOffset int) float64

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

func ParseTimezoneOffset(timezone string) int

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

func UTCToLocal(utcHour float64, utcOffset int) float64

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL