diff --git a/src/memories.rs b/src/memories.rs index 524e2a0..695d486 100644 --- a/src/memories.rs +++ b/src/memories.rs @@ -1,7 +1,6 @@ use actix_web::web::Data; use actix_web::{HttpRequest, HttpResponse, Responder, get, web}; -use chrono::LocalResult::{Ambiguous, Single}; -use chrono::{DateTime, FixedOffset, Local, LocalResult, NaiveDate, TimeZone}; +use chrono::{DateTime, FixedOffset, Local, NaiveDate, TimeZone, Utc}; use log::{debug, trace, warn}; use opentelemetry::KeyValue; use opentelemetry::trace::{Span, Status, TraceContextExt, Tracer}; @@ -134,6 +133,15 @@ pub struct MemoriesResponse { } pub fn extract_date_from_filename(filename: &str) -> Option> { + // Filenames carry only digits — no timezone. We deliberately interpret + // them as UTC so `.timestamp()` returns the wall-clock-as-UTC unix + // seconds, matching the "naive local reinterpreted as UTC" convention + // image_exif.date_taken uses for kamadak-exif DateTimeOriginal (which + // is also naive). Anything else (Local::from_local_datetime, the + // previous behavior) shifted filename-sourced dates by the SERVER's + // TZ offset relative to UTC, making them disagree with EXIF-sourced + // dates by hours and double-shifting through Apollo's photo matcher + // (which re-anchors naive-as-UTC via the browser TZ). let build_date_from_ymd_capture = |captures: ®ex::Captures| -> Option> { let year = captures.get(1)?.as_str().parse::().ok()?; @@ -143,16 +151,8 @@ pub fn extract_date_from_filename(filename: &str) -> Option().ok()?; let sec = captures.get(6)?.as_str().parse::().ok()?; - match Local.from_local_datetime( - &NaiveDate::from_ymd_opt(year, month, day)?.and_hms_opt(hour, min, sec)?, - ) { - Single(dt) => Some(dt.fixed_offset()), - Ambiguous(early_dt, _) => Some(early_dt.fixed_offset()), - LocalResult::None => { - warn!("Weird local date: {:?}", filename); - None - } - } + let naive = NaiveDate::from_ymd_opt(year, month, day)?.and_hms_opt(hour, min, sec)?; + Some(Utc.from_utc_datetime(&naive).fixed_offset()) }; // 1. Screenshot format: Screenshot_2014-06-01-20-44-50.png