Skip to content

Instantly share code, notes, and snippets.

@KirkWylie
Created March 14, 2011 14:50
Show Gist options
  • Save KirkWylie/869242 to your computer and use it in GitHub Desktop.
Save KirkWylie/869242 to your computer and use it in GitHub Desktop.
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