Software /
code /
prosody
Comparison
core/moduleapi.lua @ 13206:7435a9341bb3
core.moduleapi: Turn negative periods or "never" into infinity
As a way to signal that the periodic thing should be disabled, matching
existing mod_mam usage
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 16 Jul 2023 21:01:31 +0200 |
parent | 13205:0ccd82b965d5 |
child | 13207:c563da1694bf |
comparison
equal
deleted
inserted
replaced
13205:0ccd82b965d5 | 13206:7435a9341bb3 |
---|---|
255 end | 255 end |
256 | 256 |
257 function api:get_option_period(name, default_value) | 257 function api:get_option_period(name, default_value) |
258 local value = self:get_option_scalar(name, default_value); | 258 local value = self:get_option_scalar(name, default_value); |
259 if type(value) == "number" then | 259 if type(value) == "number" then |
260 if value < 0 then | |
261 self:log("debug", "Treating negative period as infinity"); | |
262 return math.huge; | |
263 end | |
260 -- assume seconds | 264 -- assume seconds |
261 return value; | 265 return value; |
266 elseif value == "never" then | |
267 -- usually for disabling some periodic thing | |
268 return math.huge; | |
262 elseif type(value) == "string" then | 269 elseif type(value) == "string" then |
263 local ret = human_io.parse_duration(value); | 270 local ret = human_io.parse_duration(value); |
264 if value ~= nil and ret == nil then | 271 if value ~= nil and ret == nil then |
265 self:log("error", "Config option '%s' not understood, expecting a period (e.g. \"2 days\")", name); | 272 self:log("error", "Config option '%s' not understood, expecting a period (e.g. \"2 days\")", name); |
266 end | 273 end |