Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Showing 1 unique commit by 1 author.

Feb 24, 2013
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
This page is out of date. Refresh to see the latest.
28 docs/ref/models/querysets.txt
@@ -2064,11 +2064,13 @@ numbers and even characters.
2064 2064 year
2065 2065 ~~~~
2066 2066
2067   -For date and datetime fields, an exact year match. Takes an integer year.
  2067 +For date and datetime fields, an exact year match. Takes a year as integer or
  2068 +string
2068 2069
2069 2070 Example::
2070 2071
2071 2072 Entry.objects.filter(pub_date__year=2005)
  2073 + Entry.objects.filter(pub_date__year='2005')
2072 2074
2073 2075 SQL equivalent::
2074 2076
@@ -2084,12 +2086,13 @@ current time zone before filtering.
2084 2086 month
2085 2087 ~~~~~
2086 2088
2087   -For date and datetime fields, an exact month match. Takes an integer 1
2088   -(January) through 12 (December).
  2089 +For date and datetime fields, an exact month match. Takes a month as
  2090 +integer or string from 1 (January) through 12 (December).
2089 2091
2090 2092 Example::
2091 2093
2092 2094 Entry.objects.filter(pub_date__month=12)
  2095 + Entry.objects.filter(pub_date__month='12')
2093 2096
2094 2097 SQL equivalent::
2095 2098
@@ -2105,11 +2108,13 @@ current time zone before filtering.
2105 2108 day
2106 2109 ~~~
2107 2110
2108   -For date and datetime fields, an exact day match. Takes an integer day.
  2111 +For date and datetime fields, an exact day match. Takes a day of the month
  2112 +as integer or string.
2109 2113
2110 2114 Example::
2111 2115
2112 2116 Entry.objects.filter(pub_date__day=3)
  2117 + Entry.objects.filter(pub_date__day='3')
2113 2118
2114 2119 SQL equivalent::
2115 2120
@@ -2130,12 +2135,13 @@ week_day
2130 2135
2131 2136 For date and datetime fields, a 'day of the week' match.
2132 2137
2133   -Takes an integer value representing the day of week from 1 (Sunday) to 7
  2138 +Takes an integer or string value representing the day of week from 1 (Sunday) to 7
2134 2139 (Saturday).
2135 2140
2136 2141 Example::
2137 2142
2138 2143 Entry.objects.filter(pub_date__week_day=2)
  2144 + Entry.objects.filter(pub_date__week_day='2')
2139 2145
2140 2146 (No equivalent SQL code fragment is included for this lookup because
2141 2147 implementation of the relevant query varies among different database engines.)
@@ -2154,11 +2160,13 @@ hour
2154 2160
2155 2161 .. versionadded:: 1.6
2156 2162
2157   -For datetime fields, an exact hour match. Takes an integer between 0 and 23.
  2163 +For datetime fields, an exact hour match. Takes an integer or string between
  2164 +0 and 23.
2158 2165
2159 2166 Example::
2160 2167
2161 2168 Event.objects.filter(timestamp__hour=23)
  2169 + Event.objects.filter(timestamp__hour='23')
2162 2170
2163 2171 SQL equivalent::
2164 2172
@@ -2176,11 +2184,13 @@ minute
2176 2184
2177 2185 .. versionadded:: 1.6
2178 2186
2179   -For datetime fields, an exact minute match. Takes an integer between 0 and 59.
  2187 +For datetime fields, an exact minute match. Takes an integer or string between
  2188 +0 and 59.
2180 2189
2181 2190 Example::
2182 2191
2183 2192 Event.objects.filter(timestamp__minute=29)
  2193 + Event.objects.filter(timestamp__minute='29')
2184 2194
2185 2195 SQL equivalent::
2186 2196
@@ -2198,11 +2208,13 @@ second
2198 2208
2199 2209 .. versionadded:: 1.6
2200 2210
2201   -For datetime fields, an exact second match. Takes an integer between 0 and 59.
  2211 +For datetime fields, an exact second match. Takes an integer or string between
  2212 +0 and 59.
2202 2213
2203 2214 Example::
2204 2215
2205 2216 Event.objects.filter(timestamp__second=31)
  2217 + Event.objects.filter(timestamp__second='31')
2206 2218
2207 2219 SQL equivalent::
2208 2220
16 tests/regressiontests/model_regress/tests.py
@@ -57,6 +57,7 @@ def test_date_lookup(self):
57 57 Party.objects.create(when=datetime.datetime(1999, 12, 31))
58 58 Party.objects.create(when=datetime.datetime(1998, 12, 31))
59 59 Party.objects.create(when=datetime.datetime(1999, 1, 1))
  60 + Party.objects.create(when=datetime.datetime(1, 3, 3))
60 61 self.assertQuerysetEqual(
61 62 Party.objects.filter(when__month=2), []
62 63 )
@@ -104,6 +105,21 @@ def test_date_lookup(self):
104 105 attrgetter("when")
105 106 )
106 107
  108 + # Regression test for #18969
  109 + self.assertQuerysetEqual(
  110 + Party.objects.filter(when__year=1), [
  111 + datetime.date(1, 3, 3),
  112 + ],
  113 + attrgetter("when")
  114 + )
  115 + self.assertQuerysetEqual(
  116 + Party.objects.filter(when__year='1'), [
  117 + datetime.date(1, 3, 3),
  118 + ],
  119 + attrgetter("when")
  120 + )
  121 +
  122 +
107 123 def test_date_filter_null(self):
108 124 # Date filtering was failing with NULL date values in SQLite
109 125 # (regression test for #3501, amongst other things).

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.