diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 4ae9a813fd..4a47997ae9 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -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): diff --git a/tests/regressiontests/datatypes/models.py b/tests/regressiontests/datatypes/models.py index ff9666bc0c..9ebb6402e2 100644 --- a/tests/regressiontests/datatypes/models.py +++ b/tests/regressiontests/datatypes/models.py @@ -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.objects.filter(baked_date__year=2006) +[] + +>>> Donut.objects.filter(consumed_at__year=2007).order_by('name') +[, ] + +>>> Donut.objects.filter(consumed_at__year=2006) +[] + +>>> Donut.objects.filter(consumed_at__year=2005) +[] + +>>> Donut.objects.filter(consumed_at__year=2008) +[] + """}