@@ -1039,9 +1039,7 @@ def fromtimestamp(cls, t):
10391039 raise TypeError ("'NoneType' object cannot be interpreted as an integer" )
10401040 if t < 0 and os .name == 'nt' :
10411041 # Windows converters throw an OSError for negative values.
1042- y , m , d , hh , mm , ss , weekday , jday , dst = _time .localtime (0 )
1043- result = cls (y , m , d )
1044- return result + timedelta (seconds = t )
1042+ return cls .fromtimestamp (0 ) + timedelta (seconds = t )
10451043 y , m , d , hh , mm , ss , weekday , jday , dst = _time .localtime (t )
10461044 return cls (y , m , d )
10471045
@@ -1859,6 +1857,10 @@ def _fromtimestamp(cls, t, utc, tz):
18591857
18601858 A timezone info object may be passed in as well.
18611859 """
1860+ if t < 0 and os .name == 'nt' :
1861+ # Windows converters throw an OSError for negative values.
1862+ return cls ._fromtimestamp (0 , utc , tz ) + timedelta (seconds = t )
1863+
18621864 frac , t = _math .modf (t )
18631865 us = round (frac * 1e6 )
18641866 if us >= 1000000 :
@@ -1869,11 +1871,6 @@ def _fromtimestamp(cls, t, utc, tz):
18691871 us += 1000000
18701872
18711873 converter = _time .gmtime if utc else _time .localtime
1872- if t < 0 and os .name == 'nt' :
1873- # Windows converters throw an OSError for negative values.
1874- y , m , d , hh , mm , ss , weekday , jday , dst = converter (0 )
1875- result = cls (y , m , d , hh , mm , ss , 0 , tz )
1876- return result + timedelta (seconds = t , microseconds = us )
18771874 y , m , d , hh , mm , ss , weekday , jday , dst = converter (t )
18781875 ss = min (ss , 59 ) # clamp out leap seconds if the platform has them
18791876 result = cls (y , m , d , hh , mm , ss , us , tz )
0 commit comments