Changeset View
Changeset View
Standalone View
Standalone View
src/duration.cpp
Show All 29 Lines | 22 | /** | |||
---|---|---|---|---|---|
30 | @author Cornelius Schumacher \<schumacher@kde.org\> | 30 | @author Cornelius Schumacher \<schumacher@kde.org\> | ||
31 | @author David Jarvie \<software@astrojar.org.uk\> | 31 | @author David Jarvie \<software@astrojar.org.uk\> | ||
32 | */ | 32 | */ | ||
33 | #include "duration.h" | 33 | #include "duration.h" | ||
34 | 34 | | |||
35 | #include <QDateTime> | 35 | #include <QDateTime> | ||
36 | #include <QTimeZone> | 36 | #include <QTimeZone> | ||
37 | 37 | | |||
38 | using namespace KCalCore; | 38 | using namespace KCalendarCore; | ||
39 | 39 | | |||
40 | /** | 40 | /** | ||
41 | Private class that helps to provide binary compatibility between releases. | 41 | Private class that helps to provide binary compatibility between releases. | ||
42 | @internal | 42 | @internal | ||
43 | */ | 43 | */ | ||
44 | //@cond PRIVATE | 44 | //@cond PRIVATE | ||
45 | class Q_DECL_HIDDEN KCalCore::Duration::Private | 45 | class Q_DECL_HIDDEN KCalendarCore::Duration::Private | ||
46 | { | 46 | { | ||
47 | public: | 47 | public: | ||
48 | int seconds() const | 48 | int seconds() const | ||
49 | { | 49 | { | ||
50 | return mDaily ? mDuration * 86400 : mDuration; | 50 | return mDaily ? mDuration * 86400 : mDuration; | ||
51 | } | 51 | } | ||
52 | int mDuration; // number of seconds or days in the duration | 52 | int mDuration; // number of seconds or days in the duration | ||
53 | bool mDaily = false; // specified in terms of days rather than seconds | 53 | bool mDaily = false; // specified in terms of days rather than seconds | ||
54 | }; | 54 | }; | ||
55 | //@endcond | 55 | //@endcond | ||
56 | 56 | | |||
57 | Duration::Duration() | 57 | Duration::Duration() | ||
58 | : d(new KCalCore::Duration::Private()) | 58 | : d(new KCalendarCore::Duration::Private()) | ||
59 | { | 59 | { | ||
60 | } | 60 | } | ||
61 | 61 | | |||
62 | Duration::Duration(const QDateTime &start, const QDateTime &end) | 62 | Duration::Duration(const QDateTime &start, const QDateTime &end) | ||
63 | : d(new KCalCore::Duration::Private()) | 63 | : d(new KCalendarCore::Duration::Private()) | ||
64 | { | 64 | { | ||
65 | if (start.time() == end.time() && start.timeZone() == end.timeZone()) { | 65 | if (start.time() == end.time() && start.timeZone() == end.timeZone()) { | ||
66 | d->mDuration = start.daysTo(end); | 66 | d->mDuration = start.daysTo(end); | ||
67 | d->mDaily = true; | 67 | d->mDaily = true; | ||
68 | } else { | 68 | } else { | ||
69 | d->mDuration = start.secsTo(end); | 69 | d->mDuration = start.secsTo(end); | ||
70 | d->mDaily = false; | 70 | d->mDaily = false; | ||
71 | } | 71 | } | ||
72 | } | 72 | } | ||
73 | 73 | | |||
74 | Duration::Duration(const QDateTime &start, const QDateTime &end, Type type) | 74 | Duration::Duration(const QDateTime &start, const QDateTime &end, Type type) | ||
75 | : d(new KCalCore::Duration::Private()) | 75 | : d(new KCalendarCore::Duration::Private()) | ||
76 | { | 76 | { | ||
77 | if (type == Days) { | 77 | if (type == Days) { | ||
78 | QDateTime endSt(end.toTimeZone(start.timeZone())); | 78 | QDateTime endSt(end.toTimeZone(start.timeZone())); | ||
79 | d->mDuration = start.daysTo(endSt); | 79 | d->mDuration = start.daysTo(endSt); | ||
80 | if (d->mDuration) { | 80 | if (d->mDuration) { | ||
81 | // Round down to whole number of days if necessary | 81 | // Round down to whole number of days if necessary | ||
82 | if (start < endSt) { | 82 | if (start < endSt) { | ||
83 | if (endSt.time() < start.time()) { | 83 | if (endSt.time() < start.time()) { | ||
84 | --d->mDuration; | 84 | --d->mDuration; | ||
85 | } | 85 | } | ||
86 | } else { | 86 | } else { | ||
87 | if (endSt.time() > start.time()) { | 87 | if (endSt.time() > start.time()) { | ||
88 | ++d->mDuration; | 88 | ++d->mDuration; | ||
89 | } | 89 | } | ||
90 | } | 90 | } | ||
91 | } | 91 | } | ||
92 | d->mDaily = true; | 92 | d->mDaily = true; | ||
93 | } else { | 93 | } else { | ||
94 | d->mDuration = start.secsTo(end); | 94 | d->mDuration = start.secsTo(end); | ||
95 | d->mDaily = false; | 95 | d->mDaily = false; | ||
96 | } | 96 | } | ||
97 | } | 97 | } | ||
98 | 98 | | |||
99 | Duration::Duration(int duration, Type type) | 99 | Duration::Duration(int duration, Type type) | ||
100 | : d(new KCalCore::Duration::Private()) | 100 | : d(new KCalendarCore::Duration::Private()) | ||
101 | { | 101 | { | ||
102 | d->mDuration = duration; | 102 | d->mDuration = duration; | ||
103 | d->mDaily = (type == Days); | 103 | d->mDaily = (type == Days); | ||
104 | } | 104 | } | ||
105 | 105 | | |||
106 | Duration::Duration(const Duration &duration) | 106 | Duration::Duration(const Duration &duration) | ||
107 | : d(new KCalCore::Duration::Private(*duration.d)) | 107 | : d(new KCalendarCore::Duration::Private(*duration.d)) | ||
108 | { | 108 | { | ||
109 | } | 109 | } | ||
110 | 110 | | |||
111 | Duration::~Duration() | 111 | Duration::~Duration() | ||
112 | { | 112 | { | ||
113 | delete d; | 113 | delete d; | ||
114 | } | 114 | } | ||
115 | 115 | | |||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 212 | { | |||
213 | return d->mDuration; | 213 | return d->mDuration; | ||
214 | } | 214 | } | ||
215 | 215 | | |||
216 | bool Duration::isNull() const | 216 | bool Duration::isNull() const | ||
217 | { | 217 | { | ||
218 | return d->mDuration == 0; | 218 | return d->mDuration == 0; | ||
219 | } | 219 | } | ||
220 | 220 | | |||
221 | QDataStream &KCalCore::operator<<(QDataStream &out, const KCalCore::Duration &duration) | 221 | QDataStream &KCalendarCore::operator<<(QDataStream &out, const KCalendarCore::Duration &duration) | ||
222 | { | 222 | { | ||
223 | out << duration.d->mDuration << duration.d->mDaily; | 223 | out << duration.d->mDuration << duration.d->mDaily; | ||
224 | return out; | 224 | return out; | ||
225 | } | 225 | } | ||
226 | 226 | | |||
227 | QDataStream &KCalCore::operator>>(QDataStream &in, KCalCore::Duration &duration) | 227 | QDataStream &KCalendarCore::operator>>(QDataStream &in, KCalendarCore::Duration &duration) | ||
228 | { | 228 | { | ||
229 | in >> duration.d->mDuration >> duration.d->mDaily; | 229 | in >> duration.d->mDuration >> duration.d->mDaily; | ||
230 | return in; | 230 | return in; | ||
231 | } | 231 | } |