Mike Orr avatar Mike Orr committed 68639fc

Adjust date test to account for leap year.

Comments (0)

Files changed (2)

   - Some ``webhelpers.misc`` helpers were undocumented.
   
   - Spelling corrections throughout, done by Marius Gedminas.
+
+* webhelpers.date:
+
+  - Adjust test in 'test_date.py' to account for leap years. (#61, reported
+    by Andrey Rahmatullin / wrar)
   
 * webhelpers.paginate:
 

tests/test_date.py

 
         # Test that if integers are supplied they are interpreted as seconds from now
         self.assertEqual("1 second", distance_of_time_in_words(1))
-        self.assertEqual("1 year", distance_of_time_in_words(0, 31536000))
-        self.assertEqual("1 year", distance_of_time_in_words(1, 31536001))
+        # The following two tests test the span from "now" to "a year from
+        # now".  Depending on when the test is run, the interval may include a
+        # leap year.  The 'try' assumes it's not a leap year, the 'except'
+        # tries it again as a leap year.
+        try:
+            self.assertEqual("1 year", distance_of_time_in_words(0, 31536000))
+            self.assertEqual("1 year", distance_of_time_in_words(1, 31536001))
+        except AssertionError:  # If the intervening year contains February 29th
+            self.assertEqual("11 months and 30 days", distance_of_time_in_words(0, 31536000))
+            self.assertEqual("11 months and 30 days", distance_of_time_in_words(1, 31536001))
          
         # Granularity is invalid
         self.assertRaises(Exception, distance_of_time_in_words, 0, 1, 'blah')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.