Commit 8c211bee authored by Nicolas Delaby's avatar Nicolas Delaby

Compute timestamp only if value is defined


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44294 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d2f4ea62
...@@ -1570,17 +1570,18 @@ class DateTimeWidget(Widget): ...@@ -1570,17 +1570,18 @@ class DateTimeWidget(Widget):
if not value and field.get_value('default_now'): if not value and field.get_value('default_now'):
value = DateTime() value = DateTime()
text_node = Element('{%s}%s' % (TEXT_URI, local_name), nsmap=NSMAP) text_node = Element('{%s}%s' % (TEXT_URI, local_name), nsmap=NSMAP)
# http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dateTime if value:
attr_dict['{%s}date-value' % OFFICE_URI] = value.ISO8601() # http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dateTime
# According http://wiki.services.openoffice.org/wiki/Documentation/How_Tos/Calc:_Date_%26_Time_functions attr_dict['{%s}date-value' % OFFICE_URI] = value.ISO8601()
# default offset is 30/12/1899 # According http://wiki.services.openoffice.org/wiki/Documentation/How_Tos/Calc:_Date_%26_Time_functions
number_of_second_in_day = 86400 #24 * 60 * 60 # default offset is 30/12/1899
timestamp = float(value) number_of_second_in_day = 86400 #24 * 60 * 60
# XXX Works only if the timezone is the same in OpenOffice timestamp = float(value)
ooo_offset_timestamp = float(DateTime(1899, 12, 30)) # XXX Works only if the timezone is the same in OpenOffice
days_value = (timestamp - ooo_offset_timestamp) / number_of_second_in_day ooo_offset_timestamp = float(DateTime(1899, 12, 30))
attr_dict['{%s}formula' % TEXT_URI] = 'ooow:%f' % days_value days_value = (timestamp - ooo_offset_timestamp) / number_of_second_in_day
text_node.attrib.update(attr_dict) attr_dict['{%s}formula' % TEXT_URI] = 'ooow:%f' % days_value
text_node.attrib.update(attr_dict)
if as_string: if as_string:
return etree.tostring(text_node) return etree.tostring(text_node)
return text_node return text_node
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment