Skip to content

Commit

Permalink
Merge pull request #75 from Team-Going/feature/74
Browse files Browse the repository at this point in the history
[fix] Period.Between 메서드 날짜 계산 오류 해결
  • Loading branch information
SunwoongH authored Jan 11, 2024
2 parents a4cfa67 + 962dc7c commit 04a3668
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.doorip.trip.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AccessLevel;
import lombok.Builder;
import org.doorip.trip.domain.Trip;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

import static java.time.Period.between;

@Builder(access = AccessLevel.PRIVATE)
public record TripCreateResponse(
Long tripId,
String title,
Expand All @@ -19,13 +21,13 @@ public record TripCreateResponse(
) {

public static TripCreateResponse of(Trip trip) {
return new TripCreateResponse(
trip.getId(),
trip.getTitle(),
trip.getStartDate(),
trip.getEndDate(),
trip.getCode(),
between(LocalDate.now(), trip.getStartDate()).getDays()
);
return TripCreateResponse.builder()
.tripId(trip.getId())
.title(trip.getTitle())
.startDate(trip.getStartDate())
.endDate(trip.getEndDate())
.code(trip.getCode())
.day((int) ChronoUnit.DAYS.between(LocalDate.now(), trip.getStartDate()))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import org.doorip.trip.domain.Trip;

import java.time.LocalDate;

import static java.time.Period.between;
import java.time.temporal.ChronoUnit;

@Builder(access = AccessLevel.PRIVATE)
public record TripResponse(
Expand All @@ -25,7 +24,7 @@ public static TripResponse of(Trip trip) {
.title(trip.getTitle())
.startDate(trip.getStartDate())
.endDate(trip.getEndDate())
.day(between(LocalDate.now(), trip.getStartDate()).getDays())
.day((int) ChronoUnit.DAYS.between(LocalDate.now(), trip.getStartDate()))
.build();
}
}

0 comments on commit 04a3668

Please sign in to comment.