Scrivio Interview library
DesignIntermediate7 min read · updated 12 November 2026

You are designing the date and time handling for a booking service: guests book hotel nights, check-in is 15:00 local time, and payments record when they happened. Which java.time types do you store and expose, and why?

Hotel nights are calendar dates in the hotel's zone, so a booking stores a LocalDate range (check-in date inclusive, check-out date exclusive), and each hotel stores its ZoneId. The 15:00 check-in is a LocalTime that we combine with the date and the hotel's zone only when we need an exact moment. Payments record when they happened as an Instant, converted to local time only for display. We never store future local times only as Instants, because zone rules can change before the date, and APIs exchange ISO-8601 strings with explicit offsets or zone IDs.

Why this question is asked

A booking service mixes three different kinds of time: calendar dates that a guest chooses, local clock times that a hotel publishes, and moments when something happened. Using one type for all of them, typically a timestamp in UTC, leads to nights that shift by a day for guests in another country, check-in times that move after a government changes its DST rules, and reports that disagree. Interviewers ask this design question to see whether we can match each requirement to the right type and explain why. In this answer, we will model the nights, the check-in time and the payments in turn, look at why future local times should not be stored as instants, design the API format, and handle the day the clocks change.

1Hotel Nights Are Calendar Dates

A hotel night is not a 24-hour interval. It is a date on the hotel's calendar: the night of 20 December in Lisbon is the same night for the guest whether they booked from Tokyo or New York. So a booking stores LocalDate values. The usual model is a half-open range: the check-in date is included and the check-out date is not, so a stay from 20 to 23 December is three nights, and back-to-back bookings meet without overlapping.

Java
record Stay(LocalDate checkIn, LocalDate checkOut) {
Stay {
if (!checkOut.isAfter(checkIn)) throw new IllegalArgumentException("at least one night");
}
long nights() { return ChronoUnit.DAYS.between(checkIn, checkOut); }
boolean overlaps(Stay o) { return checkIn.isBefore(o.checkOut) && o.checkIn.isBefore(checkOut); }
}
Stay s = new Stay(LocalDate.of(2026, 12, 20), LocalDate.of(2026, 12, 23));
System.out.println(s.nights()); // 3
System.out.println(s.overlaps(new Stay(LocalDate.of(2026, 12, 23), LocalDate.of(2026, 12, 25)))); // false

Because a LocalDate has no zone, there is nothing to convert, and nothing can shift it by a day. Prices per night, availability per date and reports per day all work on the same simple values. In the database, these map to DATE columns.

2The Hotel's Zone and the 15:00 Check-In

Check-in at 15:00 means 15:00 on the hotel's wall clock. We store it as a LocalTime on the hotel, next to the hotel's ZoneId, for example Europe/Lisbon. A ZoneId names a region whose offset rules, including DST, come from the time zone database that the JDK ships and updates.

When we need the exact moment, for example to send a reminder three hours before check-in or to show the guest the time in their own zone, we combine the three pieces at that time: date, local time and zone.

Java
record Hotel(String id, ZoneId zone, LocalTime checkInTime) {}
Hotel lisbon = new Hotel("h1", ZoneId.of("Europe/Lisbon"), LocalTime.of(15, 0));
ZonedDateTime checkIn = s.checkIn().atTime(lisbon.checkInTime()).atZone(lisbon.zone());
System.out.println(checkIn); // 2026-12-20T15:00Z[Europe/Lisbon] (Lisbon is UTC+0 in winter)
System.out.println(checkIn.toInstant()); // 2026-12-20T15:00:00Z
Instant remindAt = checkIn.minusHours(3).toInstant(); // 2026-12-20T12:00:00Z
System.out.println(checkIn.withZoneSameInstant(ZoneId.of("America/New_York"))); // 2026-12-20T10:00-05:00[America/New_York]
Step throughWhat we store and what we compute
  1. BookingLocalDate checkIn, LocalDate checkOut
  2. HotelZoneId zone, LocalTime checkInTime
  3. Computed when neededZonedDateTime = date + time + zone
  4. PaymentInstant paidAt, stored in UTC

4 layers, from the top down. Step through them one at a time.

Local values and the zone are stored; the exact moment of a future event is derived.

3Payments Are Instants

A payment is something that happened at one exact moment. Its natural type is Instant, taken from an injected Clock so tests can control it. We store it in UTC, in PostgreSQL a timestamptz column, and convert it to a local time only for display: the hotel sees it in Lisbon time, the guest in their own zone, and finance reports in whatever zone their rules require.

Java
Instant paidAt = Instant.now(clock); // 2026-11-04T14:03:22Z
String forHotel = paidAt.atZone(lisbon.zone())
.format(DateTimeFormatter.ofPattern("d MMM yyyy HH:mm")); // 4 Nov 2026 14:03

The difference from check-in is direction in time. A payment is in the past, so its moment is a fact that no rule change can alter. A check-in is in the future, and its moment depends on rules that may still change.

4Why Not Store Future Local Times as Instants

It is tempting to store everything as UTC instants. For the future check-in, that would mean computing the instant today using today's zone rules. But governments change their time zone rules regularly, adding or removing DST or moving the switch date, sometimes with only weeks of notice, and the JDK picks up those changes through time zone database updates.

If a country abolishes DST next year, a check-in stored as an instant computed with the old rules would now correspond to 14:00 or 16:00 local time, while the hotel still opens rooms at 15:00. By storing the local date, local time and zone, we compute the instant when we need it, with the rules current at that time, and the check-in stays at 15:00 local. The general rule is that future events defined by a local clock are stored as local values plus a zone; past events are stored as instants.

Storing a future check-in
Stored asAfter a zone rule changeResult
Instant computed at booking timeinstant unchanged, local time shiftscheck-in shows 14:00 or 16:00
LocalDate + LocalTime + ZoneIdinstant recomputed with new rulescheck-in stays 15:00 local

5The API Format

At the API boundary we use ISO-8601 strings, never numbers or locale-formatted text, and we make zones explicit. Dates without time are plain dates, local times travel with the hotel's zone ID, and moments carry an offset, preferably Z for UTC. Spring Boot's Jackson setup writes java.time types in ISO-8601 by default.

JSON
{
"hotelId": "h1",
"hotelZone": "Europe/Lisbon",
"checkIn": "2026-12-20",
"checkOut": "2026-12-23",
"checkInTime": "15:00",
"checkInAt": "2026-12-20T15:00:00Z",
"payment": { "amount": "450.00", "currency": "EUR", "paidAt": "2026-11-04T14:03:22Z" }
}

checkInAt is a convenience field computed when the response is built, for clients that want a moment; the source of truth remains the date, the time and the zone. Clients that show times to guests should use the zone ID, not just an offset, so they can apply the right rules for other dates.

6Follow-up questions

How would you represent a check-in time on a day the clocks change?

The same way: LocalDate plus LocalTime plus the hotel's ZoneId, and the conversion handles the transition. Most zones change their clocks in the early morning, so 15:00 is normally unaffected, but some zones switch at other hours. If a local time falls in a gap, when clocks jump forward, atZone moves it later by the length of the gap, so 02:30 on 14 March 2027 in New York becomes 03:30-04:00. If it falls in an overlap, when clocks go back, atZone picks the earlier offset, and withLaterOffsetAtOverlap() chooses the later one. If hotels might set times in those windows, the business should decide the rule, and we test it with fixed dates. Also, the night itself may be 23 or 25 hours long, which does not matter because we charge per date, not per hour.

Which database column types would you use?

DATE for check-in and check-out, TIME for the hotel's check-in time, a text column for the ZoneId such as Europe/Lisbon, and timestamptz in PostgreSQL for payment instants, which stores UTC and converts on the way in and out. With JDBC 4.2 and Hibernate 6 or later, these map directly to LocalDate, LocalTime and Instant or OffsetDateTime.

How do you test date logic reliably?

Inject a java.time.Clock instead of calling Instant.now() directly, and use Clock.fixed in tests. Then tests can run as if it were the night of a DST change, a leap day or the last day of the year, and assertions use exact values.

7Conclusion

In this answer, we matched each requirement to the right java.time type. Nights are LocalDate ranges with an inclusive check-in and exclusive check-out date, because a night is a calendar concept in the hotel's zone. Each hotel stores its ZoneId and its LocalTime check-in, and we combine them with the date into a ZonedDateTime only when we need the moment. Payments are Instants, stored in UTC and converted only for display. Future local times are not stored only as instants, because zone rules can change before the date, and the API uses ISO-8601 strings with explicit offsets or zone IDs.

What to say in the interviewAbout 100 seconds aloud

Open with

I would use three different kinds of type because the booking has three kinds of time. Hotel nights are calendar dates in the hotel's zone, so a booking stores a LocalDate check-in and a LocalDate check-out, half-open, so twenty to twenty-three December is three nights and back-to-back bookings do not overlap.

Then, if they want more

Nothing can shift a LocalDate by a day for a guest in another country. Each hotel stores its ZoneId, like Europe/Lisbon, and its check-in time as a LocalTime of 15:00.

When I need the exact moment, say for a reminder or to show the guest the time in their own zone, I combine date, time and zone into a ZonedDateTime at that point. Payments are facts in the past, so they are Instants from an injected Clock, stored in UTC as timestamptz and converted to a zone only for display.

I would not store future check-ins only as Instants, because governments change DST rules, and an instant computed with today's rules could end up at 14:00 or 16:00 local time after a change; storing the local values plus the zone keeps check-in at 15:00.

In the API I would use ISO-8601: plain dates for the stay, the zone ID for the hotel, and instants with a Z offset for payments. For a day when the clocks change, the same model works, and atZone resolves gaps by moving later and overlaps by taking the earlier offset, which the business can override.

About this answer

Last updated
12 November 2026
Versions it names
Hibernate 6
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 "You are designing the date and time handling for a booking service: guests book hotel...": https://scrivio-interview-library.netlify.app/java/date-and-time/9bbb52717c/