diff --git a/server/src/main/java/com/talkka/server/bus/service/BusStatService.java b/server/src/main/java/com/talkka/server/bus/service/BusStatService.java index 5ed74e92..a61834cf 100644 --- a/server/src/main/java/com/talkka/server/bus/service/BusStatService.java +++ b/server/src/main/java/com/talkka/server/bus/service/BusStatService.java @@ -45,14 +45,12 @@ public List getBusStat(BusStatReqDto busStatReqDto) { public List getBusStatNow(Long routeId, Long stationId) { LocalDateTime now = LocalDateTime.now(); - int startTime = getTime(now.minusMinutes(30)); - int endTime = getTime(now.plusMinutes(30)); return busStatRepository.findByRouteIdAndStationIdAndDayOfWeekBetweenNow( routeId, stationId, - now.getDayOfWeek().getValue(), - startTime, - endTime + getDayOfWeek(now), + getTime(now.minusMinutes(30)), + getTime(now.plusMinutes(30)) ).stream() .map(BusStatRespDto::of) .toList(); @@ -115,7 +113,7 @@ private static BusStatEntity toBusStatEntity(BusLocationEntity before, BusLocati .afterTime(after.getCreatedAt()) .plateNo(after.getPlateNo()) .plateType(after.getPlateType()) - .dayOfWeek(before.getCreatedAt().getDayOfWeek().getValue()) + .dayOfWeek(getDayOfWeek(before.getCreatedAt())) .time(getTime(before.getCreatedAt())) .build(); } @@ -125,6 +123,13 @@ private static int getTime(LocalDateTime localDateTime) { return localDateTime.getHour() * 100 + localDateTime.getMinute(); } + private static int getDayOfWeek(LocalDateTime localDateTime) { + if (localDateTime.getHour() < 3) { + return localDateTime.getDayOfWeek().getValue() - 1; + } + return localDateTime.getDayOfWeek().getValue(); + } + // old logic // @Deprecated // @Transactional