Repository navigation
Expand file tree
/
Copy pathvevent.cpp
More file actions
69 lines (60 loc) · 2.78 KB
/
Copy pathvevent.cpp
File metadata and controls
69 lines (60 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*############################################################################
# Copyright (c) 2020 Source Simian : https://github.com/sourcesimian/uICAL #
############################################################################*/
#include "uICAL/cppstl.h"
#include "uICAL/types.h"
#include "uICAL/util.h"
#include "uICAL/dateperiod.h"
#include "uICAL/datetime.h"
#include "uICAL/rrule.h"
#include "uICAL/vevent.h"
#include "uICAL/vline.h"
#include "uICAL/vobject.h"
#include "uICAL/error.h"
namespace uICAL {
VEvent::VEvent(const VObject_ptr& obj, const TZMap_ptr& tzmap, const string& default_tz) {
VLine_ptr dtStart = obj->getPropertyByName("DTSTART");
VLine_ptr dtEnd = obj->getPropertyByName("DTEND");
VLine_ptr rRule = obj->getPropertyByName("RRULE");
VLine_ptr summary = obj->getPropertyByName("SUMMARY");
if (dtStart == nullptr) { throw ImplementationError("all events must have a DTSTART"); }
if (summary == nullptr) { throw ImplementationError("all events must have a SUMMARY"); }
if (dtStart->getParam("VALUE") == "DATE") {
this->start = DateTime(dtStart->value + "T000000" + dtStart->getParam("TZID"), tzmap, default_tz);
if (dtEnd == nullptr) {
DatePeriod oneday(86400);
this->end = this->start + oneday;
} else {
this->end = DateTime(dtEnd->value + "T000000" + dtStart->getParam("TZID"), tzmap, default_tz);
}
} else {
this->start = DateTime(dtStart->value + dtStart->getParam("TZID"), tzmap, default_tz);
if (dtEnd == nullptr) {
DatePeriod oneday(86400);
this->end = this->start + oneday;
} else {
this->end = DateTime(dtEnd->value + dtStart->getParam("TZID"), tzmap, default_tz);
}
}
this->summary = summary->value;
if (rRule != nullptr) {
this->rrule = new_ptr<RRule>(rRule->value, this->start, tzmap, default_tz);
} else {
this->rrule = new_ptr<RRule>("", this->start, tzmap, default_tz);
}
auto rdates = obj->getPropertiesByName("RDATE");
for (auto date : rdates) {
this->rrule->include(DateTime(date->value + date->getParam("TZID"), tzmap, default_tz));
}
auto exdates = obj->getPropertiesByName("EXDATE");
for (auto date : exdates) {
this->rrule->exclude(DateTime(date->value + date->getParam("TZID"), tzmap, default_tz));
}
}
void VEvent::str(ostream& out) const {
out << "VEVENT: " << this->summary << uICAL::endl;
out << " - start: " << this->start << uICAL::endl;
out << " - end: " << this->end << uICAL::endl;
out << " - rrule: " << this->rrule << uICAL::endl;
}
}