diff --git a/CHANGES.txt b/CHANGES.txt index e2f41df..c4c1d36 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,11 +4,15 @@ Unreleased Bug Fixes ~~~~~~~~~ +- Time of "00:00" no longer gives ``colander.Invalid``. + - Un-break wrapping of callable instances as ``colander.deferred``. See https://github.com/Pylons/colander/issues/141. + - Set the max length TLD to 22 in ``Email`` validator based on the current list of valid TLDs. See https://github.com/Pylons/colander/issues/159 + - Fix an issue where ``drop`` was not recognized as a default and was returning the ``drop`` instance instead of omitting the value. https://github.com/Pylons/colander/issues/139 diff --git a/colander/__init__.py b/colander/__init__.py index 4104863..ab02e2a 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -1635,7 +1635,7 @@ class Time(SchemaType): This type serializes python ``datetime.time`` objects to a `ISO8601 `_ string format. - The format includes the date only. + The format includes the time only. The constructor accepts no arguments. @@ -1673,13 +1673,12 @@ class Time(SchemaType): err_template = _('Invalid time') def serialize(self, node, appstruct): - if not appstruct: - return null - if isinstance(appstruct, datetime.datetime): appstruct = appstruct.time() if not isinstance(appstruct, datetime.time): + if not appstruct: + return null raise Invalid(node, _('"${val}" is not a time object', mapping={'val':appstruct}) diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index bf6e6fc..fca4ab5 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -2257,6 +2257,15 @@ class TestTime(unittest.TestCase): expected = time.isoformat().split('.')[0] self.assertEqual(result, expected) + def test_serialize_with_zero_time(self): + import datetime + typ = self._makeOne() + time = datetime.time(0) + node = DummySchemaNode(None) + result = typ.serialize(node, time) + expected = time.isoformat().split('.')[0] + self.assertEqual(result, expected) + def test_serialize_with_datetime(self): typ = self._makeOne() dt = self._dt()