diff SrvTxtUtils.py @ 87:77f2478ae971

getDateString method to format dates in English and German.
author casties
date Wed, 15 May 2013 11:01:55 +0200
parents 63184d71c014
children 2e2dd6a5ab26
line wrap: on
line diff
--- 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)