Skip to content

Commit

Permalink
Merge pull request #22 from senaite/datetime-converter
Browse files Browse the repository at this point in the history
Support datetime objects in date converter
  • Loading branch information
xispa authored Nov 29, 2021
2 parents 048053d + e0779d1 commit 03dc877
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.1.0 (unreleased)
------------------

- #22 Support datetime objects in date converter
- #21 Fix UnicodeEncodeError when exporting via CSV
- #20 Allow to retrieve column value with a Python expression
- #19 Fix columns and active-tab handling
Expand Down
10 changes: 7 additions & 3 deletions src/senaite/databox/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# Copyright 2018-2020 by it's authors.
# Some rights reserved, see README and LICENSE.

from datetime import datetime

import six

from bika.lims import api
Expand Down Expand Up @@ -56,9 +58,11 @@ def to_link(obj, key, value, **kw):
def to_date(obj, key, value, dfmt="%d.%m.%Y"):
"""to date
"""
if not isinstance(value, DateTime):
return ""
return DT2dt(value).strftime(dfmt)
if isinstance(value, DateTime):
return DT2dt(value).strftime(dfmt)
elif isinstance(value, datetime):
return value.strftime(dfmt)
return value


def to_long_date(obj, key, value, dfmt="%d.%m.%Y %H:%M"):
Expand Down

0 comments on commit 03dc877

Please sign in to comment.