# HG changeset patch # User Kim Alvefur # Date 1635254269 -7200 # Node ID bf67060572839f0b488ed0917c8b688639d5c79f # Parent 593b141ba01cd933d92c66d94d22bcd4644d93d8 util.dataforms: Turn number values into timestamps for datetime fields Makes it symmetric with parsing. diff -r 593b141ba01c -r bf6706057283 spec/util_dataforms_spec.lua --- 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); diff -r 593b141ba01c -r bf6706057283 util/dataforms.lua --- 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);