Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(381)

Unified Diff: trytond/ir/lang.py

Issue 97042: Add strftime to ir.lang (Closed)
Patch Set: Fix missing last day and last month Created 14 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « trytond/ir/gen_time_locale.py ('k') | trytond/ir/time_locale.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trytond/ir/lang.py
===================================================================
--- a/trytond/ir/lang.py
+++ b/trytond/ir/lang.py
@@ -1,8 +1,10 @@
-#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
+#This file is part of Tryton. The COPYRIGHT file at the top level of
+#this repository contains the full copyright notices and license terms.
"Lang"
from trytond.model import ModelView, ModelSQL, fields
from trytond.model.cacheable import Cacheable
import time
+from time_locale import TIME_LOCALE
class Lang(ModelSQL, ModelView, Cacheable):
@@ -99,6 +101,11 @@
and '%j' not in lang.date \
and '%-j' not in lang.date:
return False
+ if '%x' in lang.date \
+ or '%X' in lang.date \
+ or '%c' in lang.date \
+ or '%Z' in lang.date:
+ return False
return True
def check_xml_record(self, cursor, user, ids, values, context=None):
@@ -291,4 +298,20 @@
return s.replace('<', '').replace('>', '')
+ def strftime(self, timetuple, code, format):
+ '''
+ Convert timetuple to a string as specified by the format argument.
+
+ :param timetuple: a tuple or struct_time representing a time
+ :param code: locale code
+ :param format: a string
+ :return: a string
+ '''
+ if code in TIME_LOCALE:
+ for f, i in (('%a', 6), ('%A', 6), ('%b', 1), ('%B', 1)):
+ format = format.replace(f, TIME_LOCALE[code][f][timetuple[i]])
+ format = format.replace('%p', TIME_LOCALE[code]['%p']\
+ [timetuple[3] < 12 and 0 or 1])
+ return time.strftime(format, timetuple)
+
Lang()
« no previous file with comments | « trytond/ir/gen_time_locale.py ('k') | trytond/ir/time_locale.py » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b