summaryrefslogtreecommitdiff
path: root/src/RSS.cpp
diff options
context:
space:
mode:
authorPhysick <96335032+DegustatorPonos@users.noreply.github.com>2026-05-10 18:27:17 +0500
committerPhysick <96335032+DegustatorPonos@users.noreply.github.com>2026-05-10 18:27:17 +0500
commita14878b4a453f48f3b200481c343a7fc59181b0f (patch)
treeba89b96fd5291dde97450e66a886c7d5c8915b2c /src/RSS.cpp
parentd059e68f0bfb5f59cb748f622ad7fc65e4f6a189 (diff)
datetime support
Diffstat (limited to 'src/RSS.cpp')
-rw-r--r--src/RSS.cpp25
1 files changed, 20 insertions, 5 deletions
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 <stdexcept>
#include <curl/curl.h>
+#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';
}