mirror of https://github.com/django/django.git
Fixed #3689, #5223 -- Fixed "1st of January" comparisons for SQLite without breaking the other backends.
Based on a patch from raminf and tests from Nebojsa Djordjevic. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7150 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c1f45c326c
commit
32402773f1
|
@ -228,7 +228,11 @@ class Field(object):
|
|||
value = int(value)
|
||||
except ValueError:
|
||||
raise ValueError("The __year lookup type requires an integer argument")
|
||||
return ['%s-01-01 00:00:00' % value, '%s-12-31 23:59:59.999999' % value]
|
||||
if settings.DATABASE_ENGINE == 'sqlite3':
|
||||
first = '%s-01-01'
|
||||
else:
|
||||
first = '%s-01-01 00:00:00'
|
||||
return [first % value, '%s-12-31 23:59:59.999999' % value]
|
||||
raise TypeError("Field has invalid lookup: %s" % lookup_type)
|
||||
|
||||
def has_default(self):
|
||||
|
|
|
@ -56,4 +56,30 @@ datetime.date(1938, 6, 4)
|
|||
datetime.time(5, 30)
|
||||
>>> d3.consumed_at
|
||||
datetime.datetime(2007, 4, 20, 16, 19, 59)
|
||||
|
||||
# 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.save()
|
||||
>>> d1 = Donut(name='Date Test 2006', baked_date=datetime.datetime(year=2006, month=1, day=1), consumed_at=datetime.datetime(year=2006, month=1, day=1))
|
||||
>>> d1.save()
|
||||
|
||||
>>> Donut.objects.filter(baked_date__year=2007)
|
||||
[<Donut: Date Test 2007>]
|
||||
|
||||
>>> Donut.objects.filter(baked_date__year=2006)
|
||||
[<Donut: Date Test 2006>]
|
||||
|
||||
>>> Donut.objects.filter(consumed_at__year=2007).order_by('name')
|
||||
[<Donut: Apple Fritter>, <Donut: Date Test 2007>]
|
||||
|
||||
>>> Donut.objects.filter(consumed_at__year=2006)
|
||||
[<Donut: Date Test 2006>]
|
||||
|
||||
>>> Donut.objects.filter(consumed_at__year=2005)
|
||||
[]
|
||||
|
||||
>>> Donut.objects.filter(consumed_at__year=2008)
|
||||
[]
|
||||
|
||||
"""}
|
||||
|
|
Loading…
Reference in New Issue