Skip to content

Instantly share code, notes, and snippets.

@Tombarr
Last active September 11, 2018 14:30
Show Gist options
  • Save Tombarr/c183317a46088a2812f81073d3719e5e to your computer and use it in GitHub Desktop.
Save Tombarr/c183317a46088a2812f81073d3719e5e to your computer and use it in GitHub Desktop.
TemporalAdjuster for adjusting a date to the last working business day
public static TemporalAdjuster LAST_WORKING_DAY = TemporalAdjusters.ofDateAdjuster(lastDayOfMonth -> {
int daysToSubtract = Math.max(0, lastDayOfMonth.getDayOfWeek().getValue() - DayOfWeek.FRIDAY.getValue());
return lastDayOfMonth.minusDays(daysToSubtract);
});
// Example Usage
LocalDate.now().with(LAST_WORKING_DAY);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment