myusuf3 / delorean

Delorean: Time Travel Made Easy
http://delorean.rtfd.org/
MIT License
1.84k stars 128 forks source link

Delorean.shift does not take datetime.timezone.utc #97

Closed numberoverzero closed 6 years ago

numberoverzero commented 7 years ago

To reproduce:

import delorean
import datetime

utc = datetime.timezone.utc
dt = datetime.datetime(2017, 3, 5, 3, 1, 46, 425154, tzinfo=utc)

d = delorean.Delorean(dt).shift(utc)

From these lines, Delorean doesn't support anything outside of pytz.timezone ability to parse, which breaks on zone.upper() at the beginning of this method.

Should I always use "UTC" instead of datetime's provided datetime.timezone.utc? I was hoping to reuse the standard library's version across different datetime libraries.

jacobKKK commented 6 years ago

Is convert datetime.timezone and pytz.timezone to Delorean().shift() a good solution to these problem? Because it currently take the argument from Delorean().shift() directly to pytz.timezone()constructor.

myusuf3 commented 6 years ago

You should always use UTC why would you pull in datetime to just ask for utc timezone. There are few examples that cover what you are trying to do at http://delorean.rtfd.org.

numberoverzero commented 6 years ago

Thanks for the response. I'm pulling in datetime for more than utc but wanted to provide a minimal example. I'll use "UTC" instead.

I was hoping that .shift would handle a datetime.tzinfo instance (as well as a string through the use of pytz) because I provide a library that maps dynamodb objects to python types, and I include an extension for Delorean which simply forwards the users' timezone parameter through.

I expect most users will provide a string such as "utc" and things will be fine, but some may use a custom datetime.tzinfo subclass; datetime.timezone is simply a concrete example of the problem. From the docs:

Note that only one concrete tzinfo class, the timezone class, is supplied by the datetime module. The timezone class can represent simple timezones with fixed offset from UTC, such as UTC itself or North American EST and EDT timezones.