Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

local-time: switch from time to jiff #31

Merged
merged 1 commit into from
Jul 29, 2024
Merged

Conversation

BurntSushi
Copy link
Contributor

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.

@BurntSushi
Copy link
Contributor Author

Let me know if you want me to remove the %Z directive.

@Byron Byron self-assigned this Jul 29, 2024
@Byron
Copy link
Owner

Byron commented Jul 29, 2024

Thanks a lot for contributing! I can't wait to merge and use it from within gitoxide.

A quick test showed that it didn't actually show the local time though, but I am looking into it to see what the issue could be.

> RUST_LOG=info cargo run --example dashboard --features="local-time render-tui render-tui-crossterm render-line render-line-crossterm signal-hook render-line-autoconfigure progress-tree" -- -R log
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 计数代码行 4 → 进展良好!
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 检查未使用的依赖项 → Humming along…
[2024-07-29T13:28:36Z INFO  prodash::tree::item] Checking for unused dependencies 4 → 感觉好极了!
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 检查未使用的依赖项 11 → It feels good to be done!
[2024-07-29T13:28:36Z INFO  prodash::tree::item] Generating report → Told you so!!
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 下载板条箱 8 → Making good progress!
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 下载板条箱 4 → 会很快完成的……
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 计数代码行 7 → It will be done soooooon…
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 计数代码行 7 → Humming along…
[2024-07-29T13:28:36Z WARN  prodash::tree::item] 下载板条箱 3 → This didn't end well…
[2024-07-29T13:28:36Z INFO  prodash::tree::item] Generating report 4 → It will be done soooooon…
[2024-07-29T13:28:36Z INFO  prodash::tree::item] Generating report 1 → 会很快完成的……
[2024-07-29T13:28:36Z INFO  prodash::tree::item] Generating report 5 → 会很快完成的……
[2024-07-29T13:28:36Z INFO  prodash::tree::item] Generating report 3 → 会很快完成的……
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 检查板条箱膨胀 3 → It feels good to be done!
[2024-07-29T13:28:36Z INFO  prodash::tree::item] Running 'cargo geiger' → 嗡嗡作响…
[2024-07-29T13:28:36Z WARN  prodash::tree::item] Checking for unused dependencies 6 → Oh my… I failed you 😞
[2024-07-29T13:28:36Z INFO  prodash::tree::item] 运行程序 'cargo geiger' → It will be done soooooon…
[2024-07-29T13:28:36Z WARN  prodash::tree::item] 检查未使用的依赖项 → This didn't end well…
[2024-07-29T13:28:36Z INFO  prodash::tree::item] Counting lines of code → 嗡嗡作响…

The time displayed is UTC, I should be +2h.

Answer

I was looking at RustLog output, which naturally doesn't use local times (or needs configuration to do).

@Mrmaxmeier
Copy link

You can also drop this outdated part of the README: 🙂

* **On Unix** one needs to provide flags to rustc when building the binary to acknowledge potential unsoundness: `RUSTFLAGS="--cfg unsound_local_offset" cargo build`

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.
@BurntSushi
Copy link
Contributor Author

@Mrmaxmeier Done!

@Byron Yeah, I think env_logger uses humantime which just emits logs in UTC since it doesn't have any "local" time support. It'd be cool for env_logger to have a feature that prints in local time, although I could see folks actually specifically wanting UTC.

Copy link
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a while, but here (in the header) is how it looks with the new timezone display.

Screenshot 2024-07-29 at 15 46 25

I love it!

@Byron Byron merged commit 87f66fb into Byron:main Jul 29, 2024
2 checks passed
@Byron
Copy link
Owner

Byron commented Jul 29, 2024

Great, a new release is out and I will make gitoxide use it real quick.

@BurntSushi BurntSushi deleted the ag/jiff branch July 29, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants