weiro/models/users.go

32 lines
600 B
Go
Raw Normal View History

2026-02-19 10:21:27 +00:00
package models
import "time"
2026-02-19 10:21:27 +00:00
type User struct {
ID int64
Username string
PasswordHashed []byte
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
}