From 4cb60316bcea70d7dd8cdb37f24aca418be99c03 Mon Sep 17 00:00:00 2001 From: Jeff Houle <44010975+jhoule86@users.noreply.github.com> Date: Sun, 9 Feb 2025 03:40:02 -0500 Subject: [PATCH 1/2] truncate timezone ID only if it is too long --- .../rebble/cobble/shared/handlers/SystemHandler.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt b/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt index a5aa83fb..10cda409 100644 --- a/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt +++ b/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt @@ -122,13 +122,20 @@ class SystemHandler( val timezone = TimeZone.currentSystemDefault() val now = Clock.System.now() val timezoneOffsetMinutes = timezone.offsetAt(now).totalSeconds.seconds.inWholeMinutes - Logging.i("Sending current time to watch: $now, timezone: ${timezone.id} (truncated: ${timezone.id.take(MAX_TIMEZONE_NAME_LENGTH)}), offset: $timezoneOffsetMinutes") + + val normalizedZone = timezone.id + if (normalizedZone.length > MAX_TIMEZONE_NAME_LENGTH) { + normalizedZone = timezone.id.take(MAX_TIMEZONE_NAME_LENGTH) + Logging.i("Time Zone ${timezone.id} exceeds maximum value length and has been truncated to ${normalizedZone}") + } + val updateTimePacket = TimeMessage.SetUTC( now.epochSeconds.toUInt(), timezoneOffsetMinutes.toShort(), - timezone.id.take(MAX_TIMEZONE_NAME_LENGTH) + normalizedZone ) + Logging.i("Sending current time to watch: $now, timezone: ${normalizedZone}, offset: $timezoneOffsetMinutes") systemService.send(updateTimePacket) } @@ -162,4 +169,4 @@ class SystemHandler( } expect fun platformTimeChangedFlow(context: PlatformContext): Flow -expect fun getPlatformPebbleFlags(context: PlatformContext): Set \ No newline at end of file +expect fun getPlatformPebbleFlags(context: PlatformContext): Set From a05d79f8a11a00763dcab64c2c8a27d728c2f965 Mon Sep 17 00:00:00 2001 From: Jeff Houle <44010975+jhoule86@users.noreply.github.com> Date: Sun, 9 Feb 2025 05:09:47 -0500 Subject: [PATCH 2/2] call take on local variable instead of original value --- .../kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt b/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt index 10cda409..f161fdbd 100644 --- a/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt +++ b/android/shared/src/commonMain/kotlin/io/rebble/cobble/shared/handlers/SystemHandler.kt @@ -125,7 +125,7 @@ class SystemHandler( val normalizedZone = timezone.id if (normalizedZone.length > MAX_TIMEZONE_NAME_LENGTH) { - normalizedZone = timezone.id.take(MAX_TIMEZONE_NAME_LENGTH) + normalizedZone = normalizedZone.take(MAX_TIMEZONE_NAME_LENGTH) Logging.i("Time Zone ${timezone.id} exceeds maximum value length and has been truncated to ${normalizedZone}") }