Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix current day name and 24 hours issue #42

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading