Added dates formatting functions ZTK-1.1
authorThierry Florac <tflorac@ulthar.net>
Tue, 23 Apr 2013 11:16:12 +0200
branchZTK-1.1
changeset 213 ec49fc38bcb4
parent 212 0c2257bf3762
child 214 91a1aa280326
Added dates formatting functions
docs/HISTORY.txt
src/ztfy/utils/date.py
src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.mo
src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.po
src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.mo
src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.po
src/ztfy/utils/locales/ztfy.utils.pot
--- a/docs/HISTORY.txt	Sun Apr 21 11:24:24 2013 +0200
+++ b/docs/HISTORY.txt	Tue Apr 23 11:16:12 2013 +0200
@@ -4,6 +4,7 @@
 0.4.2
 -----
  - small correction in getHumanSize() function
+ - added dates formatting functions
 
 0.4.1
 -----
--- a/src/ztfy/utils/date.py	Sun Apr 21 11:24:24 2013 +0200
+++ b/src/ztfy/utils/date.py	Tue Apr 23 11:16:12 2013 +0200
@@ -26,7 +26,8 @@
 from zope.i18n import translate
 
 # import local packages
-from timezone import gmtime
+from ztfy.utils.request import queryRequest
+from ztfy.utils.timezone import gmtime, tztime
 
 from ztfy.utils import _
 
@@ -75,6 +76,18 @@
     return datetime(value.year, value.month, value.day)
 
 
+EXT_DATE_FORMAT = _("on %d/%m/%Y")
+EXT_DATETIME_FORMAT = _("on %d/%m/%Y at %H:%M")
+
+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')
+
+def formatDatetime(value, format=EXT_DATETIME_FORMAT, request=None):
+    return formatDate(value, format, request)
+
+
 def getAge(value):
     """Get age of a given datetime (including timezone) compared to current datetime (in UTC)
     
Binary file src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.mo has changed
--- a/src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.po	Sun Apr 21 11:24:24 2013 +0200
+++ b/src/ztfy/utils/locales/en/LC_MESSAGES/ztfy.utils.po	Tue Apr 23 11:16:12 2013 +0200
@@ -14,7 +14,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: ZTFY.utils\n"
-"POT-Creation-Date: Wed Apr 10 18:38:24 2013\n"
+"POT-Creation-Date: Tue Apr 23 11:16:22 2013\n"
 "PO-Revision-Date: 2009-08-14 18:14+0200\n"
 "Last-Translator: Thierry Florac <tflorac@ulthar.net>\n"
 "Language-Team: French <traduc@traduc.org>\n"
Binary file src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.mo has changed
--- a/src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.po	Sun Apr 21 11:24:24 2013 +0200
+++ b/src/ztfy/utils/locales/fr/LC_MESSAGES/ztfy.utils.po	Tue Apr 23 11:16:12 2013 +0200
@@ -16,7 +16,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: ZTFY.utils\n"
-"POT-Creation-Date: Wed Apr 10 16:36:50 2013\n"
+"POT-Creation-Date: Tue Apr 23 11:16:22 2013\n"
 "PO-Revision-Date: 2012-03-26 14:18+0200\n"
 "Last-Translator: Thierry Florac <thierry.florac@onf.fr>\n"
 "Language-Team: français <>\n"
@@ -35,65 +35,73 @@
 msgid "ZEO connection properties"
 msgstr "Propriétés de la connexion ZEO"
 
-#: ztfy/utils/date.py:101
+#: ztfy/utils/date.py:102
+msgid "%d months ago"
+msgstr "il y a %d mois"
+
+#: ztfy/utils/date.py:104
+msgid "%d weeks ago"
+msgstr "il y a %d semaines"
+
+#: ztfy/utils/date.py:106
+msgid "%d days ago"
+msgstr "il y a %d jours"
+
+#: ztfy/utils/date.py:108
+msgid "the day before yesterday"
+msgstr "avant-hier"
+
+#: ztfy/utils/date.py:110
+msgid "yesterday"
+msgstr "hier"
+
+#: ztfy/utils/date.py:114
 msgid "%d hours ago"
 msgstr "il y a %d heures"
 
-#: ztfy/utils/date.py:103
+#: ztfy/utils/date.py:116
 msgid "%d minutes ago"
 msgstr "il y a %d minutes"
 
-#: ztfy/utils/date.py:105
+#: ztfy/utils/date.py:118
 msgid "less than 5 minutes ago"
 msgstr "il y a moins de 5 minutes"
 
-#: ztfy/utils/date.py:116
+#: ztfy/utils/date.py:129
 msgid "%d months"
 msgstr "%d mois"
 
-#: ztfy/utils/date.py:118
+#: ztfy/utils/date.py:131
 msgid "%d weeks"
 msgstr "%d semaines"
 
-#: ztfy/utils/date.py:120
+#: ztfy/utils/date.py:133
 msgid "%d days"
 msgstr "%d jours"
 
-#: ztfy/utils/date.py:124
+#: ztfy/utils/date.py:137
 msgid "%d day and %d hours"
 msgstr "%d jours et %d heures"
 
-#: ztfy/utils/date.py:127
+#: ztfy/utils/date.py:140
 msgid "%d hours"
 msgstr "%d heures"
 
-#: ztfy/utils/date.py:131
+#: ztfy/utils/date.py:144
 msgid "%d minutes"
 msgstr "%d minutes"
 
-#: ztfy/utils/date.py:133
+#: ztfy/utils/date.py:146
 msgid "%d seconds"
 msgstr "%d secondes"
 
-#: ztfy/utils/date.py:89
-msgid "%d months ago"
-msgstr "il y a %d mois"
-
-#: ztfy/utils/date.py:91
-msgid "%d weeks ago"
-msgstr "il y a %d semaines"
+#: ztfy/utils/date.py:79
+msgid "on %d/%m/%Y"
+msgstr "le %d/%m/%Y"
 
-#: ztfy/utils/date.py:93
-msgid "%d days ago"
-msgstr "il y a %d jours"
-
-#: ztfy/utils/date.py:95
-msgid "the day before yesterday"
-msgstr "avant-hier"
-
-#: ztfy/utils/date.py:97
-msgid "yesterday"
-msgstr "hier"
+#: ztfy/utils/date.py:80
+msgid "on %d/%m/%Y at %H:%M"
+msgstr "le %d/%m/%Y à %H:%M"
 
 #: ztfy/utils/encoding.py:100
 msgid "Greek (iso8859_7)"
--- a/src/ztfy/utils/locales/ztfy.utils.pot	Sun Apr 21 11:24:24 2013 +0200
+++ b/src/ztfy/utils/locales/ztfy.utils.pot	Tue Apr 23 11:16:12 2013 +0200
@@ -14,7 +14,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: Meaningless\n"
-"POT-Creation-Date: Wed Apr 10 18:38:24 2013\n"
+"POT-Creation-Date: Tue Apr 23 11:16:22 2013\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: Zope 3 Developers <zope-dev@zope.org>\n"
@@ -31,64 +31,72 @@
 msgid "ZEO connection properties"
 msgstr ""
 
-#: ztfy/utils/date.py:101
-msgid "%d hours ago"
+#: ztfy/utils/date.py:102
+msgid "%d months ago"
+msgstr ""
+
+#: ztfy/utils/date.py:104
+msgid "%d weeks ago"
 msgstr ""
 
-#: ztfy/utils/date.py:103
-msgid "%d minutes ago"
+#: ztfy/utils/date.py:106
+msgid "%d days ago"
 msgstr ""
 
-#: ztfy/utils/date.py:105
-msgid "less than 5 minutes ago"
+#: ztfy/utils/date.py:108
+msgid "the day before yesterday"
+msgstr ""
+
+#: ztfy/utils/date.py:110
+msgid "yesterday"
+msgstr ""
+
+#: ztfy/utils/date.py:114
+msgid "%d hours ago"
 msgstr ""
 
 #: ztfy/utils/date.py:116
-msgid "%d months"
+msgid "%d minutes ago"
 msgstr ""
 
 #: ztfy/utils/date.py:118
+msgid "less than 5 minutes ago"
+msgstr ""
+
+#: ztfy/utils/date.py:129
+msgid "%d months"
+msgstr ""
+
+#: ztfy/utils/date.py:131
 msgid "%d weeks"
 msgstr ""
 
-#: ztfy/utils/date.py:120
+#: ztfy/utils/date.py:133
 msgid "%d days"
 msgstr ""
 
-#: ztfy/utils/date.py:124
+#: ztfy/utils/date.py:137
 msgid "%d day and %d hours"
 msgstr ""
 
-#: ztfy/utils/date.py:127
+#: ztfy/utils/date.py:140
 msgid "%d hours"
 msgstr ""
 
-#: ztfy/utils/date.py:131
+#: ztfy/utils/date.py:144
 msgid "%d minutes"
 msgstr ""
 
-#: ztfy/utils/date.py:133
+#: ztfy/utils/date.py:146
 msgid "%d seconds"
 msgstr ""
 
-#: ztfy/utils/date.py:89
-msgid "%d months ago"
-msgstr ""
-
-#: ztfy/utils/date.py:91
-msgid "%d weeks ago"
+#: ztfy/utils/date.py:79
+msgid "on %d/%m/%Y"
 msgstr ""
 
-#: ztfy/utils/date.py:93
-msgid "%d days ago"
-msgstr ""
-
-#: ztfy/utils/date.py:95
-msgid "the day before yesterday"
-msgstr ""
-
-#: ztfy/utils/date.py:97
-msgid "yesterday"
+#: ztfy/utils/date.py:80
+msgid "on %d/%m/%Y at %H:%M"
 msgstr ""
 
 #: ztfy/utils/encoding.py:100