Skip to content

Commit 261a8a9

Browse files
authored
Merge pull request #587 from actiontech/fix-company-notice
fix: extract time util functions to pkg/timeutil for company notice timezone handling
2 parents 5055382 + 37fc795 commit 261a8a9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pkg/timeutil/timeutil.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)