Fiks: parse PG-timestamps korrekt (normalisér +00 → +00:00 for chrono)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
vegard 2026-03-16 18:19:26 +01:00
parent b6fd6b5ef0
commit 69b1cb4221

View file

@ -539,10 +539,17 @@ pub fn mark_synced(ctx: &ReducerContext, ids: Vec<u64>) -> Result<(), String> {
/// Parse en PG-tekststreng ("2026-03-15 23:57:11.677139+00") til SpacetimeDB Timestamp.
fn parse_timestamp(s: &str) -> Option<Timestamp> {
if s.is_empty() { return None; }
// Prøv standard ISO-parse først, deretter PG-formater
let dt = s.parse::<chrono::DateTime<chrono::FixedOffset>>()
// 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())