Use predefined time zones

This commit is contained in:
cuigh 2017-11-22 11:38:24 +08:00
parent 10fcc1452c
commit 62ede94143
3 changed files with 48 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package controller
import (
"github.com/cuigh/auxo/net/web"
"github.com/cuigh/swirl/biz"
"github.com/cuigh/swirl/misc"
"github.com/cuigh/swirl/model"
)
@ -26,7 +27,7 @@ func settingIndex(ctx web.Context) error {
return err
}
m := newModel(ctx).Set("Setting", setting)
m := newModel(ctx).Set("Setting", setting).Set("TimeZones", misc.TimeZones)
return ctx.Render("system/setting/index", m)
}
@ -34,6 +35,12 @@ func settingUpdate(ctx web.Context) error {
setting := &model.Setting{}
err := ctx.Bind(setting)
if err == nil {
for _, tz := range misc.TimeZones {
if tz.Name == setting.TimeZone.Name {
setting.TimeZone.Offset = tz.Offset
break
}
}
err = biz.Setting.Update(setting, ctx.User())
}
return ajaxResult(ctx, err)

View File

@ -13,6 +13,38 @@ const (
envDBAddress = "DB_ADDRESS"
)
// TimeZones holds some commonly used time-zones.
var TimeZones = []struct {
Name string
Offset int32 // seconds east of UTC
}{
{"GMT", 0},
{"GMT+12", 12 * 60 * 60},
{"GMT+11", 11 * 60 * 60},
{"GMT+10", 10 * 60 * 60},
{"GMT+9", 9 * 60 * 60},
{"GMT+8(Asia/Shanghai)", 8 * 60 * 60},
{"GMT+7", 7 * 60 * 60},
{"GMT+6", 6 * 60 * 60},
{"GMT+5", 5 * 60 * 60},
{"GMT+4", 4 * 60 * 60},
{"GMT+3", 3 * 60 * 60},
{"GMT+2", 2 * 60 * 60},
{"GMT+1", 1 * 60 * 60},
{"GMT-1", -1 * 60 * 60},
{"GMT-2", -2 * 60 * 60},
{"GMT-3", -3 * 60 * 60},
{"GMT-4", -4 * 60 * 60},
{"GMT-5", -5 * 60 * 60},
{"GMT-6", -6 * 60 * 60},
{"GMT-7", -7 * 60 * 60},
{"GMT-8", -8 * 60 * 60},
{"GMT-9", -9 * 60 * 60},
{"GMT-10", -10 * 60 * 60},
{"GMT-11", -11 * 60 * 60},
{"GMT-12", -12 * 60 * 60},
}
var Options = &struct {
DockerEndpoint string
DBType string

View File

@ -48,14 +48,18 @@
<div class="field-body">
<div class="field has-addons">
<div class="control has-icons-left">
<input name="tz.name" value="{{ .Setting.TimeZone.Name }}" class="input" type="text" placeholder="Location name">
<div class="select">
<select name="tz.name">
{{ offset := .Setting.TimeZone.Offset }}
{{ range .TimeZones }}
<option value="{{ .Name }}"{{ if offset == .Offset }} selected{{ end }}>{{ .Name }}</option>
{{ end }}
</select>
</div>
<div class="icon is-left">
<i class="fa fa-globe"></i>
</div>
</div>
<div class="control">
<input name="tz.offset" value="{{ .Setting.TimeZone.Offset }}" class="input" type="text" placeholder="Offset in seconds" data-type="integer">
</div>
</div>
</div>
</div>