How can I get the next friday with the Joda-Time API.
The LocalDate
of today is today
. It looks to me you have to decide whever you are before or after the friday of the current week. See this method:
private LocalDate calcNextFriday(LocalDate d) {
LocalDate friday = d.dayOfWeek().setCopy(5);
if (d.isBefore(friday)) {
return d.dayOfWeek().setCopy(5);
} else {
return d.plusWeeks(1).dayOfWeek().setCopy(5);
}
}
Is it possible to do it shorter or with a oneliner?
PS: Please don't advise me using JDKs date/time stuff. Joda-Time is a much better API.
Java 8 introduces java.time package (Tutorial) which is even better.
DateTime
could use arollForwardTo(...)
method – TrapaniInterval
class found in Joda-Time. So use each for its strengths. You can mix and match within a project. Just be careful with yourimport
statements as a few of their classes share the same name. – CallimachusInterval
andLocalDateRange
. – Callimachus