Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(install): auto set the default time zone to where the server is located #1304

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions internal/base/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
22 changes: 20 additions & 2 deletions internal/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -452,5 +471,4 @@ func (m *Mentor) initDefaultBadges() {
return
}
}
return
}