mirror of
https://github.com/cuigh/swirl
synced 2024-12-28 14:51:57 +00:00
Use predefined time zones
This commit is contained in:
parent
10fcc1452c
commit
62ede94143
@ -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)
|
||||
|
32
misc/misc.go
32
misc/misc.go
@ -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
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user