Reputation: 323
OK, so my code has worked good until the day became Sunday.
I'm working on an app that uses the Calendar util allot, so it functioning the way i think it does is important to me! The problem:
import java.util.Calendar;
...
Calendar test = Calendar.getInstance();
test.setFirstDayOfWeek(Calendar.MONDAY);
Log.e("WEEEK TEST:", ""+ test.get(Calendar.WEEK_OF_YEAR));
test.add(Calendar.WEEK_OF_YEAR, 1);
Log.e("WEEEK TEST:", ""+ test.get(Calendar.WEEK_OF_YEAR));
Outputs this:
06-01 14:04:07.636 12005-12005/test.app E/WEEEK TEST:﹕ 23
06-01 14:04:07.636 12005-12005/test.app E/WEEEK TEST:﹕ 23
How can this even happen, and how do i fix it?
Upvotes: 1
Views: 2075
Reputation: 323
Calendar test = Calendar.getInstance();
test.add(Calendar.WEEK_OF_YEAR, -1);
test.add(Calendar.WEEK_OF_YEAR, 1);
test.setFirstDayOfWeek(Calendar.MONDAY);
Now "test" should work correctly
Upvotes: 1