if (calFilter.isShowBreaks() == true) {
if (lastStopTime != null
&& DateHelper.isSameDay(stopTime, lastStopTime) == true
&& startTime.getMillis() - lastStopTime.getMillis() > 60000) {
// Show breaks between time sheets of one day (> 60s).
final Event breakEvent = new Event();
breakEvent.setEditable(false);
final String breakId = String.valueOf(++breaksCounter);
breakEvent.setClassName(BREAK_EVENT_CLASS_NAME).setId(breakId).setStart(lastStopTime).setEnd(startTime)
.setTitle(getString("timesheet.break"));
breakEvent.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9");
events.put(breakId, breakEvent);
final TimesheetDO breakTimesheet = new TimesheetDO().setStartDate(lastStopTime.toDate()).setStopTime(startTime.getMillis());
breaksMap.put(breakId, breakTimesheet);
}
lastStopTime = stopTime;
}
final long duration = timesheet.getDuration();
final MyEvent event = new MyEvent();
final String id = "" + timesheet.getId();
event.setClassName(EVENT_CLASS_NAME);
event.setId(id);
event.setStart(startTime);
event.setEnd(stopTime);
final String title = getTitle(timesheet);
if (longFormat == true) {
// Week or day view:
event.setTitle(title + "\n" + getToolTip(timesheet) + "\n" + formatDuration(duration, false));
} else {
// Month view:
event.setTitle(title);
}
if (month != null && startTime.getMonthOfYear() != month && stopTime.getMonthOfYear() != month) {
// Display time sheets of other month as grey blue:
event.setTextColor("#222222").setBackgroundColor("#ACD9E8").setColor("#ACD9E8");
}
events.put(id, event);
if (month == null || startTime.getMonthOfYear() == month) {
totalDuration += duration;
addDurationOfDay(startTime.getDayOfMonth(), duration);
}
final int dayOfYear = startTime.getDayOfYear();
addDurationOfDayOfYear(dayOfYear, duration);
event.setTooltip(
getString("timesheet"),
new String[][] {
{ title},
{ timesheet.getLocation(), getString("timesheet.location")},
{ KostFormatter.formatLong(timesheet.getKost2()), getString("fibu.kost2")},
{ TaskFormatter.instance().getTaskPath(timesheet.getTaskId(), true, OutputType.PLAIN),
getString("task")},
{ timesheet.getDescription(), getString("description")}});
}
}
if (calFilter.isShowStatistics() == true) {
// Show statistics: duration of every day is shown as all day event.
DateTime day = start;
final Calendar cal = DateHelper.getCalendar();
cal.setTime(start.toDate());
final int numberOfDaysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
int paranoiaCounter = 0;
do {
if (++paranoiaCounter > 1000) {
log.error("Paranoia counter exceeded! Dear developer, please have a look at the implementation of buildEvents.");
break;
}
final int dayOfYear = day.getDayOfYear();
final long duration = durationsPerDayOfYear[dayOfYear];
final boolean firstDayOfWeek = day.getDayOfWeek() == PFUserContext.getJodaFirstDayOfWeek();
if (firstDayOfWeek == false && duration == 0) {
day = day.plusDays(1);
continue;
}
final Event event = new Event().setAllDay(true);
final String id = "s-" + (dayOfYear);
event.setId(id);
event.setStart(day);
final String durationString = formatDuration(duration, false);
if (firstDayOfWeek == true) {
// Show week of year at top of first day of week.
long weekDuration = 0;
for (short i = 0; i < 7; i++) {
int d = dayOfYear + i;
if (d > numberOfDaysInYear) {
d -= numberOfDaysInYear;
}
weekDuration += durationsPerDayOfYear[d];
}
final StringBuffer buf = new StringBuffer();
buf.append(getString("calendar.weekOfYearShortLabel")).append(DateHelper.getWeekOfYear(day));
if (days > 1 && weekDuration > 0) {
// Show total sum of durations over all time sheets of current week (only in week and month view).
buf.append(": ").append(formatDuration(weekDuration, false));
}
if (duration > 0) {
buf.append(", ").append(durationString);
}
event.setTitle(buf.toString());
} else {
event.setTitle(durationString);
}
event.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9");
event.setEditable(false);
events.put(id, event);
day = day.plusDays(1);
} while (day.isAfter(end) == false);
}
}