Use chrono library instead

This commit is contained in:
David Markowitz 2025-05-14 01:14:07 -07:00
parent 6e959492db
commit d993a772d7
2 changed files with 7 additions and 5 deletions

View File

@ -180,14 +180,16 @@ std::vector<ILeaderboard::Entry> FilterToNumResults(const std::vector<ILeaderboa
}
std::vector<ILeaderboard::Entry> FilterWeeklies(const std::vector<ILeaderboard::Entry>& leaderboard) {
using namespace std::chrono;
// Filter the leaderboard to only include entries from the last week
const auto currentTime = std::chrono::system_clock::now();
auto epochTime = std::chrono::duration_cast<std::chrono::seconds>(currentTime.time_since_epoch()).count();
constexpr auto SECONDS_IN_A_WEEK = 60 * 60 * 24 * 7; // if you think im taking leap seconds into account thats cute.
const auto epochTime = system_clock::now();
constexpr auto oneWeek = weeks(1);
std::vector<ILeaderboard::Entry> weeklyLeaderboard;
for (const auto& entry : leaderboard) {
if (epochTime - entry.lastPlayedTimestamp < SECONDS_IN_A_WEEK) {
const sys_time<seconds> asSysTime(seconds(entry.lastPlayedTimestamp));
const auto timeDiff = epochTime - asSysTime;
if (timeDiff < oneWeek) {
weeklyLeaderboard.push_back(entry);
}
}

View File

@ -1698,7 +1698,7 @@ void GameMessages::HandleRequestActivitySummaryLeaderboardData(RakNet::BitStream
bool weekly = inStream.ReadBit();
// The client cant accept more than 10 results.
// The client won't accept more than 10 results even if we wanted it to
LeaderboardManager::SendLeaderboard(gameID, queryType, weekly, entity->GetObjectID(), entity->GetObjectID(), 10);
}