Mercurial > babel > old > babel-test
diff babel/dates.py @ 216:1f3c3924b1b5
Support for fractional seconds field in date formatting. Closes #47.
author | cmlenz |
---|---|
date | Sun, 15 Jul 2007 22:09:02 +0000 |
parents | d37628e752c4 |
children | 4de6f4604830 |
line wrap: on
line diff
--- a/babel/dates.py +++ b/babel/dates.py @@ -468,6 +468,8 @@ return self.format(self.value.minute, num) elif char == 's': return self.format(self.value.second, num) + elif char == 'S': + return self.format_frac_seconds(self.value.microsecond, num) elif char in ('z', 'Z', 'v'): return self.format_timezone(char, num) else: @@ -518,6 +520,10 @@ period = {0: 'am', 1: 'pm'}[int(self.value.hour > 12)] return get_period_names(locale=self.locale)[period] + def format_frac_seconds(self, char, num): + value = str(self.value.microsecond) + return self.format(round(float('.%s' % value), num) * 10**num, num) + def format_timezone(self, char, num): if char in ('z', 'v'): if hasattr(self.value.tzinfo, 'zone'):