diff --git a/src/image_metadata/mod.rs b/src/image_metadata/mod.rs index 5e23ef5..8303295 100644 --- a/src/image_metadata/mod.rs +++ b/src/image_metadata/mod.rs @@ -10,6 +10,7 @@ pub use gps::GPSLocation; pub use obj::LpImageMetadata; use crate::i18n::*; +use crate::util; use gtk::glib; @@ -95,10 +96,7 @@ impl ImageMetadata { dt.minute.into(), dt.second.into(), ) { - // Translators: Date (%x) and time (%X) combined - if let Ok(formatted) = datetime.format(&i18n("%x %X")) { - return Some(formatted.to_string()); - } + return util::datetime_fmt(&datetime); } } } diff --git a/src/util.rs b/src/util.rs index 02d3523..347c5bb 100644 --- a/src/util.rs +++ b/src/util.rs @@ -8,6 +8,22 @@ use once_cell::sync::Lazy; use std::fmt::{Debug, Write}; use std::path::{Path, PathBuf}; +/// Returns localized date + time format +pub fn datetime_fmt(datetime: &glib::DateTime) -> Option { + // Translators: This is the date and time format we use in metadata output etc. + // The format has to follow + // The default is already translated. Don't change if you are not sure what to use. + let datetime_format = i18n("%x %X"); + + let fmt = datetime.format(&datetime_format); + + if let Err(err) = &fmt { + log::error!("Could not format DateTime with '{datetime_format}': {err}"); + } + + fmt.ok().map(|x| x.to_string()) +} + pub fn get_file_display_name(file: &gio::File) -> Option { let info = query_attributes(file, vec![gio::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME]).ok()?; diff --git a/src/widgets/properties_view.rs b/src/widgets/properties_view.rs index 92b9686..8154176 100644 --- a/src/widgets/properties_view.rs +++ b/src/widgets/properties_view.rs @@ -355,16 +355,14 @@ impl LpPropertiesView { #[template_callback] fn created_date(&self, info: Option) -> String { info.and_then(|i| i.creation_date_time()) - .and_then(|t| t.format("%x, %X").ok()) - .map(|t| t.to_string()) + .and_then(|t| util::datetime_fmt(&t)) .unwrap_or_else(|| FALLBACK.to_owned()) } #[template_callback] fn modified_date(&self, info: Option) -> String { info.and_then(|i| i.modification_date_time()) - .and_then(|t| t.format("%x, %X").ok()) - .map(|t| t.to_string()) + .and_then(|t| util::datetime_fmt(&t)) .unwrap_or_else(|| FALLBACK.to_owned()) }