fix(ui): Prevent NaN values in environment metrics (#4316)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2026-01-26 06:52:13 -06:00 committed by GitHub
parent 847152acd7
commit 50a04a98b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 8 deletions

View file

@ -26,6 +26,8 @@ object UnitConversions {
/** Formats temperature as a string with the unit suffix. */
fun Float.toTempString(isFahrenheit: Boolean): String {
if (this.isNaN()) return "--"
val temp = if (isFahrenheit) celsiusToFahrenheit(this) else this
val unit = if (isFahrenheit) "F" else "C"

View file

@ -77,6 +77,12 @@ class UnitConversionsTest {
assertEquals("-40°F", (-40.0f).toTempString(true))
}
@Test
fun `toTempString handles NaN`() {
assertEquals("--", Float.NaN.toTempString(false))
assertEquals("--", Float.NaN.toTempString(true))
}
@Test
fun `celsiusToFahrenheit converts correctly`() {
mapOf(