fix(dates): prefer earliest of fs created/modified as fallback

On copied or restored files (e.g. a backup library), the OS stamps
created at copy time while modified is preserved from the source, so
the earlier of the two is a better proxy for when the content
originated. Adds utils::earliest_fs_time and threads it through the
three spots that fall back to filesystem dates: photos-list sort,
memories grouping, and insight-generation timestamp.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cameron
2026-04-23 17:20:12 -04:00
parent d54419e779
commit dc2a96162e
4 changed files with 31 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
use std::time::SystemTime;
/// Normalize a file path to use forward slashes for cross-platform consistency
/// This ensures paths stored in the database always use `/` regardless of OS
///
@@ -12,6 +14,20 @@ pub fn normalize_path(path: &str) -> String {
path.replace('\\', "/")
}
/// Pick the earlier of a file's created and modified timestamps.
///
/// On copied/restored files (e.g., a backup library), `created` is stamped at
/// copy time while `modified` is preserved from the source — so the earlier
/// of the two is a better proxy for when the content originated. Falls back
/// to whichever timestamp is available if one platform lacks the other.
pub fn earliest_fs_time(md: &std::fs::Metadata) -> Option<SystemTime> {
match (md.created().ok(), md.modified().ok()) {
(Some(c), Some(m)) => Some(c.min(m)),
(Some(t), None) | (None, Some(t)) => Some(t),
(None, None) => None,
}
}
#[cfg(test)]
mod tests {
use super::*;