aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-24 12:18:47 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-02-24 12:18:47 +0000
commit67f8d8fccd3403450f6652fdd67a4db37112a592 (patch)
tree2a2599d24fecfd568e73a0a747efe7ea008762f4 /lualib
parent7e62a09e0ba8645cd03dfed3e381a7f00d571683 (diff)
downloadrspamd-67f8d8fccd3403450f6652fdd67a4db37112a592.tar.gz
rspamd-67f8d8fccd3403450f6652fdd67a4db37112a592.zip
[Minor] Add docs and weeks suffix for parse_time_interval
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_util.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 4b2498e61..fb9fab0a4 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -271,6 +271,15 @@ end
exports.disable_module = disable_module
+
+--[[[
+-- @function lua_util.parse_time_interval(str)
+-- Parses human readable time interval
+-- Accepts 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days,
+-- 'w' for weeks, 'y' for years
+-- @param {string} str input string
+-- @return {number|nil} parsed interval as seconds (might be fractional)
+--]]
local function parse_time_interval(str)
local function parse_time_suffix(s)
if s == 's' then
@@ -281,6 +290,8 @@ local function parse_time_interval(str)
return 3600
elseif s == 'd' then
return 86400
+ elseif s == 'w' then
+ return 86400 * 7
elseif s == 'y' then
return 365 * 86400;
end
@@ -300,7 +311,7 @@ local function parse_time_interval(str)
(lpeg.S("+-") * parser.fractional)
parser.time = lpeg.Cf(lpeg.Cc(1) *
(parser.number / tonumber) *
- ((lpeg.S("smhdy") / parse_time_suffix) ^ -1),
+ ((lpeg.S("smhdwy") / parse_time_suffix) ^ -1),
function (acc, val) return acc * val end)
local t = lpeg.match(parser.time, str)