-
Notifications
You must be signed in to change notification settings - Fork 277
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
show future commit dates without panicking #1389
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The simplest solution is often the best. I think saying that the repo is created "in x days/hours/etc." is an elegant and clear way to call out a time traveler.
Is there an emoji combo that can represent a time traveler? 🤔
src/info/utils/mod.rs
Outdated
let since_epoch_duration = SystemTime::now() | ||
.duration_since(SystemTime::UNIX_EPOCH) | ||
.unwrap(); | ||
|
||
let ts = Duration::from_secs(match time.seconds.try_into() { | ||
Ok(s) => s, | ||
Err(_) => return "<before UNIX epoch>".into(), | ||
}); | ||
let duration = since_epoch_duration.checked_sub(ts).expect( | ||
"Achievement unlocked: time travel! \ | ||
Check your system clock and commit dates.", | ||
); | ||
let ht = HumanTime::from(-(duration.as_secs() as i64)); | ||
// Calculate the distance from the current time. This handles | ||
// future dates gracefully and will simply return something like `in 5 minutes` | ||
let duration = (ts.as_secs() as i64) - (since_epoch_duration.as_secs() as i64); | ||
let ht = HumanTime::from(duration); | ||
ht.to_string() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a suggestion to simplify the logic and handle commit time before epoch :
fn to_human_time(time: Time) -> String {
let since_epoch_duration = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("System time is before the Unix epoch");
// Calculate the distance from the current time. This handles
// future dates gracefully and will simply return something like `in 5 minutes`
let delta_in_seconds = time.seconds - (since_epoch_duration.as_secs() as i64);
HumanTime::from(delta_in_seconds).to_string()
}
It will also require to update the unit test display_time_before_epoch
to avoid an underflow
6816f9a
to
bd56fa0
Compare
That emoji combo looks good! I'm not saying we have to add those, I was kind of half-joking. But it could be fun as an easter egg. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can leave out the emoji for now 🤔
Thanks a lot for you contribution @MalteT and @spenserblack for the review 🎉
Depending on the requirements (is there a config option for emojis? would we always show the with the message?) I would be willing to open a mini PR to add that, @o2sh 🤔 |
Nope, because we don't have any emojis in the output yet. |
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [o2sh/onefetch](https://github.com/o2sh/onefetch) | minor | `2.21.0` -> `2.22.0` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>o2sh/onefetch (o2sh/onefetch)</summary> ### [`v2.22.0`](https://github.com/o2sh/onefetch/blob/HEAD/CHANGELOG.md#2220-2024-09-20) [Compare Source](o2sh/onefetch@2.21.0...2.22.0) ##### New Features 🎉 - Add support for nerd font glyphs in languages info by [@​Localghost385](https://github.com/Localghost385) in o2sh/onefetch#1395 - \[onefetch.dev] Add nerdfont iconts to the preview by [@​Localghost385](https://github.com/Localghost385) in o2sh/onefetch#1411 - Automate publishing crates to crates.io by [@​musicinmybrain](https://github.com/musicinmybrain) in o2sh/onefetch#1364 ##### Bug Fixes 🐛 - Show future commit dates without panicking by [@​MalteT](https://github.com/MalteT) in o2sh/onefetch#1389 ##### Chores 🧹 - Re-generate the man page with --no-info by [@​musicinmybrain](https://github.com/musicinmybrain) in o2sh/onefetch#1376 - Drop unused shebangs from repo test fixture scripts by [@​musicinmybrain](https://github.com/musicinmybrain) in o2sh/onefetch#1375 ##### Commit Statistics <csr-read-only-do-not-edit/> - 3 commits contributed to the release. - 135 days passed between releases. - 0 commits were understood as [conventional](https://www.conventionalcommits.org). - 3 unique issues were worked on: [#​1389](o2sh/onefetch#1389), [#​1395](o2sh/onefetch#1395), [#​1404](o2sh/onefetch#1404) ##### Commit Details <csr-read-only-do-not-edit/> <details><summary>view details</summary> - **[#​1389](o2sh/onefetch#1389 - Show future commit dates without panicking ([`61ab298`](o2sh/onefetch@61ab298)) - **[#​1395](o2sh/onefetch#1395 - Add support for nerd font glyphs in languages info ([`6bf1807`](o2sh/onefetch@6bf1807)) - **[#​1404](o2sh/onefetch#1404 - Bump gix from 0.64.0 to 0.66.0 in the gix group ([`19f77b2`](o2sh/onefetch@19f77b2)) </details> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Fixes #1306.
Sorry for the long wait! This is the lamest solution I found, the tool will simply display the time as
in 5 days
. The librarytime_humanize
can already handle this.Thanks!