mirror of https://github.com/django/django.git
Fixed #12059 - Let TimeField.to_python correctly return a datetime.time object when having a datetime object.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12137 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
00252d84d7
commit
b7236b8576
|
@ -1036,7 +1036,7 @@ class TimeField(Field):
|
||||||
# Not usually a good idea to pass in a datetime here (it loses
|
# Not usually a good idea to pass in a datetime here (it loses
|
||||||
# information), but this can be a side-effect of interacting with a
|
# information), but this can be a side-effect of interacting with a
|
||||||
# database backend (e.g. Oracle), so we'll be accommodating.
|
# database backend (e.g. Oracle), so we'll be accommodating.
|
||||||
return value.time
|
return value.time()
|
||||||
|
|
||||||
# Attempt to parse a datetime:
|
# Attempt to parse a datetime:
|
||||||
value = smart_str(value)
|
value = smart_str(value)
|
||||||
|
|
|
@ -58,6 +58,15 @@ datetime.time(5, 30)
|
||||||
>>> d3.consumed_at
|
>>> d3.consumed_at
|
||||||
datetime.datetime(2007, 4, 20, 16, 19, 59)
|
datetime.datetime(2007, 4, 20, 16, 19, 59)
|
||||||
|
|
||||||
|
# Test for ticket #12059: TimeField wrongly handling datetime.datetime object.
|
||||||
|
|
||||||
|
>>> d2.baked_time = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59)
|
||||||
|
>>> d2.save()
|
||||||
|
|
||||||
|
>>> d3 = Donut.objects.all()[0]
|
||||||
|
>>> d3.baked_time
|
||||||
|
datetime.time(16, 19, 59)
|
||||||
|
|
||||||
# Year boundary tests (ticket #3689)
|
# Year boundary tests (ticket #3689)
|
||||||
|
|
||||||
>>> d = Donut(name='Date Test 2007', baked_date=datetime.datetime(year=2007, month=12, day=31), consumed_at=datetime.datetime(year=2007, month=12, day=31, hour=23, minute=59, second=59))
|
>>> d = Donut(name='Date Test 2007', baked_date=datetime.datetime(year=2007, month=12, day=31), consumed_at=datetime.datetime(year=2007, month=12, day=31, hour=23, minute=59, second=59))
|
||||||
|
|
Loading…
Reference in New Issue