gh-81708: Support negative timestamps in _PyTime_localtime for windows #131056
      
        
          +119
        
        
          −32
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
DO NOT MERGE.
This is a work-in-progress/proof-of-concept pull request for not using
localtimeon Windows for negative epoch values but instead using win32 APIs. We basically have a set of long-standing issues and work-arounds/platform specific code for the fact thatlocaltimeon Windows does not support negative numbers, unlike our other platforms.Some examples from a quick search include:
datetime.fromtimestamp(t).astimezone()fails for0<=t<86400in Windows #107078The changes to
Python/pytime.care the ones to look at, the rest are just enabling tests/removing work-arounds. Note that I had to use anif-guard to only use the new win32 apis when the unix timestamp is>= 0because as it turns out,mktimeon Windows has this behavior where it just doesn't account for DST correctly. Without it, tests that rely on round-trippingmktimeandlocaltimefail. (See this repo for more details on that)There is also the question on how to support
tm_ydayandtm_isdst. I have an implementation oftm_ydayand a commented out one fortm_isdst./cc @zooba for thoughts on this approach, whether it's worth pursuing.
/cc @eryksun for Windows expertise on the APIs/methodology