Added test case for years before 1900 ZTK-1.1
authorThierry Florac <thierry.florac@onf.fr>
Thu, 26 Mar 2015 15:37:02 +0100
branchZTK-1.1
changeset 262 811bd7424e87
parent 261 f2c1b9927f34
child 263 dec0866c6c44
Added test case for years before 1900
src/ztfy/utils/date.py
--- a/src/ztfy/utils/date.py	Mon Sep 15 12:50:49 2014 +0200
+++ b/src/ztfy/utils/date.py	Thu Mar 26 15:37:02 2015 +0100
@@ -86,7 +86,12 @@
 def formatDate(value, format=EXT_DATE_FORMAT, request=None):
     if request is None:
         request = queryRequest()
-    return datetime.strftime(tztime(value), translate(format, context=request).encode('utf-8')).decode('utf-8')
+    if value.year >= 1900:
+        return datetime.strftime(tztime(value), translate(format, context=request).encode('utf-8')).decode('utf-8')
+    else:
+        return format.replace('%d', str(value.day)) \
+                     .replace('%m', str(value.month)) \
+                     .replace('%Y', str(value.year))
 
 
 def formatDatetime(value, format=EXT_DATETIME_FORMAT, request=None):