Documentation
¶
Overview ¶
Package timeutil provides centralized timezone handling for the application. Call LoadProcessLocation once during initialization to set the canonical timezone, then use Now() and Location() for business times and database values instead of time.Now() and time.Local. time.Now stays right for what no zone affects: durations, deadlines and Unix timestamps.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoadLocation ¶
LoadLocation loads the timezone by name (e.g., "Asia/Shanghai", "UTC"). Must be called once at startup before any other function in this package. An unknown name is an error and leaves the current timezone in place.
func LoadProcessLocation ¶ added in v1.21.0
LoadProcessLocation loads the timezone like LoadLocation and makes it the process's local timezone as well, so time.Now, time.Unix and every library reading time.Local (GORM's automatic timestamps among them) keep a single clock with Now. It matters for PostgreSQL: a zone-less timestamp column stores the written value's wall clock, so values written in two zones stop comparing. Call it once at startup, before other goroutines read the time.
func Location ¶
Location returns the canonical application timezone. Falls back to time.Local if LoadLocation was never called.
func LocationName ¶
func LocationName() string
LocationName returns the configured timezone name, or "Local" when LoadLocation was never called.
Types ¶
This section is empty.