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

Make time test relative to current time #613

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/info/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ mod tests {

use super::*;
use git2::Time;
use std::time::SystemTime;
use std::time::{Duration, SystemTime};

#[test]
fn display_time_as_human_time_current_time_now() {
Expand All @@ -379,8 +379,13 @@ mod tests {

#[test]
fn display_time_as_human_time_current_time_arbitrary() {
let time = 1600000000;
let time = Time::new(time, 0);
let day = Duration::from_secs(60 * 60 * 24);
let current_time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap();
// NOTE 366 so that it's a year ago even with leap years.
let year_ago = current_time - (day * 366);
let time = Time::new(year_ago.as_secs() as i64, 0);
let result = git_time_to_formatted_time(&time, false);
assert_eq!(result, "a year ago");
}
Expand Down