Store more data inside of timedeltas

According to the docs, only days, seconds, and microseconds are store internally. What’s confusing to me is much more can be passed, including hours and minutes. My suggestion/question is why aren’t more attributes stored?

Because everything is normalised to days/seconds/microseconds. So 1 minute is stored as 60 seconds, and if you ask how many minutes, the 60 seconds is converted back into 1 minute. The performance cost is negligible, and by holding the data like this there’s no need to maintain multiple representations in parallel.

4 Likes

Interesting! Why are days and seconds stored at all? Why not everything as microseconds?

Days and seconds, because the number of seconds in a day isn’t constant (leap seconds and DST, for example). Microseconds I’m not sure about - possibly just because seconds are convenient for a lot of uses, or because microseconds were added later and it wasn’t worth changing existing code that worked.

In reality, it doesn’t matter what the internal representation is, though. It’s the API that’s important.

3 Likes