Skip to content

Commit

Permalink
Fix current day name and 24 hours issue
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Surzhykov <yuriisurzhykov@gmail.com>
  • Loading branch information
yuriisurzhykov committed May 29, 2024
1 parent a7e673a commit fe1a9b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface StringToDayOfWeekMapper : Mapper<String, DayOfWeek> {
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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit fe1a9b3

Please sign in to comment.