Software /
code /
prosody
Changeset
11878:bf6706057283
util.dataforms: Turn number values into timestamps for datetime fields
Makes it symmetric with parsing.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Oct 2021 15:17:49 +0200 |
parents | 11877:593b141ba01c |
children | 11879:b8b889ba8d27 |
files | spec/util_dataforms_spec.lua util/dataforms.lua |
diffstat | 2 files changed, 4 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_dataforms_spec.lua Tue Oct 26 15:15:57 2021 +0200 +++ b/spec/util_dataforms_spec.lua Tue Oct 26 15:17:49 2021 +0200 @@ -461,7 +461,7 @@ 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);
--- a/util/dataforms.lua Tue Oct 26 15:15:57 2021 +0200 +++ b/util/dataforms.lua Tue Oct 26 15:17:49 2021 +0200 @@ -103,7 +103,9 @@ 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);