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 ) ; } }
Convert the holiday format from EquivalenceClassTransformer into a date format