fix: Handle string timestamps in weather view DateTime comparison

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 <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-08-03 15:49:46 -05:00
parent de10763915
commit cc5b3ec027
No known key found for this signature in database

View file

@ -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