Skip to content

in_months behavior inconsistent in 30-day months #606

Open
@rileyjohngibbs

Description

@rileyjohngibbs
  • 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: macOS 11.6.1
  • Pendulum version: 2.1.2 and 3.0.0a0

Issue

When calculating a diff's in_months method, the following results seem inconsistent:

start end in_months result
2022-01-02 2023-01-01 11
2022-02-02 2023-02-01 11
2022-03-02 2023-03-01 11
2022-04-02 2023-04-01 12
2022-05-02 2023-05-01 11
2022-06-02 2023-06-01 12
2022-07-02 2023-07-01 11
2022-08-02 2023-08-01 11
2022-09-02 2023-09-01 12
2022-10-02 2023-10-01 11
2022-11-02 2023-11-01 12
2022-12-02 2023-12-01 11

It seems that whenever the end date is in one of the months with 30 days (April, June, September, November), if the start date's day of the month is one day later than the corresponding end day of the month, the number of months from in_months is one higher than it "should" be.

Obviously this is a sticky issue because the definition of a "month" is not well defined (it can be any value from 28 to 31 days), but since this behavior doesn't happen with February, the behavior seems inconsistent at the least.

Desired Result

The in_months method should be determined based on the comparison of the day of the month, not the duration of the last month in the interval, which seems to be the root of this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions