-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3761f87
commit c19e472
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/src/main/java/dev/tripdraw/domain/trip/TripDuration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.tripdraw.domain.trip; | ||
|
||
import java.time.Duration; | ||
|
||
public class TripDuration { | ||
|
||
private static final String MINUTE = "분"; | ||
private static final String HOUR = "시간"; | ||
private static final String DAY = "일"; | ||
private static final String WHITE_SPACE = " "; | ||
|
||
private final Duration duration; | ||
|
||
private TripDuration(Duration duration) { | ||
this.duration = duration; | ||
} | ||
|
||
public static TripDuration of(Duration duration) { | ||
return new TripDuration(duration); | ||
} | ||
|
||
public String durationInMinutes() { | ||
long minutes = duration.toMinutes(); | ||
return minutes + MINUTE; | ||
} | ||
|
||
public String durationInHoursAndMinutes() { | ||
long hours = duration.toHours(); | ||
long minutes = duration.toMinutes() - (hours * 60); | ||
|
||
return hours + HOUR + WHITE_SPACE + minutes + MINUTE; | ||
} | ||
|
||
public String durationInDaysAndHoursAndMinutes() { | ||
long days = duration.toDays(); | ||
long hours = duration.toHours() - (days * 24); | ||
long minutes = duration.toMinutes() - (days * 1440) - (hours * 60); | ||
|
||
return days + DAY + WHITE_SPACE + hours + HOUR + WHITE_SPACE + minutes + MINUTE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/src/test/java/dev/tripdraw/domain/trip/TripDurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.tripdraw.domain.trip; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.Duration; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@SuppressWarnings("NonAsciiCharacters") | ||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
class TripDurationTest { | ||
|
||
private final TripDuration tripDuration = TripDuration.of(Duration.ofMinutes(3248)); | ||
|
||
@Test | ||
void 여행기간을_분_단위로_나타낸다() { | ||
// given & when | ||
String durationInMinutes = tripDuration.durationInMinutes(); | ||
|
||
// then | ||
assertThat(durationInMinutes).isEqualTo("3248분"); | ||
} | ||
|
||
@Test | ||
void 여행기간을_시간과_분_단위로_나타낸다() { | ||
// given & when | ||
String durationInHoursAndMinutes = tripDuration.durationInHoursAndMinutes(); | ||
|
||
// then | ||
assertThat(durationInHoursAndMinutes).isEqualTo("54시간 8분"); | ||
} | ||
|
||
@Test | ||
void 여행기간을_일과_시간과_분_단위로_나타낸다() { | ||
// given & when | ||
String durationInDaysAndHoursAndMinutes = tripDuration.durationInDaysAndHoursAndMinutes(); | ||
// then | ||
assertThat(durationInDaysAndHoursAndMinutes).isEqualTo("2일 6시간 8분"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters