Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delorean object from aware datetimes #22

Closed
mwaterfall opened this issue Feb 12, 2013 · 7 comments
Closed

Delorean object from aware datetimes #22

mwaterfall opened this issue Feb 12, 2013 · 7 comments

Comments

@mwaterfall
Copy link

There seems to be no way to create a Delorean object from an aware datetime object.

Is there a reason for this?

I tend to work with fully aware datetime objects in UTC, but with them being passed around and used everywhere, it's not particularly easy to create a Delorean object from them, without having to do:

dt = Delorean(datetime=dt_utc.replace(tzinfo=None), timezone='UTC')

Which is a bit tedious for an awesome library like Delorean!

I might be a little naive though (excuse the pun!) so I wanted to ask!

@myusuf3
Copy link
Owner

myusuf3 commented Feb 12, 2013

I initially made this the default behaviour in order to help people from making mistakes with passing in localized datetime objects forcing them to take into account what they were actually doing.

I can see how this can be annoying for currently existing systems. I will definitely try to get this in an upcoming release.

Are there any other examples of usage? That are inconvenient to use it with that I may have missed?

@fawce
Copy link

fawce commented Feb 17, 2013

I have a lot of code that also uses pytz for setting the tzinfo, so another nice feature would be to have the constructor accept as a single argument a datetime that has a pytz timezone:

e.g.

dt = datetime(2010, 3, 12, tzinfo=pytz.utc)
dd = Delorean(dt)
dt_eastern = dd.shift("US/Eastern").datetime

@mwaterfall
Copy link
Author

@myusuf3 No I've not come across anything else that's inconvenient, I'm really enjoying using Delorean. If it had a kwarg that took an aware datetime (ensuring anyone that used it is doing it intentionally) then that would be perfect!

@myusuf3
Copy link
Owner

myusuf3 commented Mar 16, 2013

@mwaterfall @fawce I have added support for dealing with already localized datetime objects. c6f4185

Hope this alleviates some pain with the library.

I would reread this section for the new functionality. http://delorean.readthedocs.org/en/latest/quickstart.html#making-some-time

@myusuf3 myusuf3 closed this as completed Mar 16, 2013
@fawce
Copy link

fawce commented Mar 16, 2013

Since my most common use is shift, I would prefer the time zone parameter to shift an aware date time rather than be ignored.

@myusuf3
Copy link
Owner

myusuf3 commented Mar 17, 2013

@fawce you can still shift after the object is created, but I guess I can update that caveat in an upcoming release.

@mwaterfall
Copy link
Author

@myusuf3 Awesome, thanks for incorporating this feature. Much appreciated :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants