https://github.com/HubSpot/sanetime https://sanetime.readthedocs.org/en/latest/
Delorean – datetime conversions in Python
31–40 of 42 posts
Re: Delorean – datetime conversions in Python
#32I 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/
Re: Delorean – datetime conversions in Python
#33I'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…
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
#34I 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
#35I'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.
Re: Delorean – datetime conversions in Python
#36I'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...
Re: Delorean – datetime conversions in Python
#37Re: Delorean – datetime conversions in Python
#38There 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.
Re: Delorean – datetime conversions in Python
#39Re: Delorean – datetime conversions in Python
#40[Edit add link] https://github.com/crsmithdev/arrow