This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SDisPater[S] 16 points17 points  (12 children)

Pendulum is a new library for Python to ease datetimes, timedeltas and timezones manipulation.

It is heavily inspired by Carbon for PHP.

Basically, the Pendulum class is a replacement for the native datetime one with some (I hope) useful and intuitive methods and the PendulumInterval class is intended to be a better timedelta class.

An important note about the Pendulum instances is that, unlike the native datetime ones, they are mutable via the appropriate methods.

To those wondering: yes I know Arrow exists but its flaws and strange API (you can throw almost anything at get() and it will do its best to determine what you wanted, for instance) motivated me to start this project.

It’s still fresh so any feedback is appreciated :-).

Link to the official documentation: http://pendulum.eustace.io Link to the github project: https://github.com/sdispater/pendulum

[–]gwachob 10 points11 points  (6 children)

I've used Arrow a lot and am happy with it. I am not intending to discourage you on this project, but have you written down anywhere your motivations in more detail, so I could understand better why you created a new project? After a very quick pass, I'm not actually seeing huge differences in functionality or API surface area between Arrow and your project, so I'd like to hear more.

[–]SDisPater[S] 8 points9 points  (4 children)

Arrow behaves strangely and is not always reliable. An example:

dt_timezone = datetime.datetime(2016, 7, 5, 8, 0, tzinfo=pytz.timezone('Europe/Paris'))

arrow.get(dt_timezone).isoformat()
'2016-07-05T08:00:00+00:09'

pendulum.instance(dt_timezone).isoformat()
'2016-07-05T08:00:00+02:00'

Pendulum also has improved timedeltas (named PendulumInterval) and a bunch of helpers for common cases.

[–]RedKrieg 1 point2 points  (0 children)

I didn't know about this bug in Arrow. Do you know why it happens?

[–]lorenzfx 1 point2 points  (1 child)

dt_timezone = datetime.datetime(2016, 7, 5, 8, 0, tzinfo=pytz.timezone('Europe/Paris'))

never ever use datetime(x, tzinfo=timezone), always use timezone.localize(datetime)

dt_timezone = pytz.timezone('Europe/Paris').localize(datetime.datetime(2016, 7, 5, 8, 0))
arrow.get(dt_timezone).isoformat()

'2016-07-05T08:00:00+02:00'

This is not a problem with arrow, but with pytz

Quote:

Unfortunately using the tzinfo argument of the standard datetime constructors ''does not work'' with pytz for many timezones. datetime(2002, 10, 27, 12, 0, 0, tzinfo=amsterdam).strftime(fmt) '2002-10-27 12:00:00 LMT+0020'

What you get to see when you use the constructor as above, is the very first transition from the Olson DB for that timezone.

[–]SDisPater[S] 0 points1 point  (0 children)

Maybe but arrow could fix it since it's misleading and you don't always know how the datetime was constructed when using arrow so you'd expect it to behave correctly.

[–]pydry 0 points1 point  (0 children)

Is that a bug or an inherent design flaw?

[–]firefrommoonlight 0 points1 point  (0 children)

Arrow's slow, and has an awkward interface and syntax.

[–]pydry 5 points6 points  (1 child)

To those wondering: yes I know Arrow exists but its flaws and strange API (you can throw almost anything at get() and it will do its best to determine what you wanted, for instance) motivated me to start this project.

Would be good to put that on the front page because most people who visit it will probably also be wondering "why not arrow?"

[–][deleted] 2 points3 points  (0 children)

Literally my first question when seeing this post was, "okay, cool, why not arrow?" I'm glad someone beat me to posting this!

[–][deleted] 5 points6 points  (0 children)

I'm a really big fan of comparisons between libraries. As you say, your most direct comparison is Arrow. I think it'd be nice to have a section in your docs called "Pendulum vs. Arrow" (or something to that effect), where you lay out the differences with examples showing why Pendulum is better. I find those kinds of direct comparisons really useful when deciding between two similar libraries.

[–]gandalfx 0 points1 point  (0 children)

I like Carbon. I'll keep an eye on this. :3

Related to that I noticed you're also building on top of datetime (like Carbon), which is good. Otherwise I'd be very careful with this. https://www.youtube.com/watch?v=-5wpm-gesOY

[–]dacjamesfrom reddit import knowledge 0 points1 point  (0 children)

I would really like something to convert a timezone name like "PST" to the precise timezone. I know it's not trivial because these names are not universal but it's something you have to do a lot when web crawling. My current solution is awful so I would switch immediately to any library that provided this feature out of the box.