Added ToClientTimezone() util func.
This commit is contained in:
parent
9e3a7fddcc
commit
afb3774646
21
pkg/util/util.go
Normal file
21
pkg/util/util.go
Normal file
@ -0,0 +1,21 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ToClientTimezone converts given time to timezone set in a
|
||||
// X-Client-Timezone header. If this header is not set, then
|
||||
// converts to UTC.
|
||||
func ToClientTimezone(t time.Time, r *http.Request) time.Time {
|
||||
if tz := r.Header.Get("X-Client-Timezone"); tz != "" {
|
||||
loc, err := time.LoadLocation(tz)
|
||||
if err != nil {
|
||||
return t.UTC()
|
||||
}
|
||||
return t.In(loc)
|
||||
}
|
||||
|
||||
return t.UTC()
|
||||
}
|
Loading…
Reference in New Issue
Block a user