Diff

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
line wrap: on
line diff
--- a/util/dataforms.lua	Mon Oct 25 21:45:06 2021 +0200
+++ b/util/dataforms.lua	Mon Oct 25 21:45:46 2021 +0200
@@ -14,6 +14,7 @@
 local t_concat = table.concat;
 local st = require "util.stanza";
 local jid_prep = require "util.jid".prep;
+local datetime = require "util.datetime";
 
 local _ENV = nil;
 -- luacheck: std none
@@ -321,6 +322,13 @@
 		end
 	end
 
+data_validators["xs:dateTime"] =
+	function(data, field) -- luacheck: ignore 212/field
+		local n = datetime.parse(data);
+		if not n then return false, "invalid timestamp"; end
+		return true, n;
+	end
+
 
 local function get_form_type(form)
 	if not st.is_stanza(form) then