summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/luasrc
diff options
context:
space:
mode:
authorDaniel Dickinson <openwrt@daniel.thecshore.com>2015-12-01 23:43:18 -0500
committerDaniel Dickinson <openwrt@daniel.thecshore.com>2015-12-14 23:26:26 -0500
commit6318f67fd46450b501879d9cf36c023fab7824d3 (patch)
treeff6cbc20ed5f55a2c48ccaa9cea0248e4b943563 /modules/luci-base/luasrc
parent63155e99325d2f7b57eee99496648e7a3cf6c14b (diff)
luci-base: Add time and data datatypes for use with firewall app
Adding LuCI configuation of the firewall time and data uci options is in progress and this adds the necessary datatypes for validating those fields.
Diffstat (limited to 'modules/luci-base/luasrc')
-rw-r--r--modules/luci-base/luasrc/cbi/datatypes.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/modules/luci-base/luasrc/cbi/datatypes.lua b/modules/luci-base/luasrc/cbi/datatypes.lua
index 52f90afee..4c003be2a 100644
--- a/modules/luci-base/luasrc/cbi/datatypes.lua
+++ b/modules/luci-base/luasrc/cbi/datatypes.lua
@@ -341,3 +341,48 @@ end
function phonedigit(val)
return (val:match("^[0-9\*#!%.]+$") ~= nil)
end
+
+function timehhmmss(val)
+ return (val:match("^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$") ~= nil)
+end
+
+function dateyyyymmdd(val)
+ if val ~= nil then
+ yearstr, monthstr, daystr = val:match("^(%d%d%d%d)-(%d%d)-(%d%d)$")
+ if (yearstr == nil) or (monthstr == nil) or (daystr == nil) then
+ return false;
+ end
+ year = tonumber(yearstr)
+ month = tonumber(monthstr)
+ day = tonumber(daystr)
+ if (year == nil) or (month == nil) or (day == nil) then
+ return false;
+ end
+
+ local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+
+ local function is_leap_year(year)
+ return (year % 4 == 0) and ((year % 100 ~= 0) or (year % 400 == 0))
+ end
+
+ function get_days_in_month(month, year)
+ if (month == 2) and is_leap_year(year) then
+ return 29
+ else
+ return days_in_month[month]
+ end
+ end
+ if (year < 2015) then
+ return false
+ end
+ if ((month == 0) or (month > 12)) then
+ return false
+ end
+ if ((day == 0) or (day > get_days_in_month(month, year))) then
+ return false
+ end
+ return true
+ end
+ return false
+end
+