This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
types.cpp
executable file
·161 lines (136 loc) · 3.39 KB
/
types.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "types.h"
Recurrence::operator string() const {
char Temp[5];
string Text = "FREQ=";
switch (Freq) {
case YEAR: Text += "YEARLY"; break;
case MONTH: Text += "MONTHLY"; break;
case DAY: Text += "DAILY"; break;
case HOUR: Text += "HOURLY"; break;
case MINUTE: Text += "MINUTELY"; break;
case SECOND: Text += "SECONDLY"; break;
case WEEK: Text += "WEEKLY"; break;
}
Text += ";INTERVAL=";
sprintf(Temp, "%d", Interval);
Text += Temp;
if (Count > 0) {
Text += ";COUNT=";
sprintf(Temp, "%d", Count);
Text += Temp;
} else if (!Until.IsEmpty()) {
Text += ";UNTIL=";
Text += Until;
}
return Text;
}
AlarmTrigger &AlarmTrigger::operator =(const string &Text) {
char UnitChar;
// 1 because always at least 'P' before the value
short i = 1;
if (Text[0] == '-')
Before = true;
while (!isdigit(Text[i]))
++i;
sscanf(Text.c_str()+i, "%hd%c", (short *)&Value, &UnitChar);
switch (UnitChar) {
case 'H': Unit = HOUR; break;
case 'D': Unit = DAY; break;
case 'W': Unit = WEEK; break;
default: Unit = MINUTE; break;
}
return *this;
}
AlarmTrigger::operator string() const {
string Text;
char Temp[6];
sprintf(Temp, "%d", Value);
if (Before)
Text = '-';
Text += 'P';
if (Unit != WEEK && Unit != DAY)
Text += 'T';
Text += Temp;
switch (Unit) {
case HOUR: Text += 'H'; break;
case DAY: Text += 'D'; break;
case WEEK: Text += 'W'; break;
default: Text += 'M'; break;
}
return Text;
}
Alarm::operator string() const {
string Text = "\r\nBEGIN:VALARM";
Text += "\r\nTRIGGER:";
Text += Trigger;
Text += "\r\nACTION:";
switch (Action) {
case AUDIO: Text += "AUDIO"; break;
case DISPLAY: Text += "DISPLAY"; break;
case PROCEDURE: Text += "PROCEDURE"; break;
case EMAIL: Text += "EMAIL"; break;
}
if (!Description.empty()) {
Text += "\r\nDESCRIPTION:";
Text += Description;
}
Text += "\r\nEND:VALARM";
return Text;
}
Event::operator string() const {
string Text = "BEGIN:VEVENT";
Text += "\r\nUID:";
Text += UID;
Text += "\r\nSUMMARY:";
Text += Summary;
// some programs do not add this property, let's leave it when modifying
if (!DtStamp.IsEmpty()) {
Text += "\r\nDTSTAMP:";
Text += DtStamp;
}
Text += "\r\nDTSTART:";
Text += DtStart;
if (!DtEnd.IsEmpty()) {
Text += "\r\nDTEND:";
Text += DtEnd;
}
if (!Description.empty()) {
Text += "\r\nDESCRIPTION:";
Text += Description;
}
if (!Categories.empty()) {
Text += "\r\nCATEGORIES:";
Text += Categories;
}
if (!RRule.IsEmpty()) {
Text += "\r\nRRULE:";
Text += RRule;
}
if (!Alarms->empty()) {
for (list<Alarm>::const_iterator AlarmsIterator = Alarms->begin(); AlarmsIterator != Alarms->end(); ++AlarmsIterator) {
Text += *AlarmsIterator;
}
}
Text += "\r\nEND:VEVENT\r\n";
return Text;
}
bool Event::HasAlarm(const Date &From, const Date &To) {
if (Alarms->empty())
return false;
bool HasAlarm = false;
Date AlarmDate;
for (list<Alarm>::iterator AlarmsIterator = Alarms->begin(); AlarmsIterator != Alarms->end(); ++AlarmsIterator) {
AlarmDate = DtStart;
if ((*AlarmsIterator).Trigger.Before)
AlarmDate[(*AlarmsIterator).Trigger.Unit] -= (*AlarmsIterator).Trigger.Value;
else
AlarmDate[(*AlarmsIterator).Trigger.Unit] += (*AlarmsIterator).Trigger.Value;
if (AlarmDate >= From && AlarmDate <= To) {
HasAlarm = true;
(*AlarmsIterator).Active = true;
} else {
(*AlarmsIterator).Active = false;
}
}
return HasAlarm;
}