Change display of date and time
This commit is contained in:
parent
3b611ff4fc
commit
cd71c895f9
2 changed files with 35 additions and 23 deletions
|
|
@ -9,6 +9,7 @@ notification-in-progress = File operations are in progress.
|
||||||
trash = Trash
|
trash = Trash
|
||||||
recents = Recents
|
recents = Recents
|
||||||
undo = Undo
|
undo = Undo
|
||||||
|
today = Today
|
||||||
|
|
||||||
# List view
|
# List view
|
||||||
name = Name
|
name = Name
|
||||||
|
|
|
||||||
55
src/tab.rs
55
src/tab.rs
|
|
@ -44,7 +44,7 @@ use std::{
|
||||||
cell::{Cell, RefCell},
|
cell::{Cell, RefCell},
|
||||||
cmp::Ordering,
|
cmp::Ordering,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
fmt,
|
fmt::{self, Display},
|
||||||
fs::{self, Metadata},
|
fs::{self, Metadata},
|
||||||
num::NonZeroU16,
|
num::NonZeroU16,
|
||||||
os::unix::fs::MetadataExt,
|
os::unix::fs::MetadataExt,
|
||||||
|
|
@ -72,7 +72,8 @@ pub const DOUBLE_CLICK_DURATION: Duration = Duration::from_millis(500);
|
||||||
pub const HOVER_DURATION: Duration = Duration::from_millis(1600);
|
pub const HOVER_DURATION: Duration = Duration::from_millis(1600);
|
||||||
|
|
||||||
//TODO: adjust for locales?
|
//TODO: adjust for locales?
|
||||||
const TIME_FORMAT: &'static str = "%a %-d %b %-Y %r";
|
const DATE_TIME_FORMAT: &'static str = "%b %-d, %-Y, %-I:%M %p";
|
||||||
|
const TIME_FORMAT: &'static str = "%-I:%M %p";
|
||||||
static SPECIAL_DIRS: Lazy<HashMap<PathBuf, &'static str>> = Lazy::new(|| {
|
static SPECIAL_DIRS: Lazy<HashMap<PathBuf, &'static str>> = Lazy::new(|| {
|
||||||
let mut special_dirs = HashMap::new();
|
let mut special_dirs = HashMap::new();
|
||||||
if let Some(dir) = dirs::document_dir() {
|
if let Some(dir) = dirs::document_dir() {
|
||||||
|
|
@ -260,6 +261,31 @@ fn format_permissions(metadata: &Metadata, owner: PermissionOwner) -> String {
|
||||||
perms.join(" ")
|
perms.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct FormatTime(std::time::SystemTime);
|
||||||
|
|
||||||
|
impl Display for FormatTime {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
let date_time = chrono::DateTime::<chrono::Local>::from(self.0);
|
||||||
|
let now = chrono::Local::now();
|
||||||
|
if date_time.date() == now.date() {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{}, {}",
|
||||||
|
fl!("today"),
|
||||||
|
date_time.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
date_time
|
||||||
|
.format_localized(DATE_TIME_FORMAT, *LANGUAGE_CHRONO)
|
||||||
|
.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format_time(time: std::time::SystemTime) -> FormatTime {
|
||||||
|
FormatTime(time)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn hidden_attribute(_metadata: &Metadata) -> bool {
|
fn hidden_attribute(_metadata: &Metadata) -> bool {
|
||||||
false
|
false
|
||||||
|
|
@ -1010,27 +1036,15 @@ impl Item {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(time) = metadata.created() {
|
if let Ok(time) = metadata.created() {
|
||||||
column = column.push(widget::text(format!(
|
column = column.push(widget::text(format!("Created: {}", format_time(time))));
|
||||||
"Created: {}",
|
|
||||||
chrono::DateTime::<chrono::Local>::from(time)
|
|
||||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(time) = metadata.modified() {
|
if let Ok(time) = metadata.modified() {
|
||||||
column = column.push(widget::text(format!(
|
column = column.push(widget::text(format!("Modified: {}", format_time(time))));
|
||||||
"Modified: {}",
|
|
||||||
chrono::DateTime::<chrono::Local>::from(time)
|
|
||||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(time) = metadata.accessed() {
|
if let Ok(time) = metadata.accessed() {
|
||||||
column = column.push(widget::text(format!(
|
column = column.push(widget::text(format!("Accessed: {}", format_time(time))));
|
||||||
"Accessed: {}",
|
|
||||||
chrono::DateTime::<chrono::Local>::from(time)
|
|
||||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
{
|
{
|
||||||
|
|
@ -1109,8 +1123,7 @@ impl Item {
|
||||||
if let Ok(time) = metadata.modified() {
|
if let Ok(time) = metadata.modified() {
|
||||||
column = column.push(widget::text(format!(
|
column = column.push(widget::text(format!(
|
||||||
"Last modified: {}",
|
"Last modified: {}",
|
||||||
chrono::DateTime::<chrono::Local>::from(time)
|
format_time(time)
|
||||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3051,9 +3064,7 @@ impl Tab {
|
||||||
|
|
||||||
let modified_text = match &item.metadata {
|
let modified_text = match &item.metadata {
|
||||||
ItemMetadata::Path { metadata, .. } => match metadata.modified() {
|
ItemMetadata::Path { metadata, .. } => match metadata.modified() {
|
||||||
Ok(time) => chrono::DateTime::<chrono::Local>::from(time)
|
Ok(time) => format_time(time).to_string(),
|
||||||
.format_localized(TIME_FORMAT, *LANGUAGE_CHRONO)
|
|
||||||
.to_string(),
|
|
||||||
Err(_) => String::new(),
|
Err(_) => String::new(),
|
||||||
},
|
},
|
||||||
ItemMetadata::Trash { .. } => String::new(),
|
ItemMetadata::Trash { .. } => String::new(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue