Hacker News new | ask | show | jobs
by antar 3592 days ago
arrow.get(value).humanize()

How can I do this with datetime+dateutil+pytz?

1 comments

I was talking about delorean and pendulum (I think josefdlange edited his comment). I agree that arrow's multi-locale natural language renderer does add a lot of value. (Although I'd argue it should be unbundled into its own module, instead of Arrow trying to replace a ton of datetime/dateutil functionality.)
> I agree that arrow's multi-locale natural language renderer does add a lot of value. Although I'd argue it should be unbundled into its own module

http://babel.pocoo.org/en/latest/api/dates.html

humanize is apparently a human-readable directioned delta, so that'd be format_timedelta(delta, add_direction=True)

    >>> print format_timedelta(ref - datetime.now(), add_direction=True)
    1 hour ago
    >>> print format_timedelta(ref - datetime.now(), add_direction=True, locale='zh')
    1小时前
    >>> print format_timedelta(ref - datetime.now(), add_direction=True, locale='ru')
    1 час назад
No editing here but that's okay. I only just came back to this conversation now :D

I think Delorean, Pendulum, Arrow, etc, aim to make dealing with dates more understandable and less painful. It's perfectly possible to fully grasp all the technicalities of pytz/dateutil/datetime -- and I recommend that anybody who has to deal with dates and times in Python do so -- but if you'd rather not think about it all and are okay with deferring some control to the opinions of one of these libraries, that's when you probably pull them off the shelf instead of the aforementioned trio.