Skip to content

Commit

Permalink
add exact upload dates to list info
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jan 20, 2024
1 parent 04601f3 commit aeee7e5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/hooks/GJLevelList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <Geode/Bindings.hpp>
#include <Geode/modify/GJLevelList.hpp>

#include "../utils.hpp"

using namespace geode::prelude;

class $modify(BIGJLevelList, GJLevelList) {
void showListInfo() {
std::stringstream ss;
ss << std::string(getUnpackedDescription()) << "\n\n";

if(m_listID > 0) ss << "List ID: <cy>" << m_listID << "</c>\n";
if(m_uploadDate > 0) ss << "Uploaded: <cy>" << TimeUtils::timestampToHumanReadable(m_uploadDate) << " ago</c> <cl>(" << TimeUtils::timeToString(m_uploadDate) << ")</c>\n";
if(m_updateDate > 0) ss << "Updated: <cy>" << TimeUtils::timestampToHumanReadable(m_updateDate) << " ago</c> <cl>(" << TimeUtils::timeToString(m_updateDate) << ")</c>";

FLAlertLayer::create(nullptr, "List Info", ss.str().c_str(), "OK", nullptr, 380.f)->show();
}
};
17 changes: 17 additions & 0 deletions src/utils/TimeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,21 @@ std::string TimeUtils::platformerTime(int value){
if(hours > 0) return fmt::format("{}:{}:{}.{}", hours, minutes, seconds, milliseconds);
if(minutes > 0) return fmt::format("{}:{}.{}", minutes, seconds, milliseconds);
return fmt::format("{}.{}", seconds, milliseconds);
}

std::string TimeUtils::timestampToHumanReadable(time_t timestamp) {
auto diff = difftime(time(nullptr), timestamp);

int years = diff / 31536000;
int months = diff / 2592000;
int days = diff / 86400;
int hours = diff / 3600;
int minutes = diff / 60;

if(years > 0) return fmt::format("{} year{}", years, years > 1 ? "s" : "");
if(months > 0) return fmt::format("{} month{}", months, months > 1 ? "s" : "");
if(days > 0) return fmt::format("{} day{}", days, days > 1 ? "s" : "");
if(hours > 0) return fmt::format("{} hour{}", hours, hours > 1 ? "s" : "");
if(minutes > 0) return fmt::format("{} minute{}", minutes, minutes > 1 ? "s" : "");
return "Less than 1 minute";
}
1 change: 1 addition & 0 deletions src/utils/TimeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ namespace TimeUtils {
std::string isoTimeToString(const std::string& input);
std::string workingTime(int value);
std::string platformerTime(int value);
std::string timestampToHumanReadable(time_t timestamp);
}

0 comments on commit aeee7e5

Please sign in to comment.