
Delorean – datetime conversions in Python - ahammad
http://delorean.readthedocs.org/en/latest/index.html
======
notatoad
I'm not a fan of the name (or the entire syntax really, but the non-
descriptive name is the worst bit). python is generally pretty self-
documenting, but calling 'Delorean' to convert times is totally obscure. using
datetime and pytz.timezone is a few too many steps at times, but at least it
is readable. This is just magic.

`return utc.localize(datetime.utcnow()).astimezone(est)` is maybe a little
annoying to type out, but it's obvious what it does. `return Delorean(est)`
doesn't make any sense at all.

~~~
dorkrawk
> but calling 'Delorean' to convert times is totally obscure

Unlike calling 'pickle' to serialize...

~~~
maw
Although now we make and eat pickled vegetables because we like the taste,
pickling was originally developed in order to enable vegetables to store
longer. Calling a serializer "pickle" isn't unreasonable.

~~~
derelk
It's not unreasonable, but it's still obscure. Calling a time utility Delorean
isn't unreasonable, despite also being obscure.

------
simonw
Every time I do something involving with timezones in Python I find myself
having to figure out the API again from scratch - it just doesn't fit in my
brain. Having read the docs for this it appears to cover everything I ever
want to do in a much more obvious way. Thanks very much!

~~~
googletron
Thank you!

------
opminion
Slightly off topic: does anybody know why timezones are not firmly isolated
within the presentation layer (more specifically, in the string formatting
functions) rather than being part of the datetime object? (datetime in Python,
DateTime in C#).

In other words why this sentence could be wrong: _Timezones are a
presentation-layer problem!_ <http://news.ycombinator.com/item?id=5083321>

~~~
calpaterson
It's because timezones can be part of business logic. For example if you want
to start trading at 9 London time, whether London is GMT or GMT+1 at the
moment.

~~~
apaprocki
Or put more simply -- recurring events :)

------
wheaties
This is very similar to Arrow. Take a look at the arrow project:
<https://github.com/crsmithdev/arrow> You guys did almost the same sort of
thing. Maybe I'm wrong and you've enhanced the functionality set even more but
it could be very well worth your efforts to combine forces.

~~~
andrewcooke
oh, thanks. that looks very good. simpler than this one, i think (at least, i
can understand arrow immediately from that page).

------
buss
I like all of the functionality it provides. Your project is similar in idea
to my own, <https://github.com/sbuss/wtftz>.

I also have a half-working website at <http://wtftz.com> for easy timezone
conversions

------
d0mine
[after reading the very first code example]

There is a better way to write it:

    
    
      from datetime import datetime
      from pytz import timezone, utc
    
      EST = "US/Eastern"
    
      now = datetime.utcnow().replace(tzinfo=utc) # now in UTC
      return now.astimezone(timezone(EST)) # now in EST
    

There is no DST transitions in UTC so localize()/normalize() are unnecessary
here.

The code still is not pretty and error-prone in general but there are already
libraries that wrap it into easy to use interface e.g., times, arrow. They are
better target to compare itself against.

------
trun
I believe someone is working on writing up a more detailed post about this,
but I'll throw the sanetime library out there. It's pretty slick and even has
built in Django support.

<https://github.com/HubSpot/sanetime>
<https://sanetime.readthedocs.org/en/latest/>

~~~
googletron
what do you mean builtin django support? its just times.

~~~
trun
You can use SaneTimeField to store sanetime objects in your Django app.

~~~
googletron
-.-

------
thruflo
From the docs looks like a quality solution to a real faff in python. Kudos.

~~~
googletron
Thanks! I have few of the improvement suggested by others in issues.

So I welcome any feedback people may have :)

------
calpaterson
The combination of datetime, date until and pytz is annoying, but its not
clear from your example whether you're better. Why not try using you example
to show many of the nuanced issues with computers representing time (that many
don't know about) and how your API helps.

For example: is it 5:30 in Phoenix, Arizona?

Sorry, can't look in detail at your API - on my phone.

------
ak217
First, I'd like to encourage the author - please keep iterating and keep the
functionality coming. There is certainly a lot that can be done to make
working with dates easier.

That said, this is just not very impressive right now. The dateutil module is
much more useful: <http://labix.org/python-dateutil>

~~~
googletron
I appreciate the encouragement. What would be much more useful is some actual
feedback. :)

I have baked in some of the niceties of dateutil into Delorean, such as rrule
and parse.

~~~
jessaustin
Please don't make it too much like dateutil; using that module requires too
much doc study. I usually end up just building a few functions from scratch
that do precisely what I want with datetime alone.

~~~
googletron
Which is the reason I abstracted many of the more complex features into
easier, less complex and easily groked API.

------
joiguru
I think times is a much more idiomatic and simple library to understand and
use. Has one simple principle. Store all date as utc and convert to/from
user's timezone only at the time of presentation.

<https://github.com/nvie/times/>

------
stuaxo
Arrow looks really good for this sort of thing, it's based on momentjs, which
is very very nice.

[Edit add link] <https://github.com/crsmithdev/arrow>

------
robbles
This is great! I recently worked on a feature that had to do some funny time
zone conversions - having this lib definitely would have helped.

------
majke
Not to be confused with this Delorean: <https://github.com/bebanjo/delorean>

------
ChrisArchitect
vote up if you came here wanting to know what the BTTF connection was

