2026-02-19 10:21:27 +00:00
|
|
|
package models
|
|
|
|
|
|
2026-02-24 11:21:26 +00:00
|
|
|
import "time"
|
|
|
|
|
|
2026-02-19 10:21:27 +00:00
|
|
|
type User struct {
|
|
|
|
|
ID int64
|
|
|
|
|
Username string
|
|
|
|
|
PasswordHashed []byte
|
2026-02-24 11:21:26 +00:00
|
|
|
TimeZone string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u User) FormatTime(t time.Time) string {
|
|
|
|
|
if loc := getLocation(u.TimeZone); loc != nil {
|
|
|
|
|
return t.In(loc).Format("2006-01-02 15:04:05")
|
|
|
|
|
}
|
|
|
|
|
return t.Format("2006-01-02 15:04:05")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var loadedLocation = map[string]*time.Location{}
|
|
|
|
|
|
|
|
|
|
func getLocation(tz string) *time.Location {
|
|
|
|
|
if loc, ok := loadedLocation[tz]; ok {
|
|
|
|
|
return loc
|
|
|
|
|
}
|
|
|
|
|
loc, err := time.LoadLocation(tz)
|
|
|
|
|
if err != nil {
|
|
|
|
|
loc = time.Local
|
|
|
|
|
}
|
|
|
|
|
loadedLocation[tz] = loc
|
|
|
|
|
return loc
|
2026-02-19 10:21:27 +00:00
|
|
|
}
|