Skip to content

Conversation

spenserblack
Copy link
Collaborator

Related: #1306

@spenserblack spenserblack marked this pull request as ready for review April 11, 2024 13:38
@spenserblack spenserblack requested a review from o2sh as a code owner April 11, 2024 13:38
@spenserblack
Copy link
Collaborator Author

cc @Byron just confirming that gix::date::Time.offset is getting used correctly here.

Copy link
Collaborator

@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.

Thanks for reeling me in.

Generally I recommend adding way more tests, and also see what happens with unusual times which are absolutely possible. Future dates and pre-epoch dates, which I believe definitely shouldn't panic.

let ts = Duration::from_secs(match (time.seconds + i64::from(time.offset)).try_into() {
Ok(s) => s,
Err(_) => return "<before UNIX epoch>".into(),
Err(_) => return Err("<before UNIX epoch>".into()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

gitoxide supports times before unix epoch, but of course, there are dates outside of the valid range of i64.

@spenserblack
Copy link
Collaborator Author

Thanks for the review @Byron!

Future dates and pre-epoch dates, which I believe definitely shouldn't panic.

This is currently being discussed in #1306, and will probably be a separate PR.

/// Gets the duration between `now` and `time`. Returns `Err` if this cannot be calculated.
fn diff_gix_time(now: SystemTime, time: Time) -> Result<Duration, String> {
let since_epoch_duration = now.duration_since(SystemTime::UNIX_EPOCH).unwrap();
let ts = Duration::from_secs(match (time.seconds + i64::from(time.offset)).try_into() {
Copy link
Owner

@o2sh o2sh Apr 14, 2024

Choose a reason for hiding this comment

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

I'm a bit confused. Why do we need to consider the offset here? This method should simply return the difference between two UTC timestamps (without timezone): now (since epoch in UTC+0) - commit.time (since epoch in UTC+0.

Sorry if I'm mistaken.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made this with the assumption that #1306 was caused by differing timezones, which was an incorrect assumption, which made me assume that we were comparing a timezone-aware time to a naive time. Right now, personally, I am not sure if commit.time.seconds is UTC+0 or if it's a naive time that needs offset to get the real time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry, I also didn't catch it. commit.time.seconds is UTC. The doc-string there unfortunately only implies it ("time in seconds since epoch."). I have fixed this here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I guess this PR should be closed, then.

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