Skip to content

Commit 0f9d903

Browse files
committed
Fix operating hours bug
1 parent 8449b76 commit 0f9d903

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

app/src/main/java/com/cornellappdev/transit/ui/components/home/GymCapacityIndicator.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cornellappdev.transit.ui.components.home
22

3+
import android.icu.util.Calendar
34
import androidx.compose.animation.core.Animatable
45
import androidx.compose.animation.core.tween
56
import androidx.compose.foundation.layout.Box
@@ -17,6 +18,7 @@ import androidx.compose.ui.Modifier
1718
import androidx.compose.ui.graphics.StrokeCap
1819
import androidx.compose.ui.text.font.FontWeight
1920
import androidx.compose.ui.text.style.TextAlign
21+
import androidx.compose.ui.tooling.preview.Preview
2022
import androidx.compose.ui.unit.dp
2123
import androidx.compose.ui.unit.sp
2224
import com.cornellappdev.transit.models.ecosystem.UpliftCapacity
@@ -115,4 +117,13 @@ fun GymCapacityIndicator(
115117
)
116118
}
117119
}
120+
}
121+
122+
@Composable
123+
@Preview(showBackground = true)
124+
private fun GymCapacityIndicatorPreview() {
125+
GymCapacityIndicator(
126+
UpliftCapacity(0.40, Calendar.getInstance()),
127+
label = null
128+
)
118129
}

app/src/main/java/com/cornellappdev/transit/ui/viewmodels/HomeViewModel.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.cornellappdev.transit.ui.viewmodels
22

33
import android.content.Context
44
import androidx.compose.ui.text.AnnotatedString
5-
import androidx.compose.ui.text.PlatformTextStyle
65
import androidx.compose.ui.text.SpanStyle
76
import androidx.compose.ui.text.buildAnnotatedString
87
import androidx.compose.ui.text.font.FontWeight
@@ -356,7 +355,7 @@ class HomeViewModel @Inject constructor(
356355
}
357356

358357
/**
359-
* Given operating hours rotated for today's date, return whether it is open and when it is open until
358+
* Given operating hours, return whether it is open and when it is open until
360359
* or when it will next open
361360
*
362361
* @param operatingHours A list of pairs mapping the first value day string to second value list of hours open
@@ -365,13 +364,14 @@ class HomeViewModel @Inject constructor(
365364
operatingHours: List<DayOperatingHours>,
366365
currentDateTime: LocalDateTime = LocalDateTime.now()
367366
): OpenStatus {
367+
val rotatedOperatingHours = rotateOperatingHours(operatingHours)
368368

369369
val currentTime = currentDateTime.toLocalTime()
370-
val todaySchedule = operatingHours[0].hours // First day should be today after rotation
370+
val todaySchedule = rotatedOperatingHours[0].hours // First day should be today after rotation
371371

372372
// Check if closed today
373373
if (todaySchedule.any { it.equals("Closed", ignoreCase = true) }) {
374-
return findOpenNextDay(operatingHours)
374+
return findOpenNextDay(rotatedOperatingHours)
375375
}
376376

377377
val timeRanges = todaySchedule.mapNotNull { parseTimeRange(it) }
@@ -391,7 +391,7 @@ class HomeViewModel @Inject constructor(
391391
}
392392

393393
// Closed for today, find next open day
394-
return findOpenNextDay(operatingHours)
394+
return findOpenNextDay(rotatedOperatingHours)
395395
}
396396

397397
/**

0 commit comments

Comments
 (0)