-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtevent.cpp
executable file
·139 lines (118 loc) · 2.52 KB
/
tevent.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
#include <QDateTime>
#include <QDebug>
#include <math.h>
#include "tevent.h"
#include "task.h"
TEvent::TEvent()
{
m_nextItem = false;
setStart();
}
void TEvent::setStart(const QDateTime start)
{
m_start = start;
//qDebug() << m_start;
}
void TEvent::setEnd(const QDateTime end)
{
m_end = end;
}
void TEvent::setStart()
{
setStart(QDateTime::currentDateTime());
}
void TEvent::setEnd()
{
setEnd(QDateTime::currentDateTime());
}
void TEvent::setNextItem(const bool isNext)
{
m_nextItem = isNext;
}
QDateTime TEvent::getStart() const
{
return m_start;
}
QString TEvent::getStartString()
{
if(m_start.toString("h") == QString("0")) {
return QString(m_start.toString("ddd d.M.yy"));
} else {
return QString(m_start.toString("ddd d.M.yy h:mm"));
}
}
QDateTime TEvent::getEnd()
{
return m_end;
}
QString TEvent::getRemaining()
{
double span = m_start.secsTo(QDateTime::currentDateTime());
bool pos = (span>0)?true:false;
if(!pos) {
span = span * (-1);
}
QString out;
if (span > 62208000) {
out = QString("%1 Jahre").arg(floor(span/31104000));
} else if (span > 31104000) {
out = QString("%1 Jahr").arg(floor(span/31104000));
} else if (span > 5184000) {
out = QString("%1 Monate").arg(floor(span/2592000));
} else if (span > 2592000) {
out = QString("%1 Monat").arg(floor(span/2592000));
} else if (span > 172800) {
out = QString("%1 Tage").arg(floor(span/86400));
} else if (span > 86400) {
out = QString("1 Tag");
} else if (span > 3600) {
out = QString("%1 Std.").arg(floor(span/3600));
} else if (span > 1800) {
out = QString("1 Std.");
} else if (span > 900) {
out = QString("30 Min.");
} else if (span > 300) {
out = QString("15 Min.");
} else if (span > 60) {
out = QString("%1 Min.").arg(floor(span/60));
} else if (span > 0 ) {
out = QString("%1 Sek.").arg(span);
} else {
out = QString("...strange");
}
if(pos) {
out.prepend("-");
}
return out;
}
QString TEvent::toString()
{
QString out = Task::toString();
QString evtOut = QString("\n\tStart: %1\n\tEnd: %2\n\tRemaining: %3")
.arg(m_start.toString(), m_end.toString(), getRemaining());
out.append(evtOut);
return out;
}
/**
* basic sanity check
*/
bool TEvent::isValid()
{
if( (getSummary().size() > 1) &&
(m_end.isValid())) {
return true;
}
return false;
}
bool TEvent::isNextItem()
{
return m_nextItem;
}
bool TEvent::operator<(const TEvent &other) const
{
return m_start < other.getStart();
}
bool TEvent::operator==(const TEvent &other) const
{
return m_start == other.getStart();
}