diff --git a/internal/base/constant/constant.go b/internal/base/constant/constant.go index f467f157b..ae9e64303 100644 --- a/internal/base/constant/constant.go +++ b/internal/base/constant/constant.go @@ -29,3 +29,43 @@ var ( Revision = "" GoVersion = "" ) + +var Timezones = []string{ + // Americas + "America/New_York", + "America/Chicago", + "America/Los_Angeles", + "America/Toronto", + "America/Vancouver", + "America/Mexico_City", + "America/Sao_Paulo", + "America/Buenos_Aires", + + // Europe + "Europe/London", + "Europe/Paris", + "Europe/Berlin", + "Europe/Madrid", + "Europe/Rome", + "Europe/Moscow", + + // Asia + "Asia/Shanghai", + "Asia/Tokyo", + "Asia/Singapore", + "Asia/Dubai", + "Asia/Hong_Kong", + "Asia/Seoul", + "Asia/Bangkok", + "Asia/Kolkata", + + // Pacific + "Australia/Sydney", + "Australia/Melbourne", + "Pacific/Auckland", + + // Africa + "Africa/Cairo", + "Africa/Johannesburg", + "Africa/Lagos", +} diff --git a/internal/migrations/init.go b/internal/migrations/init.go index c07907e7a..b2c814e13 100644 --- a/internal/migrations/init.go +++ b/internal/migrations/init.go @@ -160,9 +160,28 @@ func (m *Mentor) initAdminUserRoleRel() { } func (m *Mentor) initSiteInfoInterface() { + now := time.Now() + zoneName, offset := now.In(time.Local).Zone() + + localTimezone := "UTC" + for _, tz := range constant.Timezones { + loc, err := time.LoadLocation(tz) + if err != nil { + continue + } + + tzNow := now.In(loc) + tzName, tzOffset := tzNow.Zone() + + if tzName == zoneName && tzOffset == offset { + localTimezone = tz + break + } + } + interfaceData := map[string]string{ "language": m.userData.Language, - "time_zone": "UTC", + "time_zone": localTimezone, } interfaceDataBytes, _ := json.Marshal(interfaceData) _, m.err = m.engine.Context(m.ctx).Insert(&entity.SiteInfo{ @@ -452,5 +471,4 @@ func (m *Mentor) initDefaultBadges() { return } } - return }