From fe1a9b3a9a74810b0e840df13678f3f8385b1713 Mon Sep 17 00:00:00 2001 From: Yurii Surzhykov Date: Wed, 29 May 2024 10:23:51 -0700 Subject: [PATCH] Fix current day name and 24 hours issue Signed-off-by: Yurii Surzhykov --- .../domain/mapper/StringToDayOfWeekMapper.kt | 2 +- .../BuildCurrentLocationStatusUseCase.kt | 59 +++++++++++-------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/location-domain/src/main/java/com/github/yuriisurzhykov/purs/domain/mapper/StringToDayOfWeekMapper.kt b/location-domain/src/main/java/com/github/yuriisurzhykov/purs/domain/mapper/StringToDayOfWeekMapper.kt index d13358e..d072541 100644 --- a/location-domain/src/main/java/com/github/yuriisurzhykov/purs/domain/mapper/StringToDayOfWeekMapper.kt +++ b/location-domain/src/main/java/com/github/yuriisurzhykov/purs/domain/mapper/StringToDayOfWeekMapper.kt @@ -9,7 +9,7 @@ interface StringToDayOfWeekMapper : Mapper { class Base @Inject constructor() : StringToDayOfWeekMapper { override fun map(source: String): DayOfWeek { val weekNames = listOf("MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN") - return DayOfWeek.of(weekNames.indexOf(source)) + return DayOfWeek.of(weekNames.indexOf(source) + 1) } } } \ No newline at end of file diff --git a/location-domain/src/main/java/com/github/yuriisurzhykov/purs/domain/usecase/BuildCurrentLocationStatusUseCase.kt b/location-domain/src/main/java/com/github/yuriisurzhykov/purs/domain/usecase/BuildCurrentLocationStatusUseCase.kt index ad4bb73..ccac624 100644 --- a/location-domain/src/main/java/com/github/yuriisurzhykov/purs/domain/usecase/BuildCurrentLocationStatusUseCase.kt +++ b/location-domain/src/main/java/com/github/yuriisurzhykov/purs/domain/usecase/BuildCurrentLocationStatusUseCase.kt @@ -70,37 +70,46 @@ interface BuildCurrentLocationStatusUseCase { if (timeSlot.endTime < timeSlot.startTime) { timeSlot.startTime.isBefore(currentTime) } else { - timeSlot.endTime.isAfter(currentTime) && timeSlot.startTime.isBefore(currentTime) + (timeSlot.startTime == LocalTime.MIDNIGHT && timeSlot.endTime == LocalTime.MIDNIGHT) || + (timeSlot.startTime.isBefore(currentTime) && timeSlot.endTime.isAfter(currentTime)) } } return if (currentOpenSchedule != null) { - val timeDifference = - if (currentOpenSchedule.endTime < currentOpenSchedule.startTime) { - currentTime.until(LocalTime.MAX, ChronoUnit.MINUTES) + - LocalTime.MIDNIGHT.until(currentOpenSchedule.endTime, ChronoUnit.MINUTES) - } else { - currentTime.until(currentOpenSchedule.endTime, ChronoUnit.MINUTES) - } - // If the location closes within 24 hours, return the location status - // that it closing soon. Otherwise, return the location status that it opens - return if (timeDifference <= 60) { - if (nextWorkingDay == null) { - return LocationStatus.Closing(currentOpenSchedule.endTime) - } + if (currentOpenSchedule.startTime == LocalTime.MIDNIGHT && + currentOpenSchedule.endTime == LocalTime.MIDNIGHT) { + LocationStatus.Open(currentOpenSchedule.endTime) + } else { + val timeDifference = + if (currentOpenSchedule.endTime < currentOpenSchedule.startTime) { + currentTime.until(LocalTime.MAX, ChronoUnit.MINUTES) + + LocalTime.MIDNIGHT.until( + currentOpenSchedule.endTime, + ChronoUnit.MINUTES + ) + } else { + currentTime.until(currentOpenSchedule.endTime, ChronoUnit.MINUTES) + } + // If the location closes within 24 hours, return the location status + // that it closing soon. Otherwise, return the location status that it opens + return if (timeDifference <= 60) { + if (nextWorkingDay == null) { + return LocationStatus.Closing(currentOpenSchedule.endTime) + } - val nextOpenTime = nextWorkingDay.second.startTime - val reopenTimeDifference = currentTime.until(nextOpenTime, ChronoUnit.HOURS) - if (reopenTimeDifference > 24) { - LocationStatus.ClosingSoonLongReopen( - currentOpenSchedule.endTime, - nextWorkingDay.first, - nextOpenTime - ) + val nextOpenTime = nextWorkingDay.second.startTime + val reopenTimeDifference = currentTime.until(nextOpenTime, ChronoUnit.HOURS) + if (reopenTimeDifference > 24) { + LocationStatus.ClosingSoonLongReopen( + currentOpenSchedule.endTime, + nextWorkingDay.first, + nextOpenTime + ) + } else { + LocationStatus.ClosingSoon(currentOpenSchedule.endTime, nextOpenTime) + } } else { - LocationStatus.ClosingSoon(currentOpenSchedule.endTime, nextOpenTime) + LocationStatus.Open(currentOpenSchedule.endTime) } - } else { - LocationStatus.Open(currentOpenSchedule.endTime) } } else null }