From cc5b3ec027cafdbfea67c2a4edeb7a1ad7a15123 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sun, 3 Aug 2025 15:49:46 -0500 Subject: [PATCH] fix: Handle string timestamps in weather view DateTime comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The weather view was crashing with FunctionClauseError when comparing string timestamps with DateTime structs. This happens when packets are broadcast with string timestamps instead of DateTime objects. Changes: - Add cases to handle when one timestamp is a string and the other is DateTime - Parse ISO8601 string timestamps before comparison - Append 'Z' to timestamps that don't have timezone info - Fallback safely when parsing fails This prevents crashes when the weather view receives packets with mixed timestamp formats from different parts of the system. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- lib/aprsme_web/live/weather_live/callsign_view.ex | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/aprsme_web/live/weather_live/callsign_view.ex b/lib/aprsme_web/live/weather_live/callsign_view.ex index a07b0e7..0b46a0a 100644 --- a/lib/aprsme_web/live/weather_live/callsign_view.ex +++ b/lib/aprsme_web/live/weather_live/callsign_view.ex @@ -107,6 +107,20 @@ defmodule AprsmeWeb.WeatherLive.CallsignView do {new_time, current_time} when is_binary(new_time) and is_binary(current_time) -> new_time > current_time + {new_time, current_time} when is_binary(new_time) -> + # Parse string timestamp and compare + case DateTime.from_iso8601(new_time <> "Z") do + {:ok, new_dt, _} -> DateTime.after?(new_dt, current_time) + _ -> false + end + + {new_time, current_time} when is_binary(current_time) -> + # Parse string timestamp and compare + case DateTime.from_iso8601(current_time <> "Z") do + {:ok, current_dt, _} -> DateTime.after?(new_time, current_dt) + _ -> true + end + {new_time, current_time} -> DateTime.after?(new_time, current_time) end