Skip to content

Commit b70f296

Browse files
committed
local-time: switch from time to jiff
This swaps out `time` in favor of `jiff` for getting and formatting the local time. Note that this does add the `%Z` to the format string, which will write out time zone abbreviations like `EDT` along with the local datetime itself. The `time` crate doesn't support this, but jiff's tzdb integration let's it do it.
1 parent 10800f3 commit b70f296

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ render-line = ["crosstermion/color", "humantime", "unicode-width"]
5454
render-line-crossterm = ["crosstermion/crossterm"]
5555
render-line-autoconfigure = ["is-terminal"]
5656

57-
local-time = ["time"]
57+
local-time = ["jiff"]
5858

5959
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
6060
[dependencies]
@@ -76,7 +76,7 @@ crosstermion = { version = "0.14.0", optional = true, default-features = false }
7676
async-io = { version = "2.2.1", optional = true }
7777

7878
# localtime support for render-tui
79-
time = { version = "0.3.2", optional = true, features = ["std", "local-offset", "formatting"], default-features = false }
79+
jiff = { version = "0.1.1", optional = true }
8080

8181
# line renderer
8282
ctrlc = { version = "3.1.4", optional = true, default-features = false, features = ['termination'] }

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub use log::info;
4949
#[cfg(feature = "progress-tree-log")]
5050
pub use log::warn;
5151

52-
#[cfg(any(feature = "humantime", feature = "time"))]
52+
#[cfg(any(feature = "humantime", feature = "local-time"))]
5353
///
5454
pub mod time;
5555

src/time.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22
mod localtime {
33
use std::time::SystemTime;
44

5+
use jiff::Zoned;
6+
57
/// Return a string representing the current date and time as localtime.
68
///
79
/// Available with the `localtime` feature toggle.
810
pub fn format_now_datetime_seconds() -> String {
9-
let t = time::OffsetDateTime::now_utc();
10-
t.to_offset(time::UtcOffset::local_offset_at(t).unwrap_or(time::UtcOffset::UTC))
11-
.format(&time::format_description::parse("%F %T").expect("format known to work"))
12-
.expect("formatting always works")
11+
Zoned::now().strftime("%F %T %Z").to_string()
1312
}
1413

1514
/// Return a string representing the current time as localtime.
1615
///
1716
/// Available with the `localtime` feature toggle.
1817
pub fn format_time_for_messages(time: SystemTime) -> String {
19-
time::OffsetDateTime::from(time)
20-
.to_offset(time::UtcOffset::current_local_offset().unwrap_or(time::UtcOffset::UTC))
21-
.format(&time::format_description::parse("[hour]:[minute]:[second]").expect("format known to work"))
22-
.expect("formatting always works")
18+
Zoned::try_from(time)
19+
.expect("system time is always in range -9999-01-01..=9999-12-31")
20+
.strftime("%T")
21+
.to_string()
2322
}
2423
}
2524

0 commit comments

Comments
 (0)