I'm trying to use either Calendar or Gregorian Calendar to iterate and create a date grid. However, both of them seem to think that August, 2010 has 30 days, and that September 2 and 3 are weekends. It's as if the calendar has the wrong year, but I've tripple-checked that parameter. Here are some excerpts.
startDate.set(2010, 8, 28);
SchedulerCalendar currentDate = (SchedulerCalendar) startDate.clone();
for(int i = 0; i<daysDisplayed; i++){
newDate = new TextView(this);
String dateString = currentDate.get(Calendar.MONTH)+"/"+currentDate.get(Calendar.DATE);
//+"/"+currentDate.get(Calendar.YEAR);
newDate.setText(dateString);
newDate.setId(i+1);
newDate.setWidth(blockWidth);
newDate.setHeight(DATE_HEIGHT);
dateBar.addView(newDate);
currentDate.add(Calendar.DATE, 1);
}
private class SchedulerCalendar extends GregorianCalendar {
@Override
public void add(int field, int value) {
super.add(field, value);
if(this.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY) {
if(value>=0) super.add(Calendar.DATE, 2);
if(value<0) super.add(Calendar.DATE, -1);
}
if(this.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY) {
if(value>=0) super.add(Calendar.DATE, 1);
if(value<0) super.add(Calendar.DATE, -2);
}
}
}