mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
util.dataforms: Turn number values into timestamps for datetime fields
Makes it symmetric with parsing.
This commit is contained in:
parent
fc677f515f
commit
f956b07ca0
2 changed files with 4 additions and 2 deletions
|
@ -461,7 +461,7 @@ describe("util.dataforms", function ()
|
|||
local f = dataforms.new { { name = "when"; type = "text-single"; datatype = "xs:dateTime" } } -- luacheck: ignore 431
|
||||
|
||||
it("works", function ()
|
||||
local x = f:form({ when = "2008-08-22T21:09:00Z" });
|
||||
local x = f:form({ when = 1219439340 });
|
||||
assert.equal("2008-08-22T21:09:00Z", x:find("field/value#"))
|
||||
local d, e = f:data(x);
|
||||
assert.is_nil(e);
|
||||
|
|
|
@ -103,7 +103,9 @@ function form_t.form(layout, data, formtype)
|
|||
|
||||
if value ~= nil then
|
||||
if type(value) == "number" then
|
||||
if field_type == "boolean" then
|
||||
if field.datatype == "xs:dateTime" then
|
||||
value = datetime.datetime(value);
|
||||
elseif field_type == "boolean" then
|
||||
value = value ~= 0;
|
||||
else
|
||||
value = ("%g"):format(value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue