package utils import ( "time" ) // UserLocation resolves an IANA timezone name to a *time.Location, falling // back to UTC for empty or invalid values. The single resolution point for // server-side display conversion: the server owns timezone rendering, so // clients receive display-ready strings (or tz-aware instants) and never // convert themselves. func UserLocation(timezone string) *time.Location { if timezone == "" { return time.UTC } loc, err := time.LoadLocation(timezone) if err != nil || loc == nil { return time.UTC } return loc } // FormatTimeInTimezone renders t in the given IANA timezone as // MM-DD-YYYY HH:MM AM/PM (the established display format across the // templates). Zero times render empty. func FormatTimeInTimezone(t time.Time, timezone string) string { if t.IsZero() { return "" } return t.In(UserLocation(timezone)).Format("01-02-2006 03:04 PM") }