forked from sourcesimian/uICAL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
veventiter.cpp
68 lines (60 loc) · 1.96 KB
/
veventiter.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
/*############################################################################
# Copyright (c) 2020 Source Simian : https://github.com/sourcesimian/uICAL #
############################################################################*/
#include "uICAL/cppstl.h"
#include "uICAL/types.h"
#include "uICAL/util.h"
#include "uICAL/calendarentry.h"
#include "uICAL/datetime.h"
#include "uICAL/rruleiter.h"
#include "uICAL/vevent.h"
#include "uICAL/veventiter.h"
namespace uICAL
{
VEventIter::VEventIter(const VEvent_ptr ice, DateTime begin, DateTime end)
: ice(ice)
{
this->range_begin = begin;
this->rrule = new_ptr<RRuleIter>(this->ice->rrule, DateTime(), end);
}
bool VEventIter::next()
{
if (!this->range_begin.valid())
{
return this->rrule->next();
}
DatePeriod span = this->ice->end - this->ice->start;
while (this->rrule->next())
{
DateTime end = this->rrule->now() + span;
if (end <= this->range_begin)
continue;
return true;
}
return false;
}
DateTime VEventIter::now() const
{
return this->rrule->now();
}
VEvent_ptr VEventIter::event() const
{
return this->ice;
}
CalendarEntry_ptr VEventIter::entry() const
{
DatePeriod span = this->ice->end - this->ice->start;
DateTime end = this->rrule->now() + span;
return new_ptr<CalendarEntry>(CalendarEntry::Type::EVENT,
this->ice->summary,
this->ice->location,
this->rrule->now(),
this->ice->start_has_time,
end,
this->ice->end_has_time);
}
bool operator<(const VEventIter_ptr &a, const VEventIter_ptr &b)
{
return a->rrule->now() < b->rrule->now();
}
}