| 91 | self.strftest2(arg) |
| 92 | |
| 93 | def strftest1(self, now): |
| 94 | if support.verbose: |
| 95 | print("strftime test for", time.ctime(now)) |
| 96 | now = self.now |
| 97 | # Make sure any characters that could be taken as regex syntax is |
| 98 | # escaped in escapestr() |
| 99 | expectations = ( |
| 100 | ('%a', calendar.day_abbr[now[6]], 'abbreviated weekday name'), |
| 101 | ('%A', calendar.day_name[now[6]], 'full weekday name'), |
| 102 | ('%b', calendar.month_abbr[now[1]], 'abbreviated month name'), |
| 103 | ('%B', calendar.month_name[now[1]], 'full month name'), |
| 104 | # %c see below |
| 105 | ('%d', '%02d' % now[2], 'day of month as number (00-31)'), |
| 106 | ('%H', '%02d' % now[3], 'hour (00-23)'), |
| 107 | ('%I', '%02d' % self.clock12, 'hour (01-12)'), |
| 108 | ('%j', '%03d' % now[7], 'julian day (001-366)'), |
| 109 | ('%m', '%02d' % now[1], 'month as number (01-12)'), |
| 110 | ('%M', '%02d' % now[4], 'minute, (00-59)'), |
| 111 | ('%p', self.ampm, 'AM or PM as appropriate'), |
| 112 | ('%S', '%02d' % now[5], 'seconds of current time (00-60)'), |
| 113 | ('%U', '%02d' % ((now[7] + self.jan1[6])//7), |
| 114 | 'week number of the year (Sun 1st)'), |
| 115 | ('%w', '0?%d' % ((1+now[6]) % 7), 'weekday as a number (Sun 1st)'), |
| 116 | ('%W', '%02d' % ((now[7] + (self.jan1[6] - 1)%7)//7), |
| 117 | 'week number of the year (Mon 1st)'), |
| 118 | # %x see below |
| 119 | ('%X', '%02d:%02d:%02d' % (now[3], now[4], now[5]), '%H:%M:%S'), |
| 120 | ('%y', '%02d' % (now[0]%100), 'year without century'), |
| 121 | ('%Y', '%d' % now[0], 'year with century'), |
| 122 | # %Z see below |
| 123 | ('%%', '%', 'single percent sign'), |
| 124 | ) |
| 125 | |
| 126 | for e in expectations: |
| 127 | # mustn't raise a value error |
| 128 | try: |
| 129 | result = time.strftime(e[0], now) |
| 130 | except ValueError as error: |
| 131 | self.fail("strftime '%s' format gave error: %s" % (e[0], error)) |
| 132 | if re.match(escapestr(e[1], self.ampm), result): |
| 133 | continue |
| 134 | if not result or result[0] == '%': |
| 135 | self.fail("strftime does not support standard '%s' format (%s)" |
| 136 | % (e[0], e[2])) |
| 137 | else: |
| 138 | self.fail("Conflict for %s (%s): expected %s, but got %s" |
| 139 | % (e[0], e[2], e[1], result)) |
| 140 | |
| 141 | def strftest2(self, now): |
| 142 | nowsecs = str(int(now))[:-1] |