Created
October 22, 2019 23:06
-
-
Save ionelmc/acbf546e00bab661f0b599475807db45 to your computer and use it in GitHub Desktop.
This file contains 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
>>> delta = datetime.timedelta(days=200) | |
>>> tz = pytz.timezone('Europe/Bucharest') | |
>>> datetime_dt = datetime.datetime(2019, 1, 1, tzinfo=tz) | |
>>> print('datetime.datetime(2019, 1, 1, tzinfo=tz):', datetime_dt.isoformat()) | |
datetime.datetime(2019, 1, 1, tzinfo=tz): 2019-01-01T00:00:00+01:44 | |
>>> datetime_dt = tz.localize(datetime.datetime(2019, 1, 1)) | |
>>> print('tz.localize(datetime.datetime(2019, 1, 1)):', datetime_dt.isoformat()) | |
tz.localize(datetime.datetime(2019, 1, 1)): 2019-01-01T00:00:00+02:00 | |
>>> | |
>>> print('datetime + delta:', (datetime_dt + delta).isoformat()) | |
datetime + delta: 2019-07-20T00:00:00+02:00 | |
>>> print('datetime delta:', (datetime_dt + delta) - datetime_dt) | |
datetime delta: 200 days, 0:00:00 | |
>>> print('datetime + delta (tz.normalize):', tz.normalize(datetime_dt + delta).isoformat()) | |
datetime + delta (tz.normalize): 2019-07-20T01:00:00+03:00 | |
>>> print('datetime delta (tz.normalize):', tz.normalize(datetime_dt + delta) - datetime_dt) | |
datetime delta (tz.normalize): 200 days, 0:00:00 | |
>>> | |
>>> arrow_dt = arrow.Arrow(2019, 1, 1, tzinfo='Europe/Bucharest') | |
>>> print('arrow:', arrow_dt.isoformat()) | |
arrow: 2019-01-01T00:00:00+02:00 | |
>>> print('arrow shift:', arrow_dt.shift(days=200).isoformat()) | |
arrow shift: 2019-07-20T00:00:00+03:00 | |
>>> print('arrow delta:', arrow_dt.shift(days=200) - arrow_dt) | |
arrow delta: 200 days, 0:00:00 | |
>>> | |
>>> moment_dt = moment.date(2019, 1, 1).timezone('Europe/Bucharest') | |
>>> print('moment:', moment_dt.isoformat()) | |
moment: 2019-01-01T02:00:00+02:00 | |
>>> print('moment add:', moment_dt.add(days=200).isoformat()) | |
moment add: 2019-07-20T02:00:00+03:00 | |
>>> print('moment delta:', moment_dt.add(days=200) - moment_dt) | |
moment delta: 0:00:00 | |
>>> | |
>>> delorean_dt = delorean.Delorean(datetime.datetime(2019, 1, 1), timezone='Europe/Bucharest') | |
>>> print('delorean:', delorean_dt.format_datetime('long')) | |
delorean: January 1, 2019 at 12:00:00 AM +0200 | |
>>> print('delorean add:', (delorean_dt + delta).format_datetime('long')) | |
delorean add: July 20, 2019 at 12:00:00 AM +0200 | |
>>> print('delorean delta:', (delorean_dt + delta) - delorean_dt) | |
delorean delta: 200 days, 0:00:00 | |
>>> | |
>>> pendulum_dt = pendulum.datetime(2019, 1, 1, tz='Europe/Bucharest') | |
>>> print('pendulum:', pendulum_dt.isoformat()) | |
pendulum: 2019-01-01T00:00:00+02:00 | |
>>> print('pendulum add:', pendulum_dt.add(days=200).isoformat()) | |
pendulum add: 2019-07-20T00:00:00+03:00 | |
>>> pendulum_delta = pendulum_dt.add(days=200) - pendulum_dt | |
>>> print('pendulum delta:', pendulum_delta, 'days:', pendulum_delta.days) | |
pendulum delta: <Period [2019-01-01T00:00:00+02:00 -> 2019-07-20T00:00:00+03:00]> days: 199 |
This file contains 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
datetime.datetime(2019, 1, 1, tzinfo=tz): 2019-01-01T00:00:00+01:44 | |
tz.localize(datetime.datetime(2019, 1, 1)): 2019-01-01T00:00:00+02:00 | |
datetime + delta: 2019-07-20T00:00:00+02:00 | |
datetime delta: 200 days, 0:00:00 | |
datetime + delta (tz.normalize): 2019-07-20T01:00:00+03:00 | |
datetime delta (tz.normalize): 200 days, 0:00:00 | |
arrow: 2019-01-01T00:00:00+02:00 | |
arrow shift: 2019-07-20T00:00:00+03:00 | |
arrow delta: 200 days, 0:00:00 | |
moment: 2019-01-01T02:00:00+02:00 | |
moment add: 2019-07-20T02:00:00+03:00 | |
moment delta: 0:00:00 | |
delorean: January 1, 2019 at 12:00:00 AM +0200 | |
delorean add: July 20, 2019 at 12:00:00 AM +0200 | |
delorean delta: 200 days, 0:00:00 | |
pendulum: 2019-01-01T00:00:00+02:00 | |
pendulum add: 2019-07-20T00:00:00+03:00 | |
pendulum delta: <Period [2019-01-01T00:00:00+02:00 -> 2019-07-20T00:00:00+03:00]> days: 199 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment