-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintervalrest.h
41 lines (32 loc) · 898 Bytes
/
intervalrest.h
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
#ifndef INTERVALREST_H
#define INTERVALREST_H
#include "rest.h"
class IntervalRest : public Rest
{
public:
IntervalRest(QDateTime start, QDateTime end, QTime interval, QTime duration)
: Rest(duration),
start(start),
end(end),
interval(interval)
{}
virtual bool triggeredAt(const QDateTime &t) const
{
const qint64 window = 250;
const qint64 msecsFromStart = start.msecsTo(t);
if (msecsFromStart < 0)
return false;
if (msecsFromStart <= window)
return true;
const qint64 intervalMsecs = QTime(0, 0, 0).msecsTo(interval);
return msecsFromStart % intervalMsecs <= window;
}
virtual bool expiresAt(const QDateTime &t) const
{
return t.secsTo(end) == 0;
}
QDateTime start;
QDateTime end;
QTime interval;
};
#endif // INTERVALREST_H