propertiesView: Unify localized DateTime format
Closes #43 Part-of: <https://gitlab.gnome.org/Incubator/loupe/-/merge_requests/141>
This commit is contained in:
parent
b8d5f833f3
commit
e93020d9ab
3 changed files with 20 additions and 8 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
src/util.rs
16
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<String> {
|
||||
// Translators: This is the date and time format we use in metadata output etc.
|
||||
// The format has to follow <https://docs.gtk.org/glib/method.DateTime.format.html>
|
||||
// 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<String> {
|
||||
let info = query_attributes(file, vec![gio::FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME]).ok()?;
|
||||
|
||||
|
|
|
|||
|
|
@ -355,16 +355,14 @@ impl LpPropertiesView {
|
|||
#[template_callback]
|
||||
fn created_date(&self, info: Option<gio::FileInfo>) -> 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<gio::FileInfo>) -> 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())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue