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

last day of the month is wrong?? #1167

Closed
hawkEye-01 opened this issue Aug 27, 2021 · 2 comments · Fixed by #1170
Closed

last day of the month is wrong?? #1167

hawkEye-01 opened this issue Aug 27, 2021 · 2 comments · Fixed by #1170

Comments

@hawkEye-01
Copy link

From documentation, it seems to correctly get last day of the month..
How does it handle months with different numbers of days? Notice that adding one month will never cross the month boundary.

>>> date(2003,1,27)+relativedelta(months=+1)
datetime.date(2003, 2, 27)
>>> date(2003,1,31)+relativedelta(months=+1)
datetime.date(2003, 2, 28)
>>> date(2003,1,31)+relativedelta(months=+2)
datetime.date(2003, 3, 31)

I tried,

from datetime import date
print(date(2021, 6, 30) + relativedelta(months=-1))

which gives 2021-05-30. i should have been 2021-05-31.

@Mifrill
Copy link
Contributor

Mifrill commented Aug 29, 2021

Good catch! It's interesting, seems like plus working fine, the point in minus:

>>> date(2021, 5, 31) + relativedelta(months=+1)
datetime.date(2021, 6, 30)
>>> date(2021, 6, 30) + relativedelta(months=-1)
datetime.date(2021, 5, 30)

also:

>>> date(2021, 6, 30) - relativedelta(months=1)
datetime.date(2021, 5, 30)

@Mifrill
Copy link
Contributor

Mifrill commented Aug 29, 2021

hm... probably not only for minus, because of this:

>>> date(2021, 4, 30) + relativedelta(months=1)
datetime.date(2021, 5, 30)

should be datetime.date(2021, 5, 31) I guess

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