Skip to content

Commit

Permalink
feat(term): use local timezone when displaying time (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt authored Jun 20, 2024
1 parent 1dccd4f commit 36212b4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/synd_term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ synd-o11y = { path = "../synd_o11y", version = "0.1.7" }

anyhow = { workspace = true }
bitflags = { workspace = true }
chrono = { workspace = true, features = ["std", "now", "serde"] }
chrono = { workspace = true, features = ["std", "now", "serde", "clock"] }
clap = { workspace = true, features = ["derive", "string", "color", "suggestions", "wrap_help", "env", "std"] }
crossterm = { version = "0.27.0", features = ["event-stream"] }
directories = "5.0.1"
Expand Down
20 changes: 18 additions & 2 deletions crates/synd_term/src/types/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@ pub trait TimeExt {
fn local_ymd_hm(&self) -> String;
}

#[cfg(feature = "integration")]
impl TimeExt for Time {
fn local_ymd(&self) -> String {
self.naive_local().format("%Y-%m-%d").to_string()
self.format("%Y-%m-%d").to_string()
}

fn local_ymd_hm(&self) -> String {
self.naive_local().format("%Y-%m-%d %H:%M").to_string()
self.format("%Y-%m-%d %H:%M (%:z)").to_string()
}
}

#[cfg(not(feature = "integration"))]
impl TimeExt for Time {
fn local_ymd(&self) -> String {
self.with_timezone(&chrono::Local)
.format("%Y-%m-%d")
.to_string()
}

fn local_ymd_hm(&self) -> String {
self.with_timezone(&chrono::Local)
.format("%Y-%m-%d %H:%M (%:z)")
.to_string()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Buffer {
"────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────",
" 󰯂 Entry 2024-06-03 ",
" 󰏌 URL https://buttondown.email/o11y.news/archive/2024-06-03/ ",
"  Published 2024-06-03 20:00 ",
"  Published 2024-06-03 20:00 (+00:00) ",
" ",
" 󱙓 Summary ",
" ## Booking.com’s o11y platform ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Buffer {
"────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────",
" 󰯂 Entry 2024-06-03 ",
" 󰏌 URL https://buttondown.email/o11y.news/archive/2024-06-03/ ",
"  Published 2024-06-03 20:00 ",
"  Published 2024-06-03 20:00 (+00:00) ",
" ",
" 󱙓 Summary ",
" ## Booking.com’s o11y platform ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Buffer {
"────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────",
" 󰯂 Entry This Week in Rust 549 ",
" 󰏌 URL https://this-week-in-rust.org/blog/2024/05/29/this-week-in-rust-549/ ",
"  Published 2024-05-29 04:00 ",
"  Published 2024-05-29 04:00 (+00:00) ",
" ",
" 󱙓 Summary ",
" Hello and welcome to another issue of *This Week in Rust*! [Rust][1] is a programming language empowering everyone ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Buffer {
"────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────",
" 󰯂 Entry This Week in Rust 549 ",
" 󰏌 URL https://this-week-in-rust.org/blog/2024/05/29/this-week-in-rust-549/ ",
"  Published 2024-05-29 04:00 ",
"  Published 2024-05-29 04:00 (+00:00) ",
" ",
" 󱙓 Summary ",
" Hello and welcome to another issue of *This Week in Rust*! [Rust][1] is a programming language empowering everyone ",
Expand Down

0 comments on commit 36212b4

Please sign in to comment.