Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/activitygen/city/AGTime.cpp
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// activitygen module
5
// Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6
// This program and the accompanying materials are made available under the
7
// terms of the Eclipse Public License 2.0 which is available at
8
// https://www.eclipse.org/legal/epl-2.0/
9
// This Source Code may also be made available under the following Secondary
10
// Licenses when the conditions for such availability set forth in the Eclipse
11
// Public License 2.0 are satisfied: GNU General Public License, version 2
12
// or later which is available at
13
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
14
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
15
/****************************************************************************/
16
/// @file AGTime.cpp
17
/// @author Piotr Woznica
18
/// @author Daniel Krajzewicz
19
/// @author Michael Behrisch
20
/// @author Walter Bamberger
21
/// @date July 2010
22
///
23
// Time manager: able to manipulate the time using Sumo's format (seconds)
24
/****************************************************************************/
25
#include <config.h>
26
27
#include "AGTime.h"
28
29
30
// ===========================================================================
31
// method definitions
32
// ===========================================================================
33
AGTime::AGTime(const AGTime& time) {
34
mySeconds = time.mySeconds;
35
}
36
37
int
38
AGTime::convert(int days, int hours, int minutes, int seconds) {
39
mySeconds = seconds + 60 * (minutes + 60 * (hours + 24 * (days)));
40
return mySeconds;
41
}
42
43
int
44
AGTime::getSecondsOf(double minutes) {
45
return static_cast<int>(60.0 * minutes);
46
}
47
48
bool
49
AGTime::operator==(const AGTime& time) {
50
if (this->mySeconds == time.mySeconds) {
51
return true;
52
} else {
53
return false;
54
}
55
}
56
57
bool
58
AGTime::operator<(const AGTime& time) {
59
if (this->mySeconds < time.mySeconds) {
60
return true;
61
} else {
62
return false;
63
}
64
}
65
66
bool
67
AGTime::operator<=(const AGTime& time) {
68
if (this->mySeconds <= time.mySeconds) {
69
return true;
70
} else {
71
return false;
72
}
73
}
74
75
void
76
AGTime::operator+=(const AGTime& time) {
77
this->mySeconds += time.mySeconds;
78
}
79
80
void
81
AGTime::operator+=(int seconds) {
82
this->mySeconds += seconds;
83
}
84
85
void
86
AGTime::operator-=(const AGTime& time) {
87
this->mySeconds -= time.mySeconds;
88
}
89
90
AGTime
91
AGTime::operator+(const AGTime& time) {
92
AGTime newtime(time.mySeconds + this->mySeconds);
93
return newtime;
94
}
95
96
int
97
AGTime::getDay() {
98
return (mySeconds / 86400);
99
}
100
101
int
102
AGTime::getHour() {
103
return ((mySeconds / 3600) % 24);
104
}
105
106
int
107
AGTime::getMinute() {
108
return ((mySeconds / 60) % 60);
109
}
110
111
int
112
AGTime::getSecond() {
113
return (mySeconds % 60);
114
}
115
116
int
117
AGTime::getSecondsInCurrentDay() {
118
return (mySeconds % 86400);
119
}
120
121
int
122
AGTime::getTime() {
123
return this->mySeconds;
124
}
125
126
void
127
AGTime::setDay(int d) {
128
if (0 <= d) {
129
mySeconds -= 86400 * getDay();
130
mySeconds += 86400 * d;
131
}
132
}
133
134
void
135
AGTime::setHour(int h) {
136
if (0 <= h && h < 24) {
137
mySeconds -= 3600 * getHour();
138
mySeconds += 3600 * h;
139
}
140
}
141
142
void
143
AGTime::setMinute(int m) {
144
if (0 <= m && m < 60) {
145
mySeconds -= 60 * getMinute();
146
mySeconds += 60 * m;
147
}
148
}
149
150
void
151
AGTime::setSecond(int s) {
152
if (0 <= s && s < 60) {
153
mySeconds -= getSecond();
154
mySeconds += s;
155
}
156
}
157
158
void
159
AGTime::setTime(int seconds) {
160
mySeconds = seconds;
161
}
162
163
void
164
AGTime::addDays(int d) {
165
mySeconds += 86400 * d;
166
}
167
168
void
169
AGTime::addHours(int h) {
170
mySeconds += 3600 * h;
171
}
172
173
void
174
AGTime::addMinutes(int m) {
175
mySeconds += 60 * m;
176
}
177
178
void
179
AGTime::addSeconds(int s) {
180
mySeconds += s;
181
}
182
183
184
/****************************************************************************/
185
186