Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/timeutil/timeutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package timeutil

import "time"

// ToUTC returns a pointer to the same instant expressed in UTC.
// Returns nil if t is nil.
//
// The go-sql-driver/mysql with loc=Local symmetrically converts on both
// write (In(loc)) and read (parsed as loc), so the time.Time already
// carries the correct instant; calling UTC() only normalises the zone.
func ToUTC(t *time.Time) *time.Time {
if t == nil {
return nil
}
utc := t.UTC()
return &utc
}

// NowUTC returns the current time in UTC.
func NowUTC() time.Time {
return time.Now().UTC()
}