Comparison

util/dataforms.lua @ 11874:84f4c6957d62

util.dataforms: Add support for datetime field types via XEP-0122
author Kim Alvefur <zash@zash.se>
date Mon, 25 Oct 2021 21:45:46 +0200
parent 11630:855b065d5fd6
child 11877:593b141ba01c
comparison
equal deleted inserted replaced
11873:2b85e4e7d389 11874:84f4c6957d62
12 local tonumber = tonumber; 12 local tonumber = tonumber;
13 local tostring = tostring; 13 local tostring = tostring;
14 local t_concat = table.concat; 14 local t_concat = table.concat;
15 local st = require "util.stanza"; 15 local st = require "util.stanza";
16 local jid_prep = require "util.jid".prep; 16 local jid_prep = require "util.jid".prep;
17 local datetime = require "util.datetime";
17 18
18 local _ENV = nil; 19 local _ENV = nil;
19 -- luacheck: std none 20 -- luacheck: std none
20 21
21 local xmlns_forms = 'jabber:x:data'; 22 local xmlns_forms = 'jabber:x:data';
319 else 320 else
320 return data_validators["xs:integer"](data, field); 321 return data_validators["xs:integer"](data, field);
321 end 322 end
322 end 323 end
323 324
325 data_validators["xs:dateTime"] =
326 function(data, field) -- luacheck: ignore 212/field
327 local n = datetime.parse(data);
328 if not n then return false, "invalid timestamp"; end
329 return true, n;
330 end
331
324 332
325 local function get_form_type(form) 333 local function get_form_type(form)
326 if not st.is_stanza(form) then 334 if not st.is_stanza(form) then
327 return nil, "not a stanza object"; 335 return nil, "not a stanza object";
328 elseif form.attr.xmlns ~= "jabber:x:data" or form.name ~= "x" then 336 elseif form.attr.xmlns ~= "jabber:x:data" or form.name ~= "x" then