Scrivio Interview library
DesignIntermediate8 min read · updated 12 November 2026

Billing must find the due date as the 10th business day of the next month in the customer's country, skipping weekends and public holidays that differ per country. Design this with java.time and explain how you test it.

We model the rule as a TemporalAdjuster, for example BusinessDays.nth(10, calendar), that starts at the first day of next month and counts forward only days that are neither weekend days nor public holidays for the customer's country. Weekends and holidays come from a versioned HolidayCalendar per country, all the counting happens in LocalDate, and only at the end do we turn the due date into an Instant using the customer's zone and cut-off time. We test it with parameterized cases over tricky months plus property tests, and we store which calendar version produced each due date.

Why this question is asked

Due dates look like a small detail until a customer in another country is charged a late fee on a day their banks were closed. Billing rules like this one touch money, regulation and customer trust, so the design must be correct, explainable and auditable years later. Interviewers ask it because it combines java.time knowledge with modelling skill. In this answer, we will recap the java.time pieces we need, design the adjuster and the calendar interface, decide where time zones enter, plan the tests, and look at versioning the holiday data for audits.

1A Quick Recap of the Building Blocks

A business day is a day on which banks and offices work. For our purposes it is any day that is not a weekend day in that country and not a public holiday in that country. Both parts vary. Most countries rest on Saturday and Sunday, but several countries in the Middle East use Friday and Saturday, and the set of public holidays is different everywhere, including moving holidays such as Easter and holidays that are declared at short notice.

In java.time, LocalDate represents a calendar date with no time and no zone, which is exactly what a due date is in the customer's mind: the 14th of the month, not a millisecond. A TemporalAdjuster is a function from one date to another that we apply with date.with(adjuster). The JDK already gives us TemporalAdjusters.firstDayOfNextMonth(), which is our starting point.

2Designing the HolidayCalendar

The calendar answers one question: is this date a business day in this country? We put it behind an interface so that the counting logic never knows where the data comes from, and so that tests can supply a tiny fake calendar.

Java
public interface HolidayCalendar {
String country(); // "DE", "AE", ...
String version(); // "DE-2026.3", recorded with each due date
Set<DayOfWeek> weekend(); // {SATURDAY, SUNDAY} or {FRIDAY, SATURDAY}
boolean isHoliday(LocalDate date);
default boolean isBusinessDay(LocalDate date) {
return !weekend().contains(date.getDayOfWeek()) && !isHoliday(date);
}
}
// Production implementation: loaded from a table we maintain or import
// (country, date, name, source, version), cached per country and year.

The holiday data is data, not code. We keep it in a table that operations staff can update, importing from a trusted source and reviewing changes, because governments add holidays with weeks of notice and we cannot wait for a release. Each published change produces a new version string for that country. Notice that weekend() is part of the calendar too; hard-coding Saturday and Sunday in the counting code would quietly give wrong answers for a whole group of countries.

3The Adjuster That Finds the Nth Business Day

With the calendar in place, the rule itself is short. We move to the first day of next month, then walk forward day by day, counting only business days, until we reach the tenth. The first day of the month counts if it is itself a business day, which is the usual reading of the 10th business day of the month.

Java
public final class BusinessDays {
public static TemporalAdjuster nth(int n, HolidayCalendar cal) {
if (n < 1) throw new IllegalArgumentException("n must be >= 1");
return t -> {
LocalDate d = LocalDate.from(t).with(TemporalAdjusters.firstDayOfNextMonth());
int counted = cal.isBusinessDay(d) ? 1 : 0;
while (counted < n) {
d = d.plusDays(1);
if (cal.isBusinessDay(d)) counted++;
}
return d;
};
}
}
LocalDate invoiceDate = LocalDate.of(2026, 11, 20);
LocalDate due = invoiceDate.with(BusinessDays.nth(10, germany));
// December 2026 in Germany: Tue 1 is day 1, so the 10th business day is 2026-12-14
Step throughFinding the 10th business day of next month
  1. Invoice date in the customer's zoneLocalDate, e.g. 2026-11-20
  2. Move to the first day of next month
  3. Weekend day or holiday for this country?
    Yesdo not count itNocount it
  4. Counted 10 days?
    Yesthis is the due dateNomove one day forward and check again
  5. Convert to an Instant deadlineatTime(cut-off).atZone(customer zone).toInstant()

5 steps in order. Play them, or step through them one at a time.

Because java.time values are immutable, every step returns a new date that we assign. Because the adjuster is pure, given the same input date and the same calendar version it always returns the same answer, which is what makes the result reproducible in an audit.

4Where Time Zones Enter, and Where They Must Not

All counting happens on LocalDate, in the customer's zone. The first step, though, needs care: the invoice was created at some Instant, and which month it belongs to depends on the zone. An invoice created at 23:30 UTC on 31 October is already 1 November in Tokyo, so next month is December there and November in London. We therefore convert the creation Instant to a LocalDate with the customer's ZoneId before applying the adjuster.

Only at the very end do we turn the due date into a moment in time. The business usually says payment is due by a cut-off, such as 17:00 local time. We compute due.atTime(LocalTime.of(17, 0)).atZone(zone).toInstant() and store that Instant as the deadline that the late-fee job compares against. Keeping LocalDate for the calendar logic and Instant for the machine deadline means a daylight saving change can never shift the count by a day, and the deadline is still a precise, comparable value.

5Testing It So We Can Trust It

We test with a small, readable fake calendar and with the real calendars. The parameterized tests list known months and their expected answers, chosen to hit the hard cases: a month that starts on a holiday, December with Christmas and the year end, a leap February, a cluster of holidays such as Good Friday and Easter Monday, and a country whose weekend is Friday and Saturday. Here DE uses only the national German holidays; regional holidays would make a separate calendar.

Java
@ParameterizedTest
@CsvSource({
"2026-11-20, DE, 2026-12-14", // December starts on a Tuesday, no holiday before day 10
"2026-12-05, DE, 2027-01-15", // year end: 1 January is a holiday and a Friday
"2026-03-10, DE, 2026-04-16", // Easter cluster: Good Friday 3 Apr, Easter Monday 6 Apr
"2028-01-15, DE, 2028-02-14", // leap-year February
"2026-11-20, FS, 2026-12-14" // test calendar with a Friday-Saturday weekend
})
void tenthBusinessDay(LocalDate invoice, String country, LocalDate expected) {
assertEquals(expected, invoice.with(BusinessDays.nth(10, calendars.get(country))));
}

The expected values in such a table must come from someone checking a real calendar, not from running the code, otherwise the test only proves the code agrees with itself. Next to the examples we add property tests that run thousands of random invoice dates and assert general truths: the result is always a business day, it is always in the next month or later, there are exactly nine business days between the first of the month and the result, and the result never moves earlier when a holiday is added. Finally, the whole pipeline uses an injected Clock, so tests of the billing job can pin today to any date we like.

6Versioning Holiday Data for Audits

Holiday data will change after invoices have been issued, for example when a government declares a one-off holiday. If we recompute due dates on the fly, a customer's due date could move after they were told it, and we could no longer explain an old late fee. So we compute the due date once, at invoice time, and store it together with the calendar version that produced it, such as DE-2026.3. An auditor can then reproduce the exact result by loading that version, and support staff can answer why the date was the 14th and not the 15th.

7Follow-up questions

What happens to already issued invoices when holiday data changes?

By default nothing: the stored due date stays, because it was communicated to the customer and may already appear on a printed invoice. What we do is run a report of open invoices whose due date would differ under the new calendar version. The business then decides on a policy, and usually the fair one is to move a date later when a new holiday makes the old date a non-working day, and never to move it earlier. Any change is applied as a recorded event with the new calendar version, so the history stays complete.

Why not just use a library for holidays?

We can use a library or a public data source as the input to our calendar, but we should still put it behind our own HolidayCalendar interface and keep a versioned copy. The billing result must be stable and explainable, and we cannot let a dependency upgrade silently change due dates on the next deployment.

8Conclusion

In this answer, we designed the due-date rule as a TemporalAdjuster that starts at the first day of next month and counts days that are business days according to a per-country HolidayCalendar, which knows both the weekend days and the holidays. We kept all counting in LocalDate in the customer's zone and created an Instant deadline only at the end with the cut-off time. We tested with checked examples over hard months and with property tests, and we stored the calendar version with each due date so that results stay stable and auditable when holiday data changes.

What to say in the interviewAbout 100 seconds aloud

Open with

I would separate the rule from the data. The data is a HolidayCalendar interface per country with two things: which days of the week are the weekend, since some countries rest on Friday and Saturday, and which dates are public holidays.

Then, if they want more

The production implementation loads them from a table we maintain or import, and every change gets a version. The rule is a TemporalAdjuster, something like BusinessDays.nth(10, calendar): it moves to the first day of next month and walks forward, counting only days the calendar says are business days, until it reaches ten.

I do all of that in LocalDate in the customer's own time zone, so I first convert the invoice timestamp to a LocalDate with their ZoneId, because the month can differ by zone.

Only at the end I turn the due date into an Instant with the cut-off time, using atTime and atZone, and that Instant is what the late-fee job compares.

For testing I would use parameterized tests with expected values someone checked by hand on real calendars, covering year ends, leap years, months starting on a weekend and holiday clusters like Easter, plus property tests that the result is always a business day with exactly nine business days before it in the month.

And I would store the calendar version with every computed due date, so an auditor can reproduce it and we never silently move a date the customer was already told.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Billing must find the due date as the 10th business day of the next month in the...": https://scrivio-interview-library.netlify.app/java/date-and-time/8ea57aa913/