Live data from Hacker News

Delorean – datetime conversions in Python

delorean.readthedocs.org

31–40 of 42 posts

Re: Delorean – datetime conversions in Python

#32
post #31

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/

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

Re: Delorean – datetime conversions in Python

#33
post #4

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…

So the library does a little bit more than just deal with shifting timezones which as you put can be a little annoying. I would take a look at the docs and see what else the library can provide before you start quoting the interface incorrectly. :) As for the name I considered other things most lead to namespace pollution. You are right I might be able to clear up the reference for people who dont know "Back to the F…

Aren't you worried that someone, somewhere might actually still own the rights to that trademark, and might, one day, come to you and ask for money? After all, you're clearly exploiting the original trademark for your own gain.

I know, I know, we all love an '80s inside-joke, but I think this is just a bit too far.

(great lib btw, datetime has always been a bloody pain, for no good reason.)

Re: Delorean – datetime conversions in Python

#34
post #31

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/

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

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

Re: Delorean – datetime conversions in Python

#35
post #4

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…

It will only be non-descriptive if it doesn't catch on. See, for instance, Django, Pyramid, Twisted, etc. Twisted is a particularly good example, since it shares a similar analogy: Twisted could reference the twisted pair networks use; Delorean references a time-traveling vehicle.

[deleted]

Re: Delorean – datetime conversions in Python

#36
post #4

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 calling 'Delorean' to convert times is totally obscure Unlike calling 'pickle' to serialize...

And if i were on the mailing lists back whenever they came up with pickle, i would have told them it was a silly name too.

Re: Delorean – datetime conversions in Python

#38
[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.

Post reply on HN