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

show future commit dates without panicking #1389

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

MalteT
Copy link
Contributor

@MalteT MalteT commented Aug 8, 2024

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 library time_humanize can already handle this.

Thanks!

@MalteT MalteT requested a review from o2sh as a code owner August 8, 2024 14:15
Copy link
Collaborator

@spenserblack spenserblack left a 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? 🤔

Comment on lines 27 to 36
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()
Copy link
Owner

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

@MalteT MalteT force-pushed the feat/graceful-future-commit-dates branch from 6816f9a to bd56fa0 Compare August 10, 2024 19:01
@MalteT
Copy link
Contributor Author

MalteT commented Aug 10, 2024

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? 🤔

🕰️🚀

Maybe those? Did you plan on having something like this?
image

@spenserblack
Copy link
Collaborator

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.

Copy link
Owner

@o2sh o2sh left a 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 🎉

@o2sh o2sh merged commit 61ab298 into o2sh:main Aug 15, 2024
10 checks passed
@MalteT
Copy link
Contributor Author

MalteT commented Aug 15, 2024

I think we can leave out the emoji for now 🤔

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 🤔

@MalteT MalteT deleted the feat/graceful-future-commit-dates branch August 15, 2024 09:13
@spenserblack
Copy link
Collaborator

is there a config option for emojis?

Nope, because we don't have any emojis in the output yet.

@o2sh o2sh added the fix label Sep 15, 2024
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 23, 2024
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 [@&#8203;Localghost385](https://github.com/Localghost385) in o2sh/onefetch#1395
-   \[onefetch.dev] Add nerdfont iconts to the preview by [@&#8203;Localghost385](https://github.com/Localghost385) in o2sh/onefetch#1411
-   Automate publishing crates to crates.io by [@&#8203;musicinmybrain](https://github.com/musicinmybrain) in o2sh/onefetch#1364

##### Bug Fixes 🐛

-   Show future commit dates without panicking by [@&#8203;MalteT](https://github.com/MalteT) in o2sh/onefetch#1389

##### Chores 🧹

-   Re-generate the man page with --no-info by [@&#8203;musicinmybrain](https://github.com/musicinmybrain) in o2sh/onefetch#1376
-   Drop unused shebangs from repo test fixture scripts by [@&#8203;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: [#&#8203;1389](o2sh/onefetch#1389), [#&#8203;1395](o2sh/onefetch#1395), [#&#8203;1404](o2sh/onefetch#1404)

##### Commit Details

<csr-read-only-do-not-edit/>

<details><summary>view details</summary>

-   **[#&#8203;1389](o2sh/onefetch#1389
    -   Show future commit dates without panicking ([`61ab298`](o2sh/onefetch@61ab298))
-   **[#&#8203;1395](o2sh/onefetch#1395
    -   Add support for nerd font glyphs in languages info ([`6bf1807`](o2sh/onefetch@6bf1807))
-   **[#&#8203;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=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle future commit datetimes in the future without panicking
3 participants