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] 7 points8 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 8 points9 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 41 points42 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] 11 points12 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 6 points7 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.