Created
February 28, 2020 10:43
-
-
Save Asday/be44c79fa5ead8461e8da8da2b93c30e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 3.8.1 (default, Dec 31 2019, 18:44:59) | |
[GCC 5.4.0 20160609] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> import datetime | |
>>> samoa = datetime.timezone(datetime.timedelta(hours=14)) | |
>>> before = datetime.datetime(2011, 12, 29, tzinfo=samoa) | |
>>> before + datetime.timedelta(days=1) | |
datetime.datetime(2011, 12, 30, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=50400))) | |
>>> |
The conclusion is that, unsurprisingly, dates are bullshit, and the less anyone can have to do with them, the better. If someone else has written something to handle dates, use that.
We're Python. We shouldn't be scared of dependencies.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
However, I wonder if this is just "garbage in, garbage out".
datetime.timezone(datetime.timedelta(hours=14))
does NOT represent the political Samoa TZ, just a fixed 14-hour offset TZ.Would this bug reproduce with an actual TZ that's faithful to Samoa?
I guess you have a point that I was arguing against dependenceis in direction of "just do it with python stdlib", and the stdlib famoulsly includes no timezones database☹️
Granted.
But is the conclusion "you must use a real timezone database for human-meaningful results", or is there a fault in using
datetime.timedelta(days=1)
for going a day back/forward?[thanks for the interesting discussion, as most programmers, I don't know enough about dates...]