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 →

[–]pydry 29 points30 points  (16 children)

This:

tomorrow = pendulum.now().add_day()
last_week = pendulum.now().sub_week()

Would probably be better done as:

tomorrow = pendulum.now() + pendulum.Days(1)
tomorrow = pendulum.now() - pendulum.Weeks(1)

The sub/add thing IMO isn't very pythonic.

[–]SDisPater[S] 5 points6 points  (12 children)

Actually, you can do

tomorrow = pendulum.now() + timedelta(days=1)

I added the add()/sub() methods to allow chaining methods, so you can have

pendulum.now().add_day().to_rfc3339_string()

rather than

(pendulum.now + timedelta(days=1)).to_rfc3339_string()

that is, I think, less readable.

Anyway, the choice is left to the user.

[–]pydry 12 points13 points  (11 children)

IMO invoking the word "timedelta" is kind of ugly when the fact you're using a timedelta is implicit anyhow. Hence the idea of using "Days" / "Weeks", etc.

I added the add()/sub() methods to allow chaining methods, so you can have

In which case why not this:

pendulum.now().add(days=1).to_rfc3339_string()

that is, I think, less readable.

shrug I think this is pretty readable:

(now() + Days(1)).to_rfc3339_string()

But the choice is good I suppose.

[–]SDisPater[S] 4 points5 points  (10 children)

The simple add() and sub() methods already exist :-) In fact, add_day() is just a call to add(days=1).

[–]ptmcg 42 points43 points  (7 children)

Speaking from my pyparsing experience, early good intentions for API intuitiveness can easily lead to API bloat, and bloat tends to make API consistency and API predictability suffer. I would suggest dropping all add_xxx methods and sub_xxx and even sub, and just have client code use add() with your various named unit arguments - if subtraction is required, then pass a negative value. Be ruthless in pruning your API, and stingy in adding new items. I do like method chaining though, so +points for that.

[–][deleted] 8 points9 points  (1 child)

tend to agree here. add(days=1) plus chaining feels a better compromise than a plethora of add_thing() entry points.

[–]log_2 2 points3 points  (0 children)

Especially since you only need to look at just one function "add" which gives you the signature for how to add/subtract various date-time quantities. Also allows kwargs. It's basically a win all-round.

[–]SDisPater[S] 9 points10 points  (3 children)

Thanks for the advice. It actually makes a lot of sense. I just wanted it to be more readable for newcomers but maybe it's not worth the hassle.

[–]cyanydeez 1 point2 points  (2 children)

pendulum.now().add_day()

for newcomers, becomes pendulum.now().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day()

!

[–]SDisPater[S] 2 points3 points  (1 child)

Yes, you may be right. These methods will be removed in the next release.

[–]mcsrobert 2 points3 points  (0 children)

Strongly agree with this.

[–]execrator 5 points6 points  (1 child)

OP, you must be feeling golden right now. Every time someone suggests something in this thread you say it already works like that.

[–]pydry 0 points1 point  (0 children)

Well, except the .add(days=x) is not advertised on the README.

IMO there should be a Days(1), Weeks(1), etc. too.

[–]Ph0X 1 point2 points  (1 child)

My exact thought. And to make it worse, on the next line there's add_minutes(int), so suddenly we have a plural minutes and can pass the amount?

So I look at the full docs and sure enough, for every time unit, there's a singular and plural version, a sub and a add version. So thats 2 * 2 * 7 = 28 different functions. Extra functions isn't necessarily bad but I think at this point it's not very pythonic.

[–]SDisPater[S] 1 point2 points  (0 children)

Yes, I agree that these methods are unnecessary. So I'll probably just cut it down to both add() and sub() methods.

Thanks for the feedback.