Mercurial > babel > old > mirror
comparison babel/dates.py @ 249:d42e85b23272
`get_timezone_gmt()` wasn't getting the locale passed in all cases, which led to test errors when the default locale wasn't configured via environment variables.
author | cmlenz |
---|---|
date | Sun, 12 Aug 2007 19:19:43 +0000 |
parents | cfb4cb07cbc7 |
children | d5543485e49c |
comparison
equal
deleted
inserted
replaced
248:587b06d55323 | 249:d42e85b23272 |
---|---|
172 def get_timezone_gmt(datetime=None, width='long', locale=LC_TIME): | 172 def get_timezone_gmt(datetime=None, width='long', locale=LC_TIME): |
173 """Return the timezone associated with the given `datetime` object formatted | 173 """Return the timezone associated with the given `datetime` object formatted |
174 as string indicating the offset from GMT. | 174 as string indicating the offset from GMT. |
175 | 175 |
176 >>> dt = datetime(2007, 4, 1, 15, 30) | 176 >>> dt = datetime(2007, 4, 1, 15, 30) |
177 >>> get_timezone_gmt(dt) | 177 >>> get_timezone_gmt(dt, locale='en') |
178 u'GMT+00:00' | 178 u'GMT+00:00' |
179 | 179 |
180 >>> from pytz import timezone | 180 >>> from pytz import timezone |
181 >>> tz = timezone('America/Los_Angeles') | 181 >>> tz = timezone('America/Los_Angeles') |
182 >>> dt = datetime(2007, 4, 1, 15, 30, tzinfo=tz) | 182 >>> dt = datetime(2007, 4, 1, 15, 30, tzinfo=tz) |
183 >>> get_timezone_gmt(dt) | 183 >>> get_timezone_gmt(dt, locale='en') |
184 u'GMT-08:00' | 184 u'GMT-08:00' |
185 >>> get_timezone_gmt(dt, 'short') | 185 >>> get_timezone_gmt(dt, 'short', locale='en') |
186 u'-0800' | 186 u'-0800' |
187 | 187 |
188 The long format depends on the locale, for example in France a different | 188 The long format depends on the locale, for example in France a different |
189 string is used for GMT: | 189 string is used for GMT: |
190 | 190 |
191 >>> get_timezone_gmt(dt, 'long', locale='fr_FR') | 191 >>> get_timezone_gmt(dt, 'long', locale='fr_FR') |
192 u'HMG-08:00' | 192 u'HMG-08:00' |
193 | 193 |
194 :param dt: the ``datetime`` object; if `None`, the current date and time are | 194 :param datetime: the ``datetime`` object; if `None`, the current date and |
195 used | 195 time are used |
196 :param width: either "long" or "short" | 196 :param width: either "long" or "short" |
197 :param locale: the `Locale` object, or a locale string | 197 :param locale: the `Locale` object, or a locale string |
198 :return: the GMT offset representation of the timezone | 198 :return: the GMT offset representation of the timezone |
199 :rtype: `unicode` | 199 :rtype: `unicode` |
200 :since: version 0.9 | 200 :since: version 0.9 |
797 def format_timezone(self, char, num): | 797 def format_timezone(self, char, num): |
798 width = {3: 'short', 4: 'long'}[max(3, num)] | 798 width = {3: 'short', 4: 'long'}[max(3, num)] |
799 if char == 'z': | 799 if char == 'z': |
800 return get_timezone_name(self.value, width, locale=self.locale) | 800 return get_timezone_name(self.value, width, locale=self.locale) |
801 elif char == 'Z': | 801 elif char == 'Z': |
802 return get_timezone_gmt(self.value, width) | 802 return get_timezone_gmt(self.value, width, locale=self.locale) |
803 elif char == 'v': | 803 elif char == 'v': |
804 return get_timezone_name(self.value.tzinfo, width, | 804 return get_timezone_name(self.value.tzinfo, width, |
805 locale=self.locale) | 805 locale=self.locale) |
806 elif char == 'V': | 806 elif char == 'V': |
807 if num == 1: | 807 if num == 1: |