diff --git a/src/info.cpp b/src/info.cpp new file mode 100644 index 0000000..1910775 --- /dev/null +++ b/src/info.cpp @@ -0,0 +1,52 @@ +#include +#include + +int main() { + cpr::Response r = cpr::Get(cpr::Url{"https://example.com/data.json"}); + auto j = nlohmann::json::parse(r.text); +} + + + + + + + +#include +#include +#include + +// Portable timegm: temporarily override TZ to UTC, call mktime, restore. +// Works on POSIX, MSVC, MinGW, MSYS2 — everywhere mktime exists. +static std::time_t portable_timegm(std::tm* tm) +{ +#if defined(_WIN32) || defined(__MINGW32__) + // _mkgmtime is MSVC/UCRT's timegm equivalent, also available in MSYS2 UCRT64. + return _mkgmtime(tm); +#else + return timegm(tm); +#endif +} + +std::string utcToLocal(const std::string& iso) +{ + std::tm tm = {}; + + // Manual parse — avoids strptime, which MSVC lacks entirely. + // Expected format: "2026-06-20T14:00:00Z" + if (std::sscanf(iso.c_str(), "%d-%d-%dT%d:%d:%dZ", + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) + return iso; // Unparseable -> return as-is. + + tm.tm_year -= 1900; + tm.tm_mon -= 1; + tm.tm_isdst = -1; + + std::time_t utc = portable_timegm(&tm); + std::tm* local = std::localtime(&utc); + + char buf[64]; + std::strftime(buf, sizeof(buf), "%d %b %Y, %H:%M %Z", local); + return buf; +}