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/DateUtils.hpp | 7 +++++++ src/RSS.cpp | 25 ++++++++++++++++++++----- src/RSS.hpp | 1 + 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/DateUtils.hpp (limited to 'src') 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 +#include + +#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 #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'; } 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 #include #include +#include "DateUtils.hpp" class XML_leaf { public: -- cgit v1.3