Created
March 14, 2011 14:50
-
-
Save KirkWylie/869242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NextExpiryAdjuster implements DateAdjuster { | |
private static final DateAdjuster s_thirdWedAdjuster = | |
DateAdjusters.dayOfWeekInMonth(3, DayOfWeek.WEDNESDAY); | |
private static final DateAdjuster s_nextQuarterAdjuster = | |
new NextQuarterAdjuster(); | |
private final Set<MonthOfYear> _futureQuarters = | |
Sets.newHashSet(MonthOfYear.MARCH, MonthOfYear.JUNE, | |
MonthOfYear.SEPTEMBER, MonthOfYear.DECEMBER); | |
@Override | |
public LocalDate adjustDate(final LocalDate date) { | |
if (_futureQuarters.contains(date.getMonthOfYear()) && | |
date.with(s_thirdWedAdjuster).isAfter(date)) { | |
// in a quarter | |
return date.with(s_thirdWedAdjuster); | |
} else { | |
return date.with(s_nextQuarterAdjuster).with(s_thirdWedAdjuster); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment