summaryrefslogtreecommitdiff
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
parentd059e68f0bfb5f59cb748f622ad7fc65e4f6a189 (diff)
datetime support
-rw-r--r--src/DateUtils.hpp7
-rw-r--r--src/RSS.cpp25
-rw-r--r--src/RSS.hpp1
3 files changed, 28 insertions, 5 deletions
diff --git a/src/DateUtils.hpp b/src/DateUtils.hpp
new file mode 100644
index 0000000..358b431
--- /dev/null
+++ b/src/DateUtils.hpp
@@ -0,0 +1,7 @@
+#ifndef DATE_UTILS_H
+#define DATE_UTILS_H
+
+#include <ctime>
+#include <string>
+
+#endif // DATE_UTILS_H
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';
}
diff --git a/src/RSS.hpp b/src/RSS.hpp
index 709125d..1394842 100644
--- a/src/RSS.hpp
+++ b/src/RSS.hpp
@@ -12,6 +12,7 @@
#include <utility>
#include <variant>
#include <vector>
+#include "DateUtils.hpp"
class XML_leaf {
public: