1
0
dwelling-home/pkg/util/util.go

22 lines
425 B
Go

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()
}