Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added code to process TZURL and STANDARD section.
[xestiacalendar/.git] / source / objects / calendartimezone / CalendarTimezone.cpp
1 #include "CalendarTimezone.h"
3 using namespace std;
5 CalendarObjectValidResult CalendarTimezoneObject::ValidObject(){
6  
7         bool ValidBegin = false;
8         bool ValidEnd = false;
9         bool ValidTimeZoneID = false;
10         int SeekCount = 0;
11         string PropertyName;
12         
13         // Look for BEGIN:VEVENT.
14         
15         for (vector<string>::iterator iter = ObjectName.begin();
16                 iter != ObjectName.end(); iter++){
17         
18                 if (ObjectName[SeekCount] == "BEGIN" &&
19                         ObjectData[SeekCount] == "VTIMEZONE"){
20                         
21                         if (ValidBegin == false){
22                                 ValidBegin = true;
23                         } else {
24                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
25                         }
26                                 
27                 }
28                 
29                 if (ObjectName[SeekCount] == "END" &&
30                         ObjectData[SeekCount] == "VTIMEZONE" &&
31                         ValidBegin == false){
32                 
33                         return CALENDAROBJECTVALID_INVALIDFORMAT;
34                                 
35                 }
36                 
37                 SeekCount++;
38                         
39         }
40         
41         SeekCount = 0;
42         
43         // Look for DTSTAMP.
44         
45         for (vector<string>::iterator iter = ObjectName.begin();
46                 iter != ObjectName.end(); iter++){
47                         
48                 try{
49                         PropertyName = ObjectName[SeekCount].substr(0,4);
50                 }
51                         
52                 catch(const out_of_range& oor){
53                         continue;
54                 }
55                 
56                 if (PropertyName == "TZID"){
57                         
58                         if (ValidTimeZoneID == false){
59                                 ValidTimeZoneID = true;
60                         } else {
61                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
62                         }
63                                 
64                 }
65                         
66                 SeekCount++;
67                         
68         }
69         
70         SeekCount = 0;
71         
72         // Look for END:VEVENT.
73         
74         for (vector<string>::iterator iter = ObjectName.begin();
75                 iter != ObjectName.end(); iter++){
76         
77                 if (ObjectName[SeekCount] == "END" &&
78                         ObjectData[SeekCount] == "VTIMEZONE"){
79                         
80                         if (ValidEnd == false){
81                                 ValidEnd = true;
82                         } else {
83                                 return CALENDAROBJECTVALID_INVALIDFORMAT;
84                         }
85                                 
86                 }
87                         
88                 SeekCount++;
89                         
90         }
91         
92         // Check if the VEVENT is valid.
93         
94         if (ValidBegin == true && 
95                 ValidEnd == true && 
96                 ValidTimeZoneID == true){
97                 
98                 return CALENDAROBJECTVALID_OK;
99                         
100         } else {
101                 
102                 return CALENDAROBJECTVALID_INVALIDFORMAT;
103                 
104         }
105         
108 void CalendarTimezoneObject::ProcessData(){
110         // Process the data.
111         
112         multimap<string,string> DataReceived;
113         map<string,string> PropertyData;
114         string *PropertyNameData = nullptr;
115         int ObjectSeekCount = 0;
116         
117         // Process the data from TZID.
118         
119         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "TZID");
120         
121         if (DataReceived.begin() != DataReceived.end()){
122         
123                 try {
124                         TimeZoneDataTokens = DataReceived.begin()->first.substr(5);
125                 }
126                 
127                 catch(const out_of_range &oor){
128                         // Do nothing as there is no data.
129                 }               
130                 
131                 TimeZoneData = DataReceived.begin()->second;
132                 
133         }
134         
135         // Process the data from LAST-MODIFIED.
136         
137         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "LAST-MODIFIED");
138         
139         if (DataReceived.begin() != DataReceived.end()){
140         
141                 try {
142                         LastModifiedTokens = DataReceived.begin()->first.substr(14);
143                 }
144                 
145                 catch(const out_of_range &oor){
146                         // Do nothing as there is no data.
147                 }               
148                 
149                 LastModifiedData = DataReceived.begin()->second;
150                 
151         }
152         
153         // Process the data from TZURL.
154         
155         DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "TZURL");
156         
157         if (DataReceived.begin() != DataReceived.end()){
158         
159                 try {
160                         TimeZoneURLTokens = DataReceived.begin()->first.substr(6);
161                 }
162                 
163                 catch(const out_of_range &oor){
164                         // Do nothing as there is no data.
165                 }               
166                 
167                 TimeZoneURLData = DataReceived.begin()->second;
168                 
169         }
170         
171         // Process data from each STANDARD and DAYLIGHT.
172         
173         ProcessStandardDaylight();
174         
175         int TZSeekCount = 0;
176         int SeekCount = 0;
177         
178         for (vector<vector<string>>::iterator tzsiter = TimezoneStandardName.begin();
179                 tzsiter != TimezoneStandardName.end(); tzsiter++){
181                 bool DateTimeStartFound = false;
182                 bool TimeZoneOffsetToFound = false;
183                 bool TimeZoneOffsetFromFound = false;
184                 
185                 TimezoneDataStruct NewTZData;
186                                         
187                 // Process the data from DTSTART.
188         
189                 DataReceived = ProcessTextVectors(&TimezoneStandardName[SeekCount], 
190                                 &TimezoneStandardData[SeekCount], false, "DTSTART");
191         
192                 if (DataReceived.begin() != DataReceived.end()){
193         
194                         try {
195                                 NewTZData.DateTimeStartTokens = DataReceived.begin()->first.substr(8);
196                         }
197                 
198                         catch(const out_of_range &oor){
199                                 // Do nothing as there is no data.
200                         }
201                 
202                         NewTZData.DateTimeStartData = DataReceived.begin()->second;
203                         DateTimeStartFound = true;
204                 
205                 }
206                         
207                 // Process the data from TZOFFSETFROM.
208                         
209                 DataReceived = ProcessTextVectors(&TimezoneStandardName[SeekCount], 
210                                 &TimezoneStandardData[SeekCount], false, "TZOFFSETFROM");
211         
212                 if (DataReceived.begin() != DataReceived.end()){
213         
214                         try {
215                                 NewTZData.TimeZoneOffsetFromTokens = DataReceived.begin()->first.substr(13);
216                         }
217                 
218                         catch(const out_of_range &oor){
219                                 // Do nothing as there is no data.
220                         }
221                 
222                         NewTZData.TimeZoneOffsetFromData = DataReceived.begin()->second;
223                         TimeZoneOffsetFromFound = true;
224                 
225                 }
226                         
227                 // Process the data from TZOFFSETTO.
228                         
229                 DataReceived = ProcessTextVectors(&TimezoneStandardName[SeekCount], 
230                                 &TimezoneStandardData[SeekCount], false, "TZOFFSETTO");
231         
232                 if (DataReceived.begin() != DataReceived.end()){
233         
234                         try {
235                                 NewTZData.TimeZoneOffsetToTokens = DataReceived.begin()->first.substr(11);
236                         }
237                 
238                         catch(const out_of_range &oor){
239                                 // Do nothing as there is no data.
240                         }
241                 
242                         NewTZData.TimeZoneOffsetToData = DataReceived.begin()->second;
243                         TimeZoneOffsetToFound = true;
244                 
245                 }
246                 
247                 // Process the data from RRULE.
249                 DataReceived = ProcessTextVectors(&TimezoneStandardName[SeekCount], 
250                         &TimezoneStandardData[SeekCount], false, "RRULE");
251         
252                 if (DataReceived.begin() != DataReceived.end()){
253         
254                         try {
255                                 NewTZData.RecurranceRuleDataTokens = DataReceived.begin()->first.substr(6);
256                         }
257                 
258                         catch(const out_of_range &oor){
259                                 // Do nothing as there is no data.
260                         }               
261                         
262                         NewTZData.RecurranceRuleData = DataReceived.begin()->second;
263                 
264                 }
265                         
266                 // Process the data from COMMENT.
267         
268                 DataReceived = ProcessTextVectors(&TimezoneStandardName[SeekCount], 
269                         &TimezoneStandardData[SeekCount], true, "COMMENT");
271                 ObjectSeekCount = 0;
272         
273                 for(multimap<string,string>::iterator propiter = DataReceived.begin(); 
274                         propiter != DataReceived.end(); 
275                         ++propiter){
276                 
277                         NewTZData.CommentListTokens.push_back("");
278                         NewTZData.CommentListAltRep.push_back("");
279                         NewTZData.CommentListLanguage.push_back("");
280                         NewTZData.CommentList.push_back("");
281                         
282                         bool TokenData = false;
283                         string PropertyTokens;
284                 
285                         PropertyNameData = (string*)&propiter->first;
286                 
287                         PropertyData = SplitValues(*PropertyNameData);
288                         
289                         for(map<string,string>::iterator propdataiter = PropertyData.begin();
290                                 propdataiter != PropertyData.end(); propdataiter++){
291                         
292                                 if (propdataiter->first == "ALTREP"){
293                                 
294                                         NewTZData.CommentListAltRep[ObjectSeekCount] = propdataiter->second;
295                                 
296                                 } else if (propdataiter->first == "LANGUAGE"){
297                                 
298                                         NewTZData.CommentListLanguage[ObjectSeekCount] = propdataiter->second;
299                                 
300                                 } else {
301                                 
302                                         if (TokenData == false){
303                                                 TokenData = true;
304                                         } else {
305                                                 PropertyTokens += ";";
306                                         }
307                                 
308                                         PropertyTokens += propdataiter->first;
309                                         PropertyTokens += "=";
310                                         PropertyTokens += propdataiter->second;
311                                 
312                                 }
313                                 
314                         }
315                 
316                         if (PropertyTokens.size() > 0){
317                                 NewTZData.CommentListTokens[ObjectSeekCount] = PropertyTokens;
318                         }
319                         
320                         NewTZData.CommentList[ObjectSeekCount] = propiter->second;
321                         
322                         ObjectSeekCount++;
323                 
324                 }
325                 
326                 // Process the data from RDATE.
327                         
328                 DataReceived = ProcessTextVectors(&TimezoneStandardName[SeekCount], 
329                         &TimezoneStandardData[SeekCount], true, "RDATE");
331                 ObjectSeekCount = 0;
332         
333                 for(multimap<string,string>::iterator propiter = DataReceived.begin(); 
334                         propiter != DataReceived.end(); 
335                         ++propiter){
336                 
337                         NewTZData.RecurranceDateDataTokens.push_back("");
338                         NewTZData.RecurranceDateDataValue.push_back("");
339                         NewTZData.RecurranceDateDataTimeZoneParam.push_back("");
340                         NewTZData.RecurranceDateData.push_back("");
341                         
342                         bool TokenData = false;
343                         string PropertyTokens;
344                 
345                         PropertyNameData = (string*)&propiter->first;
346                 
347                         PropertyData = SplitValues(*PropertyNameData);
348                         
349                         for(map<string,string>::iterator dataiter = PropertyData.begin();
350                                 dataiter != PropertyData.end(); dataiter++){
351                         
352                                 if (dataiter->first == "VALUE"){
353                         
354                                         NewTZData.RecurranceDateDataValue[ObjectSeekCount] = dataiter->second;
355                                 
356                                 } else if (dataiter->first == "TZID"){
357                                 
358                                         NewTZData.RecurranceDateDataTimeZoneParam[ObjectSeekCount] = dataiter->second;
359                                 
360                                 } else {
361                                 
362                                         if (TokenData == false){
363                                                 TokenData = true;
364                                         } else {
365                                                 PropertyTokens += ";";
366                                         }
367                                 
368                                         PropertyTokens += dataiter->first;
369                                         PropertyTokens += "=";
370                                         PropertyTokens += dataiter->second;
371                                 
372                                 }
373                                 
374                         }
375                 
376                         if (PropertyTokens.size() > 0){
377                                 NewTZData.RecurranceDateDataTokens[ObjectSeekCount] = PropertyTokens;
378                         }
379                         
380                         NewTZData.RecurranceDateData[ObjectSeekCount] = propiter->second;
381                 
382                         ObjectSeekCount++;
383                 
384                 }
385                         
386                 // Process the data from TZNAME.
387                         
388                 DataReceived = ProcessTextVectors(&TimezoneStandardName[SeekCount], 
389                         &TimezoneStandardData[SeekCount], true, "TZNAME");
391                 ObjectSeekCount = 0;
392         
393                 for(multimap<string,string>::iterator propiter = DataReceived.begin(); 
394                         propiter != DataReceived.end(); 
395                         ++propiter){
396                 
397                         NewTZData.TimeZoneNameTokens.push_back("");
398                         NewTZData.TimeZoneNameLanguage.push_back("");
399                         NewTZData.TimeZoneNameData.push_back("");
400                         
401                         bool TokenData = false;
402                         string PropertyTokens;
403                 
404                         PropertyNameData = (string*)&propiter->first;
405                 
406                         PropertyData = SplitValues(*PropertyNameData);
407                         
408                         for(map<string,string>::iterator dataiter = PropertyData.begin();
409                                 dataiter != PropertyData.end(); dataiter++){
410                         
411                                 if (dataiter->first == "LANGUAGE"){
412                                 
413                                         NewTZData.TimeZoneNameLanguage[ObjectSeekCount] = dataiter->second;
414                                 
415                                 } else {
416                                 
417                                         if (TokenData == false){
418                                                 TokenData = true;
419                                         } else {
420                                                 PropertyTokens += ";";
421                                         }
422                                 
423                                         PropertyTokens += dataiter->first;
424                                         PropertyTokens += "=";
425                                         PropertyTokens += dataiter->second;
426                                 
427                                 }
428                                 
429                         }
430                 
431                         if (PropertyTokens.size() > 0){
432                                 NewTZData.TimeZoneNameTokens[ObjectSeekCount] = PropertyTokens;
433                         }
434                         
435                         NewTZData.TimeZoneNameData[ObjectSeekCount] = propiter->second;
436                 
437                         ObjectSeekCount++;
438                 
439                 }
440                         
441                 ObjectSeekCount = 0;
442         
443                 // Process data from X-*
444         
445                 for(vector<string>::iterator propiter = TimezoneStandardName[SeekCount].begin(); 
446                         propiter != TimezoneStandardName[SeekCount].end(); ++propiter){
447                 
448                         if (propiter->substr(0,2) == "X-" &&
449                                 propiter->size() > 2){
450                                         
451                                 NewTZData.XTokensData.push_back(TimezoneStandardData[SeekCount][ObjectSeekCount]);
452                                 NewTZData.XTokensDataTokens.push_back(TimezoneStandardName[SeekCount][ObjectSeekCount]);
453                                 
454                         }
455                 
456                         ObjectSeekCount++;
457                 
458                 }
459                 
460                 // Check if the required values were given and
461                 // insert NewTZData into the vector list of
462                 // standard timezones.
463                         
464                 if (DateTimeStartFound == true &&
465                         TimeZoneOffsetToFound == true &&
466                         TimeZoneOffsetFromFound == true){
467                                         
468                         TimezoneStandardCollection.push_back(NewTZData);
469                                         
470                 }
471                         
472                 SeekCount++;
473                         
474         }
475         
478 void CalendarTimezoneObject::ProcessStandardDaylight(){
480         int SeekCount = 0;
481         
482         bool TZMode = false; // False = STANDARD, True = DAYLIGHT.
483         bool ValidBegin = false;
484         vector<string> TimezoneObjectName;
485         vector<string> TimezoneObjectData;
486         
487         for (vector<string>::iterator iter = ObjectName.begin();
488                 iter != ObjectName.end(); iter++){      
489         
490                 // Check if the current name is BEGIN and
491                 // data is either STANDARD or DAYLIGHT.
492                         
493                 if (ObjectName[SeekCount] == "BEGIN" &&
494                         (ObjectData[SeekCount] == "STANDARD" || 
495                         ObjectData[SeekCount] == "DAYLIGHT")){
496                         
497                         if (ValidBegin == false){
498                                 ValidBegin = true;
499                         } else {
500                                 
501                         }
502                         
503                         if (ObjectData[SeekCount] == "STANDARD"){
504                                 TZMode = false;
505                         } else if (ObjectData[SeekCount] == "DAYLIGHT") {
506                                 TZMode = true;
507                         }
508                         
509                         SeekCount++;
510                         continue;
511                         
512                 }
513                 
514                 // Check if current name is END and
515                 // data is either STANDARD or DAYLIGHT.
516                 
517                 if (ObjectName[SeekCount] == "END" &&
518                         (ObjectData[SeekCount] == "STANDARD" || 
519                         ObjectData[SeekCount] == "DAYLIGHT") && 
520                         ValidBegin == true){
521                                 
522                         if (TZMode == false && TimezoneObjectName.size() > 0){
523                                 TimezoneStandardName.push_back(TimezoneObjectName);
524                                 TimezoneStandardData.push_back(TimezoneObjectData);
525                         } else {
526                                 TimezoneDaylightName.push_back(TimezoneObjectName);
527                                 TimezoneDaylightData.push_back(TimezoneObjectData);
528                         }
529                         
530                         TimezoneObjectName.clear();
531                         TimezoneObjectData.clear();
532                         
533                         ValidBegin = false;
534                                 
535                 }
536                 
537                 if (ValidBegin == true){
538                         
539                         TimezoneObjectName.push_back(ObjectName[SeekCount]);
540                         TimezoneObjectData.push_back(ObjectData[SeekCount]);
541                         
542                 }
543                 
544                 SeekCount++;
545                         
546         }
547                         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy