def adapt(self, value): """ Adapt `value` to a `datetime.datetime` instance. :param value: A date-like value. RFC3339 formatted date-strings are supported. If `dateutil` is installed, `dateutil.parser.parse` is used which supports many date formats. """ try: return super(DateTimeField, self).adapt(value) except TypeError: if isinstance(value, basestring): return date_parse(value) raise
def test_rfc3339(): """ Assure that RFC3339 formatting is working. Warning: This test could get different results depending on if pytz and dateutil is installed. """ n = utcnow() offset = n.tzinfo.utcoffset(n) assert offset == timedelta(0) str = generate_rfc3339(n) assert 'T' in str assert str.endswith('Z') dt = date_parse(str) # `generate_rfc3339` does not convert microseconds so we can't compare them odt = n.replace(microsecond=0) assert dt == odt