Skip to content

Commit 8cb63b5

Browse files
committed
Only call clocks once in fallback path for getting dates for issues
When chrono::clock_cast isn't available we use chrono::system_clock and chrono::file_clock, but we should only call them once so that we use consistent times for all issues.
1 parent af0aa5a commit 8cb63b5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/issues.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,19 @@ auto report_date_file_last_modified(std::filesystem::path const & filename, lwg:
5858
using namespace std::chrono;
5959
system_clock::time_point t;
6060
int id = std::stoi(filename.filename().stem().native().substr(5));
61+
// Use the Git commit date of the file if available.
6162
if (auto it = meta.git_commit_times.find(id); it != meta.git_commit_times.end())
6263
t = system_clock::from_time_t(it->second);
6364
else {
65+
// Otherwise use the modification time of the file.
6466
auto mtime = fs::last_write_time(filename);
6567
#if __cpp_lib_chrono >= 201803L
6668
t = clock_cast<system_clock>(mtime);
6769
#else
68-
auto fnow = fs::file_time_type::clock::now();
69-
t = system_clock::now() - round<seconds>(fnow - mtime);
70+
// clock_cast isn't supported, so convert to sys_time manually.
71+
static const auto snow = system_clock::now();
72+
static const auto fnow = fs::file_time_type::clock::now();
73+
t = snow - round<seconds>(fnow - mtime);
7074
#endif
7175
}
7276

0 commit comments

Comments
 (0)