Delorean – datetime conversions in Python
delorean.readthedocs.org
delorean.readthedocs.org
`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.
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 Future" series.
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.)
Unlike calling 'pickle' to serialize...
In other words why this sentence could be wrong: Timezones are a presentation-layer problem! http://news.ycombinator.com/item?id=5083321
http://infiniteundo.com/post/25326999628/falsehoods-programm...
The point is actually that it's not presentational at all. Time is far, far more complicated than your link implies; just read the comments in the HN thread: they're full of explanations for why it's oversimplifying.
Also, see: http://en.wikipedia.org/wiki/Time_standard
The essential problem comes down to the assumption that "a second" is a well-defined unit of measurement. The Wikipedia article sums it up nicely.
For applications like the vast majority of customer-facing web stuff? We rarely care about anything more precise than a minute, if that. It makes sense to isolate stuff into the presentation layer here, since the backend generally deals in milliseconds for logging anyways. But you can't generalize "customer-facing web stuff" into "anything a general purpose programming language might be used for": some of those things really care about the exactness of time and a specific time standard.
I also have a half-working website at http://wtftz.com for easy timezone conversions
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.
https://github.com/HubSpot/sanetime https://sanetime.readthedocs.org/en/latest/
So I welcome any feedback people may have :)
For example: is it 5:30 in Phoenix, Arizona?
Sorry, can't look in detail at your API - on my phone.
That said, this is just not very impressive right now. The dateutil module is much more useful: http://labix.org/python-dateutil
I have baked in some of the niceties of dateutil into Delorean, such as rrule and parse.
[Edit add link] https://github.com/crsmithdev/arrow