From 69b1cb42215b867fbecbd83e04ab2afffc74591b Mon Sep 17 00:00:00 2001 From: vegard Date: Mon, 16 Mar 2026 18:19:26 +0100 Subject: [PATCH] =?UTF-8?q?Fiks:=20parse=20PG-timestamps=20korrekt=20(norm?= =?UTF-8?q?alis=C3=A9r=20+00=20=E2=86=92=20+00:00=20for=20chrono)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.6 --- spacetimedb/src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spacetimedb/src/lib.rs b/spacetimedb/src/lib.rs index 711fc98..941981b 100644 --- a/spacetimedb/src/lib.rs +++ b/spacetimedb/src/lib.rs @@ -539,10 +539,17 @@ pub fn mark_synced(ctx: &ReducerContext, ids: Vec) -> Result<(), String> { /// Parse en PG-tekststreng ("2026-03-15 23:57:11.677139+00") til SpacetimeDB Timestamp. fn parse_timestamp(s: &str) -> Option { if s.is_empty() { return None; } - // Prøv standard ISO-parse først, deretter PG-formater - let dt = s.parse::>() + // PG returnerer "+00" som offset — chrono krever "+00:00" + let normalized = if s.ends_with("+00") { + format!("{}:00", s) + } else { + s.to_string() + }; + let dt = chrono::DateTime::parse_from_str(&normalized, "%Y-%m-%d %H:%M:%S%.f%:z") + .or_else(|_| chrono::DateTime::parse_from_str(&normalized, "%Y-%m-%d %H:%M:%S%:z")) .map(|d| d.to_utc()) .or_else(|_| { + // Fallback: uten timezone chrono::NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.f") .or_else(|_| chrono::NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S")) .map(|naive| naive.and_utc())