(self)
| 179 | self.LC_alt_digits = None |
| 180 | |
| 181 | def __calc_date_time(self): |
| 182 | # Set self.LC_date_time, self.LC_date, self.LC_time and |
| 183 | # self.LC_time_ampm by using time.strftime(). |
| 184 | |
| 185 | # Use (1999,3,17,22,44,55,2,76,0) for magic date because the amount of |
| 186 | # overloaded numbers is minimized. The order in which searches for |
| 187 | # values within the format string is very important; it eliminates |
| 188 | # possible ambiguity for what something represents. |
| 189 | time_tuple = time.struct_time((1999,3,17,22,44,55,2,76,0)) |
| 190 | time_tuple2 = time.struct_time((1999,1,3,1,1,1,6,3,0)) |
| 191 | replacement_pairs = [] |
| 192 | |
| 193 | # Non-ASCII digits |
| 194 | if self.LC_alt_digits or self.LC_alt_digits is None: |
| 195 | for n, d in [(19, '%OC'), (99, '%Oy'), (22, '%OH'), |
| 196 | (44, '%OM'), (55, '%OS'), (17, '%Od'), |
| 197 | (3, '%Om'), (2, '%Ow'), (10, '%OI')]: |
| 198 | if self.LC_alt_digits is None: |
| 199 | s = chr(0x660 + n // 10) + chr(0x660 + n % 10) |
| 200 | replacement_pairs.append((s, d)) |
| 201 | if n < 10: |
| 202 | replacement_pairs.append((s[1], d)) |
| 203 | elif len(self.LC_alt_digits) > n: |
| 204 | replacement_pairs.append((self.LC_alt_digits[n], d)) |
| 205 | else: |
| 206 | replacement_pairs.append((time.strftime(d, time_tuple), d)) |
| 207 | replacement_pairs += [ |
| 208 | ('1999', '%Y'), ('99', '%y'), ('22', '%H'), |
| 209 | ('44', '%M'), ('55', '%S'), ('76', '%j'), |
| 210 | ('17', '%d'), ('03', '%m'), ('3', '%m'), |
| 211 | # '3' needed for when no leading zero. |
| 212 | ('2', '%w'), ('10', '%I'), |
| 213 | ] |
| 214 | |
| 215 | date_time = [] |
| 216 | for directive in ('%c', '%x', '%X', '%r'): |
| 217 | current_format = time.strftime(directive, time_tuple).lower() |
| 218 | current_format = current_format.replace('%', '%%') |
| 219 | # The month and the day of the week formats are treated specially |
| 220 | # because of a possible ambiguity in some locales where the full |
| 221 | # and abbreviated names are equal or names of different types |
| 222 | # are equal. See doc of __find_month_format for more details. |
| 223 | lst, fmt = self.__find_weekday_format(directive) |
| 224 | if lst: |
| 225 | current_format = current_format.replace(lst[2], fmt, 1) |
| 226 | lst, fmt = self.__find_month_format(directive) |
| 227 | if lst: |
| 228 | current_format = current_format.replace(lst[3], fmt, 1) |
| 229 | if self.am_pm[1]: |
| 230 | # Must deal with possible lack of locale info |
| 231 | # manifesting itself as the empty string (e.g., Swedish's |
| 232 | # lack of AM/PM info) or a platform returning a tuple of empty |
| 233 | # strings (e.g., MacOS 9 having timezone as ('','')). |
| 234 | current_format = current_format.replace(self.am_pm[1], '%p') |
| 235 | for tz_values in self.timezone: |
| 236 | for tz in tz_values: |
| 237 | if tz: |
| 238 | current_format = current_format.replace(tz, "%Z") |
no test coverage detected