Skip to content

Commit 1a8d3c8

Browse files
committed
[java][booking][03_preserve_object] Preserve DateRange object
1 parent 80b0bd2 commit 1a8d3c8

File tree

1 file changed

+10
-12
lines changed
  • examples/java/java-booking-03_preserve_whole_object/src/main/java/tv/codely/booking

1 file changed

+10
-12
lines changed

examples/java/java-booking-03_preserve_whole_object/src/main/java/tv/codely/booking/Booking.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,35 @@
33
import java.time.LocalDateTime;
44

55
public final class Booking {
6-
private final BookingId id;
7-
private final LocalDateTime startDate;
8-
private final LocalDateTime endDate;
9-
private final Customer customer;
10-
private final BookingType bookingType;
11-
private final Discount discount;
12-
private final Tax tax;
6+
private final BookingId id;
7+
private final DateRange dateRange;
8+
private final Customer customer;
9+
private final BookingType bookingType;
10+
private final Discount discount;
11+
private final Tax tax;
1312

1413
public Booking(
1514
BookingId id,
16-
DateRange bookingDateRange,
15+
DateRange dateRange,
1716
Customer customer,
1817
BookingType bookingType,
1918
Discount discount,
2019
Tax tax
2120
) {
2221
this.id = id;
23-
this.startDate = bookingDateRange.startDate();
24-
this.endDate = bookingDateRange.endDate();
22+
this.dateRange = dateRange;
2523
this.customer = customer;
2624
this.bookingType = bookingType;
2725
this.discount = discount;
2826
this.tax = tax;
2927
}
3028

3129
public BookingStatus statusFor(LocalDateTime date) {
32-
if (date.isBefore(startDate)) {
30+
if (date.isBefore(dateRange.startDate())) {
3331
return BookingStatus.NOT_STARTED;
3432
}
3533

36-
if (date.isAfter(startDate) && date.isBefore(endDate)) {
34+
if (date.isAfter(dateRange.startDate()) && date.isBefore(dateRange.endDate())) {
3735
return BookingStatus.ACTIVE;
3836
}
3937

0 commit comments

Comments
 (0)