units

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package units provides shared constants and validation for speed units

Index

Constants

View Source
const (
	MPS  = "mps"
	MPH  = "mph"
	KMPH = "kmph"
	KPH  = "kph"
)

Unit constants

Variables

View Source
var CommonTimezones = []string{
	"Pacific/Niue",
	"America/Adak",
	"Pacific/Honolulu",
	"Pacific/Marquesas",
	"America/Anchorage",
	"Pacific/Gambier",
	"America/Los_Angeles",
	"Pacific/Pitcairn",
	"America/Denver",
	"America/Phoenix",
	"America/Chicago",
	"America/Mexico_City",
	"America/New_York",
	"America/Lima",
	"America/Barbados",
	"America/Santiago",
	"America/St_Johns",
	"America/Miquelon",
	"America/Sao_Paulo",
	"America/Godthab",
	"Atlantic/South_Georgia",
	"Atlantic/Azores",
	"Atlantic/Cape_Verde",
	"UTC",
	"Africa/Abidjan",
	"Europe/Dublin",
	"Antarctica/Troll",
	"Africa/Lagos",
	"Europe/Berlin",
	"Africa/Johannesburg",
	"Europe/Athens",
	"Africa/Nairobi",
	"Asia/Tehran",
	"Asia/Dubai",
	"Asia/Kabul",
	"Asia/Karachi",
	"Asia/Kolkata",
	"Asia/Kathmandu",
	"Asia/Dhaka",
	"Asia/Yangon",
	"Asia/Bangkok",
	"Asia/Singapore",
	"Australia/Eucla",
	"Asia/Seoul",
	"Australia/Darwin",
	"Australia/Adelaide",
	"Australia/Brisbane",
	"Australia/Sydney",
	"Australia/Lord_Howe",
	"Pacific/Bougainville",
	"Pacific/Norfolk",
	"Pacific/Fiji",
	"Pacific/Auckland",
	"Pacific/Chatham",
	"Pacific/Apia",
	"Pacific/Kiritimati",
}

CommonTimezones contains a curated list of commonly used timezones from the tz database Each timezone represents a unique STD/DST offset pair to avoid redundancy These are verified to exist in the system's tz database Total unique offset pairs: 55 (covering all possible timezones globally) Ordered from west to east: -11:00 (Niue) to +14:00 (Kiritimati)

View Source
var ValidUnits = []string{MPS, MPH, KMPH, KPH}

ValidUnits contains all valid unit values

Functions

func ConvertSpeed

func ConvertSpeed(speedMPS float64, targetUnits string) float64

ConvertSpeed converts a speed from meters per second to the target units Database stores speeds in m/s (meters per second)

func ConvertTime

func ConvertTime(utcTime time.Time, targetTimezone string) (time.Time, error)

ConvertTime converts a UTC time to the specified timezone Database stores all times in UTC, this function converts them for display

func ConvertToMPS

func ConvertToMPS(speed float64, fromUnits string) float64

ConvertToMPS converts a speed value in the provided units to meters per second. If the unit is unknown, it returns the input value unchanged.

func GetTimezoneLabel

func GetTimezoneLabel(tz string) string

GetTimezoneLabel returns a human-readable label for the timezone Labels include the offset(s) to make it clear which timezone is which Ordered from west to east: -11:00 (Niue) to +14:00 (Kiritimati)

func GetValidTimezonesString

func GetValidTimezonesString() string

GetValidTimezonesString returns a comma-separated string of common timezones for error messages

func GetValidUnitsString

func GetValidUnitsString() string

GetValidUnitsString returns a comma-separated string of valid units for error messages

func IsCommonTimezone

func IsCommonTimezone(tz string) bool

IsCommonTimezone checks if the given timezone is in our curated list of common timezones

func IsTimezoneValid

func IsTimezoneValid(tz string) bool

IsTimezoneValid checks if the given timezone is valid by attempting to load it from the tz database This validates against the actual system tz database rather than a hardcoded list

func IsValid

func IsValid(unit string) bool

IsValid checks if the given unit is in the list of valid units

Types

This section is empty.

Jump to

Keyboard shortcuts

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