@Webcyberrob okay logic has been added for this with some syntax updates for expanded usage.
Can you give me a few more scenarios that you deal with?
val bc = StdBusinessCalendar(
listOf(
Holiday(listOf("2020-06-24", "2020-06-25", "2020-06-26")), // Cannot be any of these dates
Is(weekday()), // Must be a weekday (no weekends)
Is(weekend().negate()), // example of saying "not a weekend"
IfIs(weekday(), betweenHours("09:00", "17:30")) {
// Standard workweek, but if something comes in at or after 16:30 (one hour less than regular business hours) then we will just go to next day. (can see how you can add extra special logic where needed).
if (it.toLocalTime().isBefore(LocalTime.of(16, 30))) {
Duration.ofMinutes(1)
} else {
Duration.ofDays(1)
}
},
IfIs(date("06-29"), betweenHours("10:00", "12:30")) {
// modification to a standard work week with a partial day
if (it.toLocalTime().isBefore(LocalTime.of(12, 30))) {
Duration.ofMinutes(1)
} else {
// If it is already past 12:30 then go to next day
Duration.ofDays(1)
}
},
Holiday(listOf("2020-06-23"))
)
)
bc.nextAvailableDateDayIncrement(now, 10, true).get() // the boolean indicates if the calculation should start +1 days from the provided date.
bc.nextAvailableDate(now).get()
bc.isAvailableDate(now)
The first two return optionals for more complex configurations at the calendar level (such as max attempts to find a date, date must be in this year, within 6 months, etc)
Can add other increment options but more common is increment by days: So if you had a now
of June 1 2020 6am, and said increment 10 business days it would give you either June 12 9am or June 15 9am (depends on your usage of the boolean in .nextAvailableDateDayIncrement(...)
. The boolean deals with a common calculation scenario where you get a submission right now, but your “2 days” starts on the next business day (such as a submission at 5pm on Friday is likely to say Monday and Tuesday are your SLA with delivery on Wed. Again its optional based on needs.
IfIs(...)
means “If the first condition is true, then the second condition must be true”. But if the first is not true, then it still returns as a successful rule. It is another way of saying “here is a sub condition that must be met if the first condition is true, otherwise i dont care.”
Holiday(..)
is a wrapper for saying "Must not be this/these dates`. You can also use MonthDay if you know it is the same dates every year. And of course you can write completely custom logic if needed…
I have been moving through a few iterations of naming conversions ConditionalIf
, IfIs
, Must
, etc. Would love feedback!