diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2008-11-06 18:59:15 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2008-11-06 18:59:15 +0000 |
commit | 4869b91bc33e374b89302a35de39e458d631d2ae (patch) | |
tree | 3baaaf1d88b56c1813814b06460143881aa34553 | |
parent | caf05a86f3e95a7a008cd3171e88e5e55dd234d6 (diff) |
* luci/modules/admin-{core,mini,full}: implement new zoneinfo in system models
3 files changed, 41 insertions, 28 deletions
diff --git a/modules/admin-core/root/lib/uci/schema/default/system b/modules/admin-core/root/lib/uci/schema/default/system index 6ce96e573a..28fee1c2e1 100644 --- a/modules/admin-core/root/lib/uci/schema/default/system +++ b/modules/admin-core/root/lib/uci/schema/default/system @@ -18,6 +18,11 @@ config variable option required true config variable + option name 'zonename' + option title 'Option zonename' + option section 'system.system' + +config variable option name 'timezone' option title 'Option timezone' option section 'system.system' diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/system.lua b/modules/admin-full/luasrc/model/cbi/admin_system/system.lua index e0e2b1cbce..9820cceb2c 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_system/system.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_system/system.lua @@ -11,8 +11,9 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.http.protocol.date") + require("luci.sys") +require("luci.sys.zoneinfo") require("luci.tools.webadmin") m = Map("system", translate("system"), translate("a_s_desc")) @@ -48,17 +49,22 @@ s:option(DummyValue, "_uptime", translate("m_i_uptime")).value = s:option(Value, "hostname", translate("hostname")) -tz = s:option(Value, "timezone", translate("timezone")) -for k, offset in luci.util.vspairs(luci.http.protocol.date.TZ) do - local zone = k:upper() - local osgn = (offset >= 0 and "" or "+") - local ohrs = math.floor(-offset / 3600) - local omin = (offset % 3600) / 60 - - local ptz = zone .. osgn .. (ohrs ~= 0 and ohrs or "") .. (omin ~= 0 and ":" .. omin or "") - local dtz = string.format("%+03d:%02d ", ohrs, omin) .. zone - - tz:value(ptz, dtz) +tz = s:option(ListValue, "zonename", translate("timezone")) +tz:value("UTC") + +for i, zone in ipairs(luci.sys.zoneinfo.TZ) do + tz:value(zone[1]) +end + +function tz.write(self, section, value) + local function lookup_zone(title) + for _, zone in ipairs(luci.sys.zoneinfo.TZ) do + if zone[1] == title then return zone[2] end + end + end + + AbstractValue.write(self, section, value) + self.map.uci:set("system", section, "timezone", lookup_zone(value) or "GMT0") end s:option(Value, "log_size", nil, "kiB").optional = true diff --git a/modules/admin-mini/luasrc/model/cbi/mini/system.lua b/modules/admin-mini/luasrc/model/cbi/mini/system.lua index a1ed1282cf..5c06a0fbeb 100644 --- a/modules/admin-mini/luasrc/model/cbi/mini/system.lua +++ b/modules/admin-mini/luasrc/model/cbi/mini/system.lua @@ -11,8 +11,9 @@ You may obtain a copy of the License at $Id$ ]]-- -require("luci.http.protocol.date") + require("luci.sys") +require("luci.sys.zoneinfo") require("luci.tools.webadmin") @@ -49,23 +50,24 @@ s:option(DummyValue, "_systime", translate("m_i_systemtime")).value = s:option(DummyValue, "_uptime", translate("m_i_uptime")).value = luci.tools.webadmin.date_format(tonumber(uptime)) - - - - s:option(Value, "hostname", translate("hostname")) -tz = s:option(Value, "timezone", translate("timezone")) -for k, offset in luci.util.vspairs(luci.http.protocol.date.TZ) do - local zone = k:upper() - local osgn = (offset >= 0 and "" or "+") - local ohrs = math.floor(-offset / 3600) - local omin = (offset % 3600) / 60 - - local ptz = zone .. osgn .. (ohrs ~= 0 and ohrs or "") .. (omin ~= 0 and ":" .. omin or "") - local dtz = string.format("%+03d:%02d ", ohrs, omin) .. zone - - tz:value(ptz, dtz) +tz = s:option(ListValue, "zonename", translate("timezone")) +tz:value("UTC") + +for i, zone in ipairs(luci.sys.zoneinfo.TZ) do + tz:value(zone[1]) +end + +function tz.write(self, section, value) + local function lookup_zone(title) + for _, zone in ipairs(luci.sys.zoneinfo.TZ) do + if zone[1] == title then return zone[2] end + end + end + + AbstractValue.write(self, section, value) + self.map.uci:set("system", section, "timezone", lookup_zone(value) or "GMT0") end return m |