Python Arrow library is not handling DST properly - Stack Overflow

admin2025-04-16  0

My understanding of shift method was it will take care of DST. However when testing for 10 hours shift on 2025-03-08T18:30:00 with US/Central as tzinfo, the expected output should be 2025-03-09T05:30:00-05:00 but I am getting 2025-03-09T04:30:00-05:00. Fyi, DST changes on March 9, 2025. At 2 a.m


# Step 1: Create a timezone-aware datetime using Arrow
start = arrow.get("2025-03-08T18:30:00").format('YYYY-MM-DDTHH:mm:ss')  # starting datetime
start_tz = arrow.get(start).replace(tzinfo='US/Central')  # Set the timezone to US/Central

# Step 2: Shift by 10 hours
shifted = start_tz.shift(hours=10)

# Step 3: Print the result
print(shifted)  # Should print: 2025-03-09T05:30:00-05:00 (after DST transition) but getting <Arrow [2025-03-09T04:30:00-05:00]>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744809200a268182.html

最新回复(0)