pendulum icon indicating copy to clipboard operation
pendulum copied to clipboard

Month subtraction does not account for years passed

Open mchant opened this issue 4 years ago • 3 comments

  • [X] I am on the latest Pendulum version.
  • [ ] I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: Microsoft Windows 10 64bit
  • Pendulum version: 2.1.2

Issue

Month subtraction works incorrectly. It only subtracts the month value of the second variable from the first variable, and doesn't account for the year.

>>> y=pendulum.datetime(2022,5,1)
>>> x=pendulum.datetime(2020,1,1)
>>> (y-x).months
4

mchant avatar May 11 '21 13:05 mchant

Can this be assigned to me?

shashankks0987 avatar May 15 '21 15:05 shashankks0987

@sdispater

shashankks0987 avatar May 15 '21 15:05 shashankks0987

This appears to be as documented: https://github.com/sdispater/pendulum/blame/master/docs/docs/duration.md#L80

You should be using method (y-x).in_months() if you're trying to get duration in truncated months.

zcnewt avatar Jul 25 '21 17:07 zcnewt