Struggling to understand timedelta rpesentation when applying an offset for an hour earlier - why is days = -1?

Dennis Lee Bieber wlfraed at ix.netcom.com
Tue Aug 31 12:46:02 EDT 2021


On Tue, 31 Aug 2021 03:59:52 -0700 (PDT), dcs3spp via Python-list
<python-list at python.org> declaimed the following:


>I cannot understand why the resultant datetime.timedelta is days=-1, seconds=82800 (23 hours) .
>

	Read the documentation...
https://docs.python.org/3/library/datetime.html#timedelta-objects


>Why is it not an hour earlier as seconds=-3600? Why is days = -1 when the resultant calculated date is the same, year, day, month??

"""
and days, seconds and microseconds are then normalized so that the
representation is unique, with

    0 <= microseconds < 1000000

    0 <= seconds < 3600*24 (the number of seconds in one day)

    -999999999 <= days <= 999999999
"""

Note that microseconds and seconds are ALWAYS normalized to be a positive
integer. So your input on -3600 is normalized to +82800 from the previous
day.


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Python-list mailing list