aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-07-16 20:59:27 +0200
committerKim Alvefur <zash@zash.se>2023-07-16 20:59:27 +0200
commit15a2cec870fad566a4519dbc12e05c0ddace2140 (patch)
tree52252e9415b3bf2052a5beb9ca424d24a3a53084
parent3c4dc9a7545791bb70f3a542eac910e6487e4ba4 (diff)
downloadprosody-15a2cec870fad566a4519dbc12e05c0ddace2140.tar.gz
prosody-15a2cec870fad566a4519dbc12e05c0ddace2140.zip
core.moduleapi: Improve handling of different types in :get_option_period
Pass positive numbers trough unharmed, parse strings as periods, discard anything else.
-rw-r--r--core/moduleapi.lua16
1 files changed, 8 insertions, 8 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 66652e09..88dd5b41 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -256,16 +256,16 @@ end
function api:get_option_period(name, default_value)
local value = self:get_option_scalar(name, default_value);
- local num = tonumber(value);
- if num then
+ if type(value) == "number" then
-- assume seconds
- return num;
- end
- local ret = human_io.parse_duration(value);
- if value ~= nil and ret == nil then
- self:log("error", "Config option '%s' not understood, expecting a period", name);
+ return value;
+ elseif type(value) == "string" then
+ local ret = human_io.parse_duration(value);
+ if value ~= nil and ret == nil then
+ self:log("error", "Config option '%s' not understood, expecting a period (e.g. \"2 days\")", name);
+ end
+ return ret;
end
- return ret;
end
function api:get_option_boolean(name, ...)