Fix parsing of exif datetimes
We previously tried to parse the exif datetime as an ISO datetime string, however the date parse uses colons instead of dashes in exif. This meant that the modification time was used for every image instead of the exif date.
This commit is contained in:
10
src/main.rs
10
src/main.rs
@ -26,6 +26,7 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
// * Brute-force protection / rate-limiting
|
||||
// * Support for headlines
|
||||
// * Image cache cleanup
|
||||
// * Limit session time (inactivity timeout)
|
||||
|
||||
type TemplateEngine = Engine<minijinja::Environment<'static>>;
|
||||
type ImageDir = PathBuf;
|
||||
@ -452,10 +453,13 @@ fn read_image_info(path: &Path) -> Result<ImageInfo> {
|
||||
.and_then(extract_exif_string);
|
||||
|
||||
match (datetime_without_timezone, timezone) {
|
||||
(Some(datetime), Some(timezone)) => (datetime + &timezone).parse().ok(),
|
||||
(Some(datetime), None) => (datetime + "Z").parse().ok(),
|
||||
(Some(datetime), Some(timezone)) => Some(datetime + &timezone),
|
||||
(Some(datetime), None) => Some(datetime + "+00:00"),
|
||||
_ => None,
|
||||
}
|
||||
}.and_then(|datetime| {
|
||||
DateTime::parse_from_str(&datetime, "%Y:%m:%d %T%:z")
|
||||
.ok().map(|d| d.with_timezone(&Utc))
|
||||
})
|
||||
}).or_else(|| {
|
||||
// If that doesn't work, fall back to the file modification time
|
||||
std::fs::metadata(path)
|
||||
|
Reference in New Issue
Block a user