775ece7fd3922b26da7e8ee2dccfd113afa5c999
[harbour-pedalo.git] / src / journey.cpp
1 #include "journey.h"
2 #include <QDebug>
3
4 Journey::Journey() :
5 start(0u),
6 duration(0u),
7 overtook(0u),
8 overtakenby(0u)
9 {
10 }
11
12 Journey::Journey(quint64 start, quint32 duration, quint32 overtook, quint32 overtakenby) :
13 start(start),
14 duration(duration),
15 overtook(overtook),
16 overtakenby(overtakenby)
17 {
18 }
19
20 quint64 Journey::getStart () const {
21 return start;
22 }
23
24 QDate Journey::getStartDate() const {
25 QDateTime date;
26
27 date.setMSecsSinceEpoch(start);
28 return date.date();
29 }
30
31 QTime Journey::getStartTime() const {
32 QDateTime time;
33
34 time.setMSecsSinceEpoch(start);
35 return time.time();
36 }
37
38 QTime Journey::getEndTime() const {
39 QDateTime time;
40
41 time.setMSecsSinceEpoch(start);
42 time.addSecs(duration);
43
44 return time.time();
45 }
46
47 qint32 Journey::getDuration () const {
48 return duration;
49 }
50
51 qint32 Journey::getOvertook () const {
52 return overtook;
53 }
54
55 qint32 Journey::getOvertakenBy () const {
56 return overtakenby;
57 }
58
59
60 void Journey::setStart (const quint64 value) {
61 start = value;
62 }
63
64 void Journey::setStartDate (const QDate &value) {
65 QDateTime time;
66
67 time.setMSecsSinceEpoch(start);
68 time.setDate(value);
69 }
70
71 void Journey::setStartTime (const QTime &value) {
72 QDateTime time;
73
74 time.setMSecsSinceEpoch(start);
75 time.setTime(value);
76 }
77
78 void Journey::setEndTime(const QTime &value) {
79 qint64 difference;
80 QDateTime starttime;
81 QDateTime endtime;
82
83 starttime.setMSecsSinceEpoch(start);
84 endtime = QDateTime(starttime);
85 endtime.setTime(value);
86 difference = starttime.secsTo(endtime);
87 if (difference < 0) {
88 difference %= 24 * 60 * 60;
89 }
90 duration = difference;
91 }
92
93 void Journey::setDuration (qint32 value) {
94 duration = value;
95 }
96
97 void Journey::setOvertook (qint32 value) {
98 overtook = value;
99 }
100
101 void Journey::setOvertakenBy (qint32 value) {
102 overtakenby = value;
103 }
104