Skip to content

Return timestamp of latest unit for file in seconds not nanoseconds #190

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

Merged
merged 1 commit into from
Apr 16, 2024
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
9 changes: 5 additions & 4 deletions lib/CIndexStoreDB/CIndexStoreDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ indexstoredb_symbol_location_path(indexstoredb_symbol_location_t loc) {
double
indexstoredb_symbol_location_timestamp(indexstoredb_symbol_location_t loc) {
auto obj = (SymbolLocation *)loc;
// Up until C++20 the reference date of time_since_epoch is undefined but according to
// Up until C++20 the reference date of time_since_epoch is undefined but according to
// https://en.cppreference.com/w/cpp/chrono/system_clock most implementations use Unix Time.
// Since C++20, system_clock is defined to measure time since 1/1/1970.
// We rely on `time_since_epoch` always returning the nanoseconds since 1/1/1970.
Expand Down Expand Up @@ -676,13 +676,14 @@ indexstoredb_timestamp_of_latest_unit_for_file(
auto obj = (Object<std::shared_ptr<IndexSystem>> *)index;
llvm::Optional<llvm::sys::TimePoint<>> timePoint = obj->value->timestampOfLatestUnitForFile(fileName);
if (timePoint) {
// Up until C++20 the reference date of time_since_epoch is undefined but according to
// Up until C++20 the reference date of time_since_epoch is undefined but according to
// https://en.cppreference.com/w/cpp/chrono/system_clock most implementations use Unix Time.
// Since C++20, system_clock is defined to measure time since 1/1/1970.
// We rely on `time_since_epoch` always returning the nanoseconds since 1/1/1970.
return timePoint->time_since_epoch().count();
auto nanosecondsSinceEpoch = timePoint->time_since_epoch().count();
return static_cast<double>(nanosecondsSinceEpoch) / 1000 / 1000 / 1000;
}
return 0;
}
}

ObjectBase::~ObjectBase() {}