Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MetRonnie opened this issue May 21, 2024 · 0 comments
Milestone

Comments

@MetRonnie
Copy link
Contributor

MetRonnie commented May 21, 2024

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."""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant