summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLzzzzzt <101313294+Lzzzzzt@users.noreply.github.com>2023-07-31 00:58:07 +0800
committerGitHub <noreply@github.com>2023-07-30 12:58:07 -0400
commit713bd70d88eff0cb5130c2661fdf84fb2d09ab2a (patch)
tree66b9b971b5941f88127eef80911f1bec25173658
parent9d1a0b2ca8616af3eefb2a26b6f77a62420ecc8a (diff)
mtime will display with local timezone (#384)
-rw-r--r--src/main.rs9
-rw-r--r--src/ui/widgets/tui_footer.rs4
-rw-r--r--src/util/format.rs2
3 files changed, 12 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 3e2b8bc..03bf646 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -77,6 +77,15 @@ lazy_static! {
static ref HOME_DIR: Option<PathBuf> = dirs_next::home_dir();
static ref USERNAME: String = whoami::username();
static ref HOSTNAME: String = whoami::hostname();
+
+ static ref TIMEZONE_STR: String = {
+ let offset = chrono::Local::now().offset().local_minus_utc() / 3600;
+ if offset.is_positive() {
+ format!(" UTC+{} ", offset.abs())
+ } else {
+ format!(" UTC-{} ", offset.abs())
+ }
+ };
}
#[derive(Clone, Debug, StructOpt)]
diff --git a/src/ui/widgets/tui_footer.rs b/src/ui/widgets/tui_footer.rs
index adfe90d..dc42ee6 100644
--- a/src/ui/widgets/tui_footer.rs
+++ b/src/ui/widgets/tui_footer.rs
@@ -8,7 +8,7 @@ use crate::config::option::TabDisplayOption;
use crate::fs::{JoshutoDirList, LinkType};
use crate::util::format;
use crate::util::unix;
-use crate::THEME_T;
+use crate::{THEME_T, TIMEZONE_STR};
pub struct TuiFooter<'a> {
dirlist: &'a JoshutoDirList,
@@ -73,7 +73,7 @@ impl<'a> Widget for TuiFooter<'a> {
Span::raw(format!("{}/{}", i + 1, self.dirlist.len())),
Span::raw(" "),
Span::raw(mtime_str),
- Span::raw(" UTC "),
+ Span::raw(TIMEZONE_STR.as_str()),
Span::raw(size_str),
Span::raw(" "),
Span::styled(
diff --git a/src/util/format.rs b/src/util/format.rs
index cd73605..0c515bb 100644
--- a/src/util/format.rs
+++ b/src/util/format.rs
@@ -23,6 +23,6 @@ pub fn file_size_to_string(file_size: u64) -> String {
pub fn mtime_to_string(mtime: time::SystemTime) -> String {
const MTIME_FORMATTING: &str = "%Y-%m-%d %H:%M";
- let datetime: chrono::DateTime<chrono::offset::Utc> = mtime.into();
+ let datetime: chrono::DateTime<chrono::offset::Local> = mtime.into();
datetime.format(MTIME_FORMATTING).to_string()
}