Skip to content

Commit

Permalink
tag parser tries also Tag::DateTime field
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Oct 6, 2024
1 parent cf59801 commit 3949787
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions src/datetime_tag_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,34 @@ pub fn captures(path: &Path) -> Result<Option<chrono::DateTime<chrono::Utc>>, ex
// println!(" {:?}", f.value);
//}

match exif.get_field(Tag::DateTimeOriginal, In::PRIMARY) {
Some(field) => match field.value {
Value::Ascii(ref vec) if !vec.is_empty() => {
let datetime = DateTime::from_ascii(&vec[0])?;
Ok(Some(
NaiveDate::from_ymd_opt(
i32::from(datetime.year),
u32::from(datetime.month),
u32::from(datetime.day),
)
.unwrap()
.and_hms_milli_opt(
u32::from(datetime.hour),
u32::from(datetime.minute),
u32::from(datetime.second),
0,
)
.unwrap()
.and_utc(),
))
}
_ => Ok(None),
let field = match exif.get_field(Tag::DateTime, In::PRIMARY) {
Some(field) => field,
None => match exif.get_field(Tag::DateTimeOriginal, In::PRIMARY) {
Some(field) => field,
None => return Ok(None),
},
None => Ok(None),
}
};

//if let Some(field) = exif.get_field(Tag::DateTime, In::PRIMARY) {
// match field.value {
// Value::Ascii(ref vec) if !vec.is_empty() => {
// if let Ok(datetime) = DateTime::from_ascii(&vec[0]) {
// println!("Year of DateTime is {}.", datetime.year);
// }
// }
// _ => {}
// }
//}
match field.value {
Value::Ascii(ref vec) if !vec.is_empty() => {
let datetime = DateTime::from_ascii(&vec[0])?;
Ok(Some(
NaiveDate::from_ymd_opt(
i32::from(datetime.year),
u32::from(datetime.month),
u32::from(datetime.day),
)
.unwrap()
.and_hms_milli_opt(
u32::from(datetime.hour),
u32::from(datetime.minute),
u32::from(datetime.second),
0,
)
.unwrap()
.and_utc(),
))
}
_ => Ok(None),
}
}

0 comments on commit 3949787

Please sign in to comment.