changeset 87:77f2478ae971

getDateString method to format dates in English and German.
author casties
date Wed, 15 May 2013 11:01:55 +0200
parents ab836d3f96dc
children 04a26a5d3d1d
files MPIWGRoot.py SrvTxtUtils.py
diffstat 2 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGRoot.py	Tue May 14 17:24:30 2013 +0200
+++ b/MPIWGRoot.py	Wed May 15 11:01:55 2013 +0200
@@ -14,7 +14,7 @@
 from MPIWGHelper import *
 import updatePersonalWWW
 import MPIWGStaff
-from SrvTxtUtils import getInt, getAt, utf8ify, refreshingImageFileIndexHtml
+from SrvTxtUtils import getInt, getAt, utf8ify, refreshingImageFileIndexHtml, getDateString
 
 
 class MPIWGRoot(ZSQLExtendFolder):
@@ -117,6 +117,11 @@
             else:
                 return False
 
+
+    def getDateString(self, **args):
+        """Return a formatted date string."""
+        return getDateString(**args)
+
     
     def getSubsections(self, here=None):
         """return sub-navigation elements i.e. elements below sections"""
--- a/SrvTxtUtils.py	Tue May 14 17:24:30 2013 +0200
+++ b/SrvTxtUtils.py	Wed May 15 11:01:55 2013 +0200
@@ -13,7 +13,7 @@
 
 import xml.etree.ElementTree as ET
 
-srvTxtUtilsVersion = "1.8"
+srvTxtUtilsVersion = "1.9"
 
 map_months = {'en': [u"",
                u"January",
@@ -118,6 +118,23 @@
     """returns the name of the month mon in the language lang"""
     return map_months[lang][mon]
 
+
+def getDateString(date=None, lang='en', withYear=True, abbrev=False):
+    """Return formatted date string."""
+    ds = None
+    if lang.lower() == 'en':
+        ds = "%s, %s"%(getMonthName(date.month(), lang), date.day())
+        if withYear:
+            ds += " %s"%date.year()
+            
+    elif lang.lower() == 'de':
+        ds = "%s.%s."%(date.day(), date.month())
+        if withYear:
+            ds += " %s"%date.year()
+            
+    return ds
+        
+
 def getHttpData(url, data=None, num_tries=3, timeout=10, noExceptions=False):
     """returns result from url+data HTTP request"""
     # we do GET (by appending data to url)