From a14878b4a453f48f3b200481c343a7fc59181b0f Mon Sep 17 00:00:00 2001 From: Physick <96335032+DegustatorPonos@users.noreply.github.com> Date: Sun, 10 May 2026 18:27:17 +0500 Subject: datetime support --- src/RSS.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/RSS.cpp') diff --git a/src/RSS.cpp b/src/RSS.cpp index a1c0dde..275b96c 100644 --- a/src/RSS.cpp +++ b/src/RSS.cpp @@ -6,6 +6,22 @@ #include #include +#define DT_TEMPLATES_LEN 2 + +const char *DT_TEMPLATES[] = { + "%Y-%m-%dT%H:%M:%SZ", + "%a, %d %b %Y %H:%M:%S GMT", +}; + +std::tm ParseTime(std::string original) { + std::tm parsed{}; + for (auto i = 0; i < DT_TEMPLATES_LEN; i++) { + strptime(original.c_str(), DT_TEMPLATES[i], &parsed); + if (parsed.tm_year != 0) break; + } + return parsed; +} + RSS::RSS(std::string url) { URL = url; channelInfo = ChannelInfo(url); @@ -65,17 +81,16 @@ RSS_Entry::RSS_Entry(XML_leaf node) { URL = node.GetChild("link").GetValue(); Contents = node.GetChild("description").GetValue(); - // auto pubDateField = node.GetChild("pubDate"); - // if (pubDateField.Value.length() == 0) return; - // std::cout << "pub date" << pubDateField.Value << std::endl; - // strptime(pubDateField.Value.c_str(), "%Y-%m-%dT%H:%M:%SZ", &pubDate); + auto pubDateField = node.GetChild("pubDate"); + if (pubDateField.Value.length() == 0) return; + pubDate = ParseTime(pubDateField.Value); } void RSS_Entry::print() { std::cout << "==============================\n" << Title << '\n' - // << std::put_time(&pubDate, "%Y-%m-%d %H:%M:%S") << '\n' + << std::put_time(&pubDate, "%Y-%m-%d %H:%M:%S") << '\n' << Contents << '\n' << URL<< '\n'; } -- cgit v1.3