Basically, in the method below, for reasons unknown to myself or my team, the outermost for loop will does not execute any code on the first itteration. What I mean by that is, on the first round of execution it goes to the end of the loop and back to the beginning without executing any code. I have confirmed this by debugging through eclipse. However, the loop executes as normal after this first cycle.
What this method is doing is pulling days from a database, putting them into weeks, and putting those weeks into a month. but, because of this weird "glitch" the first cycle does not pull any days and subsequently does not create a week to be put in the month BUT it does execute the counter of the loop which basically leaves the data out off sync with the loop:
1st run: nothing
2nd run: 1st week
3rd run: 2nd week
...
last run: SECOND LAST WEEK
so, everythime the method returns the month, the last week is always missing.
BUT what is really WEIRD is that this loop used to work perfectly. In fact, I am 99.9999% positive that it was functioning before I went home last night and then when I came in today it suddenly developed this error. The only reason that I have that tiny amount of doubt is that IT MAKES ABSOLUTELY NO SENSE FOR THAT TO BE THE CASE! So realistically I must have accidently changed something and not realised it. If anyone could thake a look at this and suggest a possible cause that would be very much appreciated.
Thanks
private Month translateToFormData(List<WeekEntry> weekList, TimeSheetForm timeSheetForm) {
int monthOfInterest = timeSheetForm.getMonth().getMonthOfYear();
// month to be returned
Month month = new Month();
// Calendars to translate from Date to Calendar
// loop through weekList
for (WeekEntry weekEntry : weekList) {
// week value to be filled
Week week = new Week();
Calendar calWeekBeginning = new GregorianCalendar();
// set the date of the first day in "week" (Sunday)
calWeekBeginning.setTime(weekEntry.getWeekBeginning());
week.setWeekBeginning(calWeekBeginning);
Set<DayEntry> daySet = weekEntry.getDays();
// Loop through days of the weekList items
for (DayEntry dayEntry : daySet) {
// day value to be filled
Day day = new Day();
Calendar calDateOfDay = new GregorianCalendar();
// set the date of the day
calDateOfDay.setTime(dayEntry.getDateOfDay());
day.setDate(calDateOfDay);
// set the hours of the day
day.setWorkHours(dayEntry.getHours());
// define the day type
if (calDateOfDay.get(Calendar.MONTH) != monthOfInterest) {
day.setType(DayType.BLANK_DAY);
} else if (calDateOfDay.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calDateOfDay.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
day.setType(DayType.WEEK_END);
} else {
day.setType(DayType.WEEK_DAY);
}
// add the day to the week
week.addDay(day);
}
// add the week to the month
month.addWeek(week);
}
return month;
}
weekListobject. Verify if the collection has correct/expected values.