Skip to content

Commit dbd60f5

Browse files
author
jopro.o
committed
[Bug Fix] 통화가 일 경계에 걸칠 경우 1초만큼의 요금이 누락되는 버그 수정
1 parent 70e7d7f commit dbd60f5

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

chapter14/src/main/java/org/eternity/billing/step02/BasicRatePolicy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private Money calculate(Call call) {
2525
return feeRules
2626
.stream()
2727
.map(rule -> rule.calculateFee(call))
28-
.reduce(Money.ZERO, (first, second) -> first.plus(second));
28+
.reduce(Money.ZERO,
29+
(first, second) -> second.isGreaterThanOrEqual(Money.ZERO) ? first.plus(second) : first);
2930
}
3031
}

chapter14/src/main/java/org/eternity/billing/step02/FeePerDuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public FeePerDuration(Money fee, Duration duration) {
1515
}
1616

1717
public Money calculate(DateTimeInterval interval) {
18-
return fee.times(interval.duration().getSeconds() / duration.getSeconds());
18+
return fee.times(Math.ceil((double)interval.duration().toNanos() / duration.toNanos()));
1919
}
2020
}
2121

chapter14/src/main/java/org/eternity/time/DateTimeInterval.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static DateTimeInterval of(LocalDateTime from, LocalDateTime to) {
1212
}
1313

1414
public static DateTimeInterval toMidnight(LocalDateTime from) {
15-
return new DateTimeInterval(from, LocalDateTime.of(from.toLocalDate(), LocalTime.of(23, 59, 59)));
15+
return new DateTimeInterval(from, LocalDateTime.of(from.toLocalDate(), LocalTime.of(23, 59, 59, 999_999_999)));
1616
}
1717

1818
public static DateTimeInterval fromMidnight(LocalDateTime to) {
@@ -22,7 +22,7 @@ public static DateTimeInterval fromMidnight(LocalDateTime to) {
2222
public static DateTimeInterval during(LocalDate date) {
2323
return new DateTimeInterval(
2424
LocalDateTime.of(date, LocalTime.of(0, 0)),
25-
LocalDateTime.of(date, LocalTime.of(23, 59, 59)));
25+
LocalDateTime.of(date, LocalTime.of(23, 59, 59, 999_999_999)));
2626
}
2727

2828
private DateTimeInterval(LocalDateTime from, LocalDateTime to) {
@@ -43,7 +43,7 @@ public LocalDateTime getTo() {
4343
}
4444

4545
public List<DateTimeInterval> splitByDay() {
46-
if (days() > 1) {
46+
if (days() > 0) {
4747
return split(days());
4848
}
4949

0 commit comments

Comments
 (0)