Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Period.Between 메서드 날짜 계산 오류 해결 #75

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}