Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
AGTime.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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/****************************************************************************/
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// ===========================================================================
33AGTime::AGTime(const AGTime& time) {
34 mySeconds = time.mySeconds;
35}
36
37int
38AGTime::convert(int days, int hours, int minutes, int seconds) {
39 mySeconds = seconds + 60 * (minutes + 60 * (hours + 24 * (days)));
40 return mySeconds;
41}
42
43int
44AGTime::getSecondsOf(double minutes) {
45 return static_cast<int>(60.0 * minutes);
46}
47
48bool
50 if (this->mySeconds == time.mySeconds) {
51 return true;
52 } else {
53 return false;
54 }
55}
56
57bool
58AGTime::operator<(const AGTime& time) {
59 if (this->mySeconds < time.mySeconds) {
60 return true;
61 } else {
62 return false;
63 }
64}
65
66bool
67AGTime::operator<=(const AGTime& time) {
68 if (this->mySeconds <= time.mySeconds) {
69 return true;
70 } else {
71 return false;
72 }
73}
74
75void
77 this->mySeconds += time.mySeconds;
78}
79
80void
81AGTime::operator+=(int seconds) {
82 this->mySeconds += seconds;
83}
84
85void
87 this->mySeconds -= time.mySeconds;
88}
89
92 AGTime newtime(time.mySeconds + this->mySeconds);
93 return newtime;
94}
95
96int
98 return (mySeconds / 86400);
99}
100
101int
103 return ((mySeconds / 3600) % 24);
104}
105
106int
108 return ((mySeconds / 60) % 60);
109}
110
111int
113 return (mySeconds % 60);
114}
115
116int
118 return (mySeconds % 86400);
119}
120
121int
123 return this->mySeconds;
124}
125
126void
128 if (0 <= d) {
129 mySeconds -= 86400 * getDay();
130 mySeconds += 86400 * d;
131 }
132}
133
134void
136 if (0 <= h && h < 24) {
137 mySeconds -= 3600 * getHour();
138 mySeconds += 3600 * h;
139 }
140}
141
142void
144 if (0 <= m && m < 60) {
145 mySeconds -= 60 * getMinute();
146 mySeconds += 60 * m;
147 }
148}
149
150void
152 if (0 <= s && s < 60) {
153 mySeconds -= getSecond();
154 mySeconds += s;
155 }
156}
157
158void
159AGTime::setTime(int seconds) {
160 mySeconds = seconds;
161}
162
163void
165 mySeconds += 86400 * d;
166}
167
168void
170 mySeconds += 3600 * h;
171}
172
173void
175 mySeconds += 60 * m;
176}
177
178void
180 mySeconds += s;
181}
182
183
184/****************************************************************************/
void operator-=(const AGTime &time)
Definition AGTime.cpp:86
bool operator==(const AGTime &time)
Definition AGTime.cpp:49
int getSecond()
Definition AGTime.cpp:112
bool operator<=(const AGTime &time)
Definition AGTime.cpp:67
int getTime()
: returns the number of seconds from the beginning of the first day of simulation this includes
Definition AGTime.cpp:122
void setSecond(int s)
Definition AGTime.cpp:151
AGTime operator+(const AGTime &time)
Definition AGTime.cpp:91
int getSecondsInCurrentDay()
Definition AGTime.cpp:117
void setDay(int d)
Definition AGTime.cpp:127
void setHour(int h)
Definition AGTime.cpp:135
int convert(int days, int hours, int minutes, int seconds)
converts days, hours and minutes to seconds
Definition AGTime.cpp:38
void addMinutes(int min)
addition of minutes to the current moment
Definition AGTime.cpp:174
void setTime(int sec)
: sets the time from the beginning of the first day of simulation in seconds
Definition AGTime.cpp:159
void operator+=(const AGTime &time)
Definition AGTime.cpp:76
int getSecondsOf(double minutes)
computes the number of seconds in the given minutes
Definition AGTime.cpp:44
void setMinute(int m)
Definition AGTime.cpp:143
bool operator<(const AGTime &time)
Definition AGTime.cpp:58
void addDays(int days)
addition of days to the current moment
Definition AGTime.cpp:164
int getMinute()
Definition AGTime.cpp:107
void addSeconds(int sec)
addition of seconds to the current moment
Definition AGTime.cpp:179
int getHour()
Definition AGTime.cpp:102
int getDay()
Definition AGTime.cpp:97
AGTime(int seconds)
Definition AGTime.h:36
int mySeconds
Definition AGTime.h:126
void addHours(int hours)
addition of hours to the current moment
Definition AGTime.cpp:169