# HG changeset patch # User cmlenz # Date 1213616272 0 # Node ID 4cba69c7d4bfce1a7acb40afee24809ce5ad199e # Parent ffde9bbc75bb3c85db416d0dd16ccbfed431c978 Fix for incorrect month context lookup in date formatting. Closes #75. Thanks to Andrew Stromnov for reporting the problem and providing a patch. diff --git a/babel/dates.py b/babel/dates.py --- a/babel/dates.py +++ b/babel/dates.py @@ -751,7 +751,7 @@ if num <= 2: return ('%%0%dd' % num) % self.value.month width = {3: 'abbreviated', 4: 'wide', 5: 'narrow'}[num] - context = {3: 'format', 4: 'format', 5: 'stand-alone'}[num] + context = {'M': 'format', 'L': 'stand-alone'}[char] return get_month_names(width, context, self.locale)[self.value.month] def format_week(self, char, num): diff --git a/babel/tests/dates.py b/babel/tests/dates.py --- a/babel/tests/dates.py +++ b/babel/tests/dates.py @@ -22,6 +22,13 @@ class DateTimeFormatTestCase(unittest.TestCase): + def test_month_context(self): + d = date(2006, 1, 8) + fmt = dates.DateTimeFormat(d, locale='cs_CZ') + self.assertEqual('1', fmt['MMM']) + fmt = dates.DateTimeFormat(d, locale='cs_CZ') + self.assertEqual('1.', fmt['LLL']) + def test_week_of_year_first(self): d = date(2006, 1, 8) fmt = dates.DateTimeFormat(d, locale='de_DE')