From: Aarni Koskela Date: Fri, 18 Aug 2017 08:34:06 +0000 (+0300) Subject: Date format: Use * parametrized format patterns instead of %%0%... (#517) X-Git-Tag: v2.5.0~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=230e1f765b59bc8682f887ba0653921e6f442381;p=thirdparty%2Fbabel.git Date format: Use * parametrized format patterns instead of %%0%... (#517) This is about 60% faster than the old version in a micro-benchmark. --- diff --git a/babel/dates.py b/babel/dates.py index 75e53a1d..d1fafe2a 100644 --- a/babel/dates.py +++ b/babel/dates.py @@ -1330,14 +1330,14 @@ class DateTimeFormat(object): def format_quarter(self, char, num): quarter = (self.value.month - 1) // 3 + 1 if num <= 2: - return ('%%0%dd' % num) % quarter + return '%0*d' % (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 + return '%0*d' % (num, self.value.month) width = {3: 'abbreviated', 4: 'wide', 5: 'narrow'}[num] context = {'M': 'format', 'L': 'stand-alone'}[char] return get_month_names(width, context, self.locale)[self.value.month] @@ -1470,7 +1470,7 @@ class DateTimeFormat(object): return get_timezone_gmt(self.value, width='iso8601', locale=self.locale) def format(self, value, length): - return ('%%0%dd' % length) % value + return '%0*d' % (length, value) def get_day_of_year(self, date=None): if date is None: