]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fixed quarters in date formatting.
authorChristopher Lenz <cmlenz@gmail.com>
Tue, 15 Jul 2008 16:34:18 +0000 (16:34 +0000)
committerChristopher Lenz <cmlenz@gmail.com>
Tue, 15 Jul 2008 16:34:18 +0000 (16:34 +0000)
ChangeLog
babel/dates.py
babel/tests/dates.py

index d0e9c6edaded93e0fe8875c4578602bdcb2d3c32..5fdfdb66e52629b848f5a2b61670f509aae92618 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,15 @@ http://svn.edgewall.org/repos/babel/tags/1.0.0/
    relative times with strings such as "2 days" or "1 month" (ticket #126).
 
 
+Version 0.9.4
+http://svn.edgewall.org/repos/babel/tags/0.9.4/
+(???, from branches/stable/0.9.x)
+
+ * Currency symbol definitions that is defined with choice patterns in the
+   CLDR data are no longer imported, so the symbol code will be used instead.
+ * Fixed quarter support in date formatting.
+
+
 Version 0.9.3
 http://svn.edgewall.org/repos/babel/tags/0.9.3/
 (Jul 9 2008, from branches/stable/0.9.x)
index dc602099b5263fd4135bfc9eb2f3421b85edac15..04069a49246a6b22a400e36948531710576f4417 100644 (file)
@@ -841,6 +841,14 @@ class DateTimeFormat(object):
             year = year[-2:]
         return year
 
+    def format_quarter(self, char, num):
+        quarter = (self.value.month - 1) // 3 + 1
+        if num <= 2:
+            return ('%%0%dd' % num) % quarter
+        width = {3: 'abbreviated', 4: 'wide', 5: 'narrow'}[num]
+        context = {'Q': 'format', 'q': 'stand-alone'}[char]
+        return get_quarter_names(width, context, self.locale)[quarter]
+
     def format_month(self, char, num):
         if num <= 2:
             return ('%%0%dd' % num) % self.value.month
index 5f6abf1e29865d13db3ff9abf15b6e77fda0baa4..b3fc14b1f72ef8040d83472c0496e76dc28092c1 100644 (file)
@@ -22,6 +22,15 @@ from babel import dates
 
 class DateTimeFormatTestCase(unittest.TestCase):
 
+    def test_quarter_format(self):
+        d = date(2006, 6, 8)
+        fmt = dates.DateTimeFormat(d, locale='en_US')
+        self.assertEqual('2', fmt['Q'])
+        self.assertEqual('2nd quarter', fmt['QQQQ'])
+        d = date(2006, 12, 31)
+        fmt = dates.DateTimeFormat(d, locale='en_US')
+        self.assertEqual('Q4', fmt['QQQ'])
+
     def test_month_context(self):
         d = date(2006, 1, 8)
         fmt = dates.DateTimeFormat(d, locale='cs_CZ')