summaryrefslogtreecommitdiff
path: root/src/RSS.cpp
diff options
context:
space:
mode:
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';
}