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

fix AddMonths for invalid year calculation #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kjaebker
Copy link

If you call AddMonths it sometimes calculates the year incorrectly

For example:

testDate := gDate.NewDate(2022, 7, 1)
newDate := testDate.AddMonths(5)

Returns => 2023-12-01

Should return => 2022-12-01

This patch fixes this year calculation

fix AddMonths for invalid year calculation
@lovung
Copy link
Owner

lovung commented Mar 23, 2022

Thanks. Could you help to add unit test for this case. @kjaebker

if iMonth <= 0 {
iMonth -= _monthsOfYear
if iMonth > _monthsOfYear {
year += iMonth / _monthsOfYear
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if iMonth <= 0 { in case the n is negative (we want to SubMonths).

I think the issue here is when iMonth = 12 * k.

@bkataru
Copy link

bkataru commented Jan 23, 2024

uh is this bot spam? or did the person leak their PAT token

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

Successfully merging this pull request may close these issues.

3 participants