/** * Convert the holiday format from EquivalenceClassTransformer into a date format * * @param holiday the date * @return a date String in the format yyyy-MM-dd */ public String convertToReadableDate(Holiday holiday) { DateTimeFormatter parser = ISODateTimeFormat.date(); if (holiday.isInDateForm()) { String month = Integer.toString(holiday.getMonth()).length() < 2 ? "0" + holiday.getMonth() : Integer.toString(holiday.getMonth()); String day = Integer.toString(holiday.getDayOfMonth()).length() < 2 ? "0" + holiday.getDayOfMonth() : Integer.toString(holiday.getDayOfMonth()); return holiday.getYear() + "-" + month + "-" + day; } else { /* * 5 denotes the final occurrence of the day in the month. Need to find actual * number of occurrences */ if (holiday.getOccurrence() == 5) { holiday.setOccurrence( numOccurrences(holiday.getYear(), holiday.getMonth(), holiday.getDayOfWeek())); } DateTime date = parser.parseDateTime(holiday.getYear() + "-" + holiday.getMonth() + "-" + "01"); Calendar calendar = Calendar.getInstance(); calendar.setTime(date.toDate()); int count = 0; while (count < holiday.getOccurrence()) { if (calendar.get(Calendar.DAY_OF_WEEK) == holiday.getDayOfWeek()) { count++; if (count == holiday.getOccurrence()) { break; } } date = date.plusDays(1); calendar.setTime(date.toDate()); } return date.toString().substring(0, 10); } }
public void hello() { StringBuilder buffy = new StringBuilder("\nHello, "); buffy.append(message).append("\n"); for (Holiday holiday : holidays) { buffy.append("Today is "); buffy.append(holiday.getDay()); buffy.append("/").append(holiday.getMonth()).append(". "); buffy.append(holiday.getGreeting()).append(".\n"); } logger.info(buffy); buffy.delete(0, buffy.length()); }