feature/manual-date-override #79
@@ -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<DateTime<FixedOffset>> {
|
||||
// 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<DateTime<FixedOffset>> {
|
||||
let year = captures.get(1)?.as_str().parse::<i32>().ok()?;
|
||||
@@ -143,16 +151,8 @@ pub fn extract_date_from_filename(filename: &str) -> Option<DateTime<FixedOffset
|
||||
let min = captures.get(5)?.as_str().parse::<u32>().ok()?;
|
||||
let sec = captures.get(6)?.as_str().parse::<u32>().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
|
||||
|
||||
Reference in New Issue
Block a user