Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed #18969 -- Added test for year lookups with year < 1000 #841

Closed
wants to merge 1 commit into from

1 participant

Florian Hahn
Florian Hahn

Thanks Tomas Ehrlich for the test

  • added test for year lookup
  • updated queryset documentation, __year, __month, __day, __week_day, __hour, __minute, __second take a string as well

Patch for 18969

Florian Hahn fhahn Fixed #18969 -- Added test for year lookups with year < 1000
Thanks Tomas Ehrlich for the test

- added test for year lookup
- updated queryset documentation, __year, __month, __day, __week_day,
  __hour, __minute, __second take a string as well
421ff12
Florian Hahn

ticket was closed as duplicat, created new pull request with correct ticket number #847

Florian Hahn fhahn closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 24, 2013
  1. Florian Hahn

    Fixed #18969 -- Added test for year lookups with year < 1000

    fhahn authored
    Thanks Tomas Ehrlich for the test
    
    - added test for year lookup
    - updated queryset documentation, __year, __month, __day, __week_day,
      __hour, __minute, __second take a string as well
This page is out of date. Refresh to see the latest.
28 docs/ref/models/querysets.txt
View
@@ -2064,11 +2064,13 @@ numbers and even characters.
year
~~~~
-For date and datetime fields, an exact year match. Takes an integer year.
+For date and datetime fields, an exact year match. Takes a year as integer or
+string
Example::
Entry.objects.filter(pub_date__year=2005)
+ Entry.objects.filter(pub_date__year='2005')
SQL equivalent::
@@ -2084,12 +2086,13 @@ current time zone before filtering.
month
~~~~~
-For date and datetime fields, an exact month match. Takes an integer 1
-(January) through 12 (December).
+For date and datetime fields, an exact month match. Takes a month as
+integer or string from 1 (January) through 12 (December).
Example::
Entry.objects.filter(pub_date__month=12)
+ Entry.objects.filter(pub_date__month='12')
SQL equivalent::
@@ -2105,11 +2108,13 @@ current time zone before filtering.
day
~~~
-For date and datetime fields, an exact day match. Takes an integer day.
+For date and datetime fields, an exact day match. Takes a day of the month
+as integer or string.
Example::
Entry.objects.filter(pub_date__day=3)
+ Entry.objects.filter(pub_date__day='3')
SQL equivalent::
@@ -2130,12 +2135,13 @@ week_day
For date and datetime fields, a 'day of the week' match.
-Takes an integer value representing the day of week from 1 (Sunday) to 7
+Takes an integer or string value representing the day of week from 1 (Sunday) to 7
(Saturday).
Example::
Entry.objects.filter(pub_date__week_day=2)
+ Entry.objects.filter(pub_date__week_day='2')
(No equivalent SQL code fragment is included for this lookup because
implementation of the relevant query varies among different database engines.)
@@ -2154,11 +2160,13 @@ hour
.. versionadded:: 1.6
-For datetime fields, an exact hour match. Takes an integer between 0 and 23.
+For datetime fields, an exact hour match. Takes an integer or string between
+0 and 23.
Example::
Event.objects.filter(timestamp__hour=23)
+ Event.objects.filter(timestamp__hour='23')
SQL equivalent::
@@ -2176,11 +2184,13 @@ minute
.. versionadded:: 1.6
-For datetime fields, an exact minute match. Takes an integer between 0 and 59.
+For datetime fields, an exact minute match. Takes an integer or string between
+0 and 59.
Example::
Event.objects.filter(timestamp__minute=29)
+ Event.objects.filter(timestamp__minute='29')
SQL equivalent::
@@ -2198,11 +2208,13 @@ second
.. versionadded:: 1.6
-For datetime fields, an exact second match. Takes an integer between 0 and 59.
+For datetime fields, an exact second match. Takes an integer or string between
+0 and 59.
Example::
Event.objects.filter(timestamp__second=31)
+ Event.objects.filter(timestamp__second='31')
SQL equivalent::
16 tests/regressiontests/model_regress/tests.py
View
@@ -57,6 +57,7 @@ def test_date_lookup(self):
Party.objects.create(when=datetime.datetime(1999, 12, 31))
Party.objects.create(when=datetime.datetime(1998, 12, 31))
Party.objects.create(when=datetime.datetime(1999, 1, 1))
+ Party.objects.create(when=datetime.datetime(1, 3, 3))
self.assertQuerysetEqual(
Party.objects.filter(when__month=2), []
)
@@ -104,6 +105,21 @@ def test_date_lookup(self):
attrgetter("when")
)
+ # Regression test for #18969
+ self.assertQuerysetEqual(
+ Party.objects.filter(when__year=1), [
+ datetime.date(1, 3, 3),
+ ],
+ attrgetter("when")
+ )
+ self.assertQuerysetEqual(
+ Party.objects.filter(when__year='1'), [
+ datetime.date(1, 3, 3),
+ ],
+ attrgetter("when")
+ )
+
+
def test_date_filter_null(self):
# Date filtering was failing with NULL date values in SQLite
# (regression test for #3501, amongst other things).
Something went wrong with that request. Please try again.