Commits

Andriy Kornatskyy committed 0f0eb76

Default date and datetime format providers should return an empty string in case year < 1900, due to limits of strftime.

Comments (0)

Files changed (1)

src/wheezy/html/utils.py

 
 
 str_format_provider = lambda value, format_spec: str_type(value)
+min_date = date(1900, 1, 1)
+min_datetime = datetime(1900, 1, 1)
 
 
 def date_format_provider(value, format_spec=None):
     """ Default format provider for ``datetime.date``.
 
+        Requires year >= 1900, otherwise returns an empty string.
+
         >>> date_format_provider(date.min)
         ''
+        >>> date_format_provider(min_date)
+        '1900/01/01'
         >>> date_format_provider(date(2012, 2, 6))
         '2012/02/06'
     """
-    if date.min == value:
+    if value < min_date:
         return ''
     # Python 2.4, 2.5
     # TypeError: strftime() argument 1 must be str, not unicode
 def datetime_format_provider(value, format_spec=None):
     """ Default format provider for ``datetime.datetime``.
 
+        Requires year >= 1900, otherwise returns an empty string.
+
         >>> datetime_format_provider(datetime.min)
         ''
+        >>> datetime_format_provider(min_datetime)
+        '1900/01/01 00:00'
         >>> datetime_format_provider(datetime(2012, 2, 6, 15, 17))
         '2012/02/06 15:17'
     """
-    if datetime.min == value:
+    if value < min_datetime:
         return ''
     # Python 2.4, 2.5
     # TypeError: strftime() argument 1 must be str, not unicode
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.