Skip to content

Commit

Permalink
Fix: 0초인 Pace를 파싱이나 직렬화 할 때 0 대신 -를 사용하도록 수정 (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
WonSteps authored Oct 10, 2024
1 parent 004cf02 commit ea23065
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/com/dnd/runus/domain/common/Pace.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @param second
*/
public record Pace(int minute, int second) {
private static final String EMPTY_PACE = "-’--”";

public Pace {
if (minute < 0 || second < 0 || second >= SECONDS_PER_MINUTE) {
throw new IllegalArgumentException("분 또는 초는 0 이상 60 미만의 값이어야 합니다.");
Expand All @@ -27,12 +29,18 @@ public static Pace ofSeconds(int seconds) {
@JsonCreator
public static Pace from(String pace) {
// e.g. 5'30" or 5’30”
if (pace.equals(EMPTY_PACE)) {
return new Pace(0, 0);
}
String[] paceArr = pace.split("[’']|”");
return new Pace(Integer.parseInt(paceArr[0]), Integer.parseInt(paceArr[1]));
}

@JsonValue
public String getJsonValue() {
if (minute == 0 && second == 0) {
return EMPTY_PACE;
}
return minute + "’" + String.format("%02d", second) + "”";
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/dnd/runus/domain/common/PaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void toSeconds(int minute, int second) {

private static Stream<Arguments> providePace() {
return Stream.of(
Arguments.of(0, 0, "0’00”"),
Arguments.of(0, 0, "-’--”"),
Arguments.of(0, 30, "0’30”"),
Arguments.of(1, 1, "1’01”"),
Arguments.of(1, 5, "1’05”"),
Expand Down

0 comments on commit ea23065

Please sign in to comment.