We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 5055382 + 37fc795 commit 261a8a9Copy full SHA for 261a8a9
pkg/timeutil/timeutil.go
@@ -0,0 +1,22 @@
1
+package timeutil
2
+
3
+import "time"
4
5
+// ToUTC returns a pointer to the same instant expressed in UTC.
6
+// Returns nil if t is nil.
7
+//
8
+// The go-sql-driver/mysql with loc=Local symmetrically converts on both
9
+// write (In(loc)) and read (parsed as loc), so the time.Time already
10
+// carries the correct instant; calling UTC() only normalises the zone.
11
+func ToUTC(t *time.Time) *time.Time {
12
+ if t == nil {
13
+ return nil
14
+ }
15
+ utc := t.UTC()
16
+ return &utc
17
+}
18
19
+// NowUTC returns the current time in UTC.
20
+func NowUTC() time.Time {
21
+ return time.Now().UTC()
22
0 commit comments