Mercurial > babel > old > babel-test
diff babel/dates.py @ 215:d37628e752c4
Dummy/stub implementation for week-in-year and week-in-month date format fields. Also, treat extended year the same as the regular year field, not even ICU seems to handle it specially.
author | cmlenz |
---|---|
date | Fri, 13 Jul 2007 22:22:03 +0000 |
parents | 90bf48c74714 |
children | 1f3c3924b1b5 |
line wrap: on
line diff
--- a/babel/dates.py +++ b/babel/dates.py @@ -438,17 +438,18 @@ self.locale = Locale.parse(locale) def __getitem__(self, name): - # TODO: a number of fields missing here char = name[0] num = len(name) if char == 'G': return self.format_era(char, num) - elif char in ('y', 'Y'): + elif char in ('y', 'Y', 'u'): return self.format_year(char, num) elif char in ('Q', 'q'): return self.format_quarter(char, num) elif char in ('M', 'L'): return self.format_month(char, num) + elif char in ('w', 'W'): + return self.format_week(char, num) elif char == 'd': return self.format(self.value.day, num) elif char in ('E', 'e', 'c'): @@ -494,6 +495,14 @@ context = {3: 'format', 4: 'format', 5: 'stand-alone'}[num] return get_month_names(width, context, self.locale)[self.value.month] + def format_week(self, char, num): + # FIXME: this should really be based on the first_week_day and + # min_week_days locale data + if char.islower(): + return self.value.strftime('%W') + else: + return '%d' % ((self.value.day + 6 - self.value.weekday()) / 7 + 1) + def format_weekday(self, char, num): if num < 3: if char.islower(): @@ -542,7 +551,6 @@ pattern = {3: '%+03d%02d', 4: 'GMT %+03d:%02d'}[max(3, num)] return pattern % (hours, seconds // 60) - def format(self, value, length): return ('%%0%dd' % length) % value