From c08c09cf1e495ddd3b9ea1b4c4e01995f929536a Mon Sep 17 00:00:00 2001 From: Stefan Pranger Date: Tue, 29 Jun 2021 16:35:37 +0200 Subject: [PATCH] fixed event getter --- ical/Event.cpp | 28 +++++++++++++++++++--------- ical/Event.h | 10 ++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ical/Event.cpp b/ical/Event.cpp index 7eda438..75d067d 100644 --- a/ical/Event.cpp +++ b/ical/Event.cpp @@ -1,6 +1,9 @@ #include #include +#include + + namespace ical { Event::Event(icalcomponent* event_component) { parse(event_component); @@ -8,8 +11,8 @@ namespace ical { void Event::parse(icalcomponent* event_component) { uid = icalcomponent_get_uid(event_component); - dtstart = icalcomponent_get_dtstart(event_component); - dtend = icalcomponent_get_dtend(event_component); + dtstart = icaltime_as_timet(icalcomponent_get_dtstart(event_component)); + dtend = icaltime_as_timet(icalcomponent_get_dtend(event_component)); summary = std::string(icalcomponent_get_summary(event_component)); parse_alarms(event_component); } @@ -24,31 +27,38 @@ namespace ical { } } - std::string get_uid() const { + std::string Event::get_uid() const { return uid; } - std::string get_summary() const { + std::string Event::get_summary() const { return summary; } - icaltimetype get_dtstart() const { + uint32_t Event::get_dtstart() const { return dtstart; } - icaltimetype get_dtend() const { + uint32_t Event::get_dtend() const { return dtend; } - std::vector get_alarms() const { + std::vector Event::get_alarms() const { return alarms; } + std::vector Event::get_db_row() const { + return {db_safe(uid), + db_safe(summary), + db_safe(std::to_string(dtstart)), + db_safe(std::to_string(dtend))}; + } + std::string Event::print() const { std::string s = ""; s += "UID: " + uid + "\n"; - s += "DTSTART: " + std::string(icaltime_as_ical_string(dtstart)) + "\n"; - s += "DTEND: " + std::string(icaltime_as_ical_string(dtend)) + "\n"; + s += "DTSTART: " + std::to_string(dtstart) + "\n"; + s += "DTEND: " + std::to_string(dtend) + "\n"; s += "SUMMARY: " + summary + "\n"; s += "ALARMS:\n"; for(auto const& a : alarms) { diff --git a/ical/Event.h b/ical/Event.h index 634ad4f..bac2557 100644 --- a/ical/Event.h +++ b/ical/Event.h @@ -18,16 +18,18 @@ namespace ical { std::string get_uid() const; std::string get_summary() const; - icaltimetype get_dtstart() const; - icaltimetype get_dtend() const; + uint32_t get_dtstart() const; + uint32_t get_dtend() const; std::vector get_alarms() const; + std::vector get_db_row() const; + std::string print() const; private: std::string uid; std::string summary; - icaltimetype dtstart; - icaltimetype dtend; + uint32_t dtstart; + uint32_t dtend; std::vector alarms; }; }