From 62ede9414344b2315f16079b686d58eef2aa90a2 Mon Sep 17 00:00:00 2001 From: cuigh Date: Wed, 22 Nov 2017 11:38:24 +0800 Subject: [PATCH] Use predefined time zones --- controller/setting.go | 9 ++++++++- misc/misc.go | 32 ++++++++++++++++++++++++++++++++ views/system/setting/index.jet | 12 ++++++++---- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/controller/setting.go b/controller/setting.go index c9a8e37..e73667f 100644 --- a/controller/setting.go +++ b/controller/setting.go @@ -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) diff --git a/misc/misc.go b/misc/misc.go index a3fec2c..cc5bc4a 100644 --- a/misc/misc.go +++ b/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 diff --git a/views/system/setting/index.jet b/views/system/setting/index.jet index 59a0ad0..abc39fd 100644 --- a/views/system/setting/index.jet +++ b/views/system/setting/index.jet @@ -48,14 +48,18 @@
- +
+ +
-
- -