Sync push
This commit is contained in:
parent
ae3153e4e4
commit
893ddf3a83
1 changed files with 52 additions and 0 deletions
52
src/info.cpp
Normal file
52
src/info.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
#include <cpr/cpr.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cpr::Response r = cpr::Get(cpr::Url{"https://example.com/data.json"});
|
||||||
|
auto j = nlohmann::json::parse(r.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue