Skip to content

Commit e3dda8f

Browse files
authored
gh-133940: test_strftime incorrectly calculates expected week (GH-134281)
Let the system determine the correct tm_wday and tm_isdst.
1 parent 66aaad6 commit e3dda8f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Lib/test/test_strftime.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,21 @@ def _update_variables(self, now):
3939
if now[3] < 12: self.ampm='(AM|am)'
4040
else: self.ampm='(PM|pm)'
4141

42-
self.jan1 = time.localtime(time.mktime((now[0], 1, 1, 0, 0, 0, 0, 1, 0)))
42+
jan1 = time.struct_time(
43+
(
44+
now.tm_year, # Year
45+
1, # Month (January)
46+
1, # Day (1st)
47+
0, # Hour (0)
48+
0, # Minute (0)
49+
0, # Second (0)
50+
-1, # tm_wday (will be determined)
51+
1, # tm_yday (day 1 of the year)
52+
-1, # tm_isdst (let the system determine)
53+
)
54+
)
55+
# use mktime to get the correct tm_wday and tm_isdst values
56+
self.jan1 = time.localtime(time.mktime(jan1))
4357

4458
try:
4559
if now[8]: self.tz = time.tzname[1]

0 commit comments

Comments
 (0)