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

bug in add method #16

Open
AndroidDesigner opened this issue Jul 8, 2016 · 1 comment
Open

bug in add method #16

AndroidDesigner opened this issue Jul 8, 2016 · 1 comment

Comments

@AndroidDesigner
Copy link

I think there is a bug in add method.
suppose call this method in another class as:
mJalaliCalendar.add(Calendar.MONTH,-1);
and suppose MONTH is "FARVARDIN".
This result in : "amount = -1" and equally amount%12 = -1.
so array index is negative!

@WhiteEglantine
Copy link

I also faced this bug and fixed it:
if (field == MONTH) {
int month;
if (amount < 0) {
add(YEAR, (amount / 12)-1);
month = get(MONTH) + 12 + amount;
} else {
amount += get(MONTH);
add(YEAR, amount / 12);
month = amount % 12;
}
super.set(MONTH, month);
if (get(DAY_OF_MONTH) > jalaliDaysInMonth[month]) {
super.set(DAY_OF_MONTH, jalaliDaysInMonth[month]);
if (get(MONTH) == 11 && isLeepYear(get(YEAR))) {
super.set(DAY_OF_MONTH, 30);
}
}
complete();
}

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

2 participants