Added ToClientTimezone() function to convert time to client's local time.
This commit is contained in:
parent
a21a361167
commit
6f152673f2
@ -1,6 +1,10 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// MainSite returns homepage address depending on network used.
|
||||
func MainSite(host string) string {
|
||||
@ -12,3 +16,18 @@ func MainSite(host string) string {
|
||||
|
||||
return "https://arav.top"
|
||||
}
|
||||
|
||||
// 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)
|
||||
} else {
|
||||
return t.UTC()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user