-
Notifications
You must be signed in to change notification settings - Fork 9
/
candlestick_interval.h
94 lines (78 loc) · 2.04 KB
/
candlestick_interval.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
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
#ifndef CANDLESTICK_INTERVAL_H_INCLUDED
#define CANDLESTICK_INTERVAL_H_INCLUDED
#include <QDateTime>
// TODO: my own interval representation? (to store logical size, not second size)
class CandlestickInterval {
public:
virtual QDateTime lastBefore(QDateTime x) = 0;
virtual QDateTime firstAfter(QDateTime x) = 0;
virtual int index(QDateTime start, QDateTime end);
virtual QDateTime minus(QDateTime x, int n);
};
namespace CI {
class PureTimespan: public CandlestickInterval {
private:
int seconds;
public:
PureTimespan(int s): seconds(s) {};
virtual QDateTime lastBefore(QDateTime x) {
return x;
}
virtual QDateTime firstAfter(QDateTime x) {
return lastBefore(x).addSecs(seconds);
}
};
/*
class Minute: public CandlestickInterval {
public:
virtual QDateTime lastBefore(QDateTime x) {
x.setTime(QTime(x.time().hour(), x.time().minute(), 0));
return x;
}
virtual QDateTime firstAfter(QDateTime x) {
return lastBefore(x).addMinutes(1);
}
};
*/
/*
class Hour: public CandlestickInterval {
public:
virtual QDateTime lastBefore(QDateTime x) {
x.setTime(QTime(x.hour(), 0, 0));
return x;
}
virtual QDateTime firstAfter(QDateTime x) {
return lastBefore(x).addHours(1);
}
};
*/
class Day: public CandlestickInterval {
public:
virtual QDateTime lastBefore(QDateTime x);
virtual QDateTime firstAfter(QDateTime x);
virtual int index(QDateTime start, QDateTime end);
};
class Month: public CandlestickInterval {
public:
virtual QDateTime lastBefore(QDateTime x) {
x.setTime(QTime(0, 0, 0));
x.setDate(QDate(x.date().year(), x.date().month(), 1));
return x;
}
virtual QDateTime firstAfter(QDateTime x) {
return lastBefore(x).addMonths(1);
}
};
class Year: public CandlestickInterval {
public:
virtual QDateTime lastBefore(QDateTime x) {
x.setTime(QTime(0, 0, 0));
x.setDate(QDate(x.date().year(), 1, 1));
return x;
}
virtual QDateTime firstAfter(QDateTime x) {
return lastBefore(x).addYears(1);
}
};
};
#endif