Skip to content

Commit 87f66fb

Browse files
committed
Merge branch 'ag/jiff'
2 parents 10800f3 + aab0986 commit 87f66fb

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
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'] }

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ This crate comes with various cargo features to tailor it to your needs.
3333
* If set, timestamps in the message pane of the `render-tui` will be using the local time, not UTC
3434
* If set, timestamps of the log messages of the `render-line` will be using the local time, not UTC
3535
* Has no effect without the `render-tui` or `render-line` respectively
36-
* **On Unix** one needs to provide flags to rustc when building the binary to acknowledge potential unsoundness: `RUSTFLAGS="--cfg unsound_local_offset" cargo build`
37-
will do the job, but there are [other ways](https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure) to do that as well.
3836
* **render-line**
3937
* Provide a minimal line-based progress renderer which can be limited to a subset of the progress hierarchy.
4038
* It's like the render-tui, but with far less dependencies and less visual fidelity - all it needs is to move
@@ -50,7 +48,7 @@ This crate comes with various cargo features to tailor it to your needs.
5048
* If enabled, calls to `render::line::Options::auto_configure()` will configure the display based on whether or not we are in a terminal
5149
and set its color mode based on what's possible or desired.
5250
* **signal-hook**
53-
* If set, and the `hide_cursor` line renderer option is set, the cursor will be hidden **and** *SIG_INT* and *SIG_TERM* handlers will be
51+
* If set, and the `hide_cursor` line renderer option is set, the cursor will be hidden **and** *SIG_INT* and *SIG_TERM* handlers will be
5452
installed to reset the cursor on exit. Otherwise you have to make sure to call `shutdown_and_wait()` on the `JoinHandle` returned
5553
to give the renderer a chance to undo the terminal changes. Failing to do so will leave the cusor hidden once the program has already
5654
finished.
@@ -65,7 +63,7 @@ This crate comes with various cargo features to tailor it to your needs.
6563
* Works everywhere natively, but has more dependencies
6664
* You can set additional features like this `cargo build --features render-tui-crossterm,crossterm/event-stream`
6765
* **render-tui-termion**
68-
* Use the `termion` crate as terminal backend
66+
* Use the `termion` crate as terminal backend
6967
* It has less dependencies but works only on `unix` systems
7068
* to get this, disable default features and chose at least `render-tui` and `render-tui-termion`.
7169
* **unit-bytes**
@@ -89,7 +87,7 @@ This crate comes with various cargo features to tailor it to your needs.
8987
* The underlying sync data structure, `dashmap`, does not document every use of unsafe
9088
* I also evaluated `evmap`, which has 25% less uses of unsafe, but a more complex interface.
9189
* Thus far it seemed 'ok' to use, who knows… we are getting mutable pieces of a hashmap from multiple threads,
92-
however, we never hand out multiple handles to the same child which should make actual concurrent access to
90+
however, we never hand out multiple handles to the same child which should make actual concurrent access to
9391
the same key impossible.
9492
* If there are more than 2^16 tasks
9593
* then
@@ -107,7 +105,7 @@ This crate comes with various cargo features to tailor it to your needs.
107105
* trying to draw beyond the terminal boundary will add a line break automatically, which can cause unexpected overdraw.
108106
* **fix**
109107
* count amount of blocks drawn, without ansi codes, and stop drawing at the boundary.
110-
108+
111109
## Lessons Learned
112110

113111
* `drop()` is not garantueed to be called when the future returns Ready and is in the futures::executor::ThreadPool

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)