Skip to content

Adding duration in months to a TimePoint can give incorrect result for 31st of month #250

@MetRonnie

Description

@MetRonnie

Correct:

>>> TimePoint(year=2023, month_of_year=7, day_of_month=31) + Duration(months=1)
2023-08-31

Also correct (last day of month):

>>> TimePoint(year=2023, month_of_year=8, day_of_month=31) + Duration(months=1)
2023-09-30

Incorrect:

>>> TimePoint(year=2023, month_of_year=8, day_of_month=31) + Duration(months=2)
2023-10-30 

(should be 2023-10-31)

This will probably need similar re-work as done in #234

See

if duration._months:
# This is the dangerous one...
new = new.add_months(duration._months)

def add_months(self, num_months: int) -> 'TimePoint':
"""Return a copy of this TimePoint with an amount of months added to
it."""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions