diff options
author | Teddy Wing | 2022-06-04 19:15:35 +0200 |
---|---|---|
committer | Teddy Wing | 2022-06-04 19:15:35 +0200 |
commit | 57cd001192adc095843af0c18044ff996fca0480 (patch) | |
tree | 0bc91c1c3b41abe4cfccf039d6f5c64bb55b5ae1 /src/database.rs | |
parent | 627d6c7e2b0e218213fa2a9c19036489c66c3141 (diff) | |
parent | 6fe38d83ec90f5adb411706ed23d9a8b2929aed8 (diff) | |
download | reflectub-57cd001192adc095843af0c18044ff996fca0480.tar.bz2 |
Merge branch 'make-errors-more-traceable-2'
Diffstat (limited to 'src/database.rs')
-rw-r--r-- | src/database.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/database.rs b/src/database.rs index ed5d327..09fedd7 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Teddy Wing +// Copyright (c) 2021, 2022 Teddy Wing // // This file is part of Reflectub. // @@ -44,12 +44,32 @@ impl Repo { impl From<&github::Repo> for Repo { fn from(repo: &github::Repo) -> Self { + use chrono::DateTime; + + let repo_updated_at = DateTime::parse_from_rfc3339(&repo.updated_at).ok(); + let repo_pushed_at = DateTime::parse_from_rfc3339(&repo.pushed_at).ok(); + + // Set `updated_at` to the most recent of `repo_updated_at` or + // `repo_pushed_at`. + let updated_at = + if repo_updated_at.is_none() && repo_pushed_at.is_none() { + repo.updated_at.clone() + + // `repo_updated_at` and `repo_pushed_at` are both Some. + } else if repo_pushed_at.unwrap() > repo_updated_at.unwrap() { + repo.pushed_at.clone() + + // Default to `repo.updated_at`. + } else { + repo.updated_at.clone() + }; + Self { id: repo.id, name: Some(repo.name.clone()), description: repo.description.clone(), default_branch: Some(repo.default_branch.clone()), - updated_at: Some(repo.updated_at.clone()), + updated_at: Some(updated_at), } } } |