SUMO - Simulation of Urban MObility
AGTime.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 // activitygen module
5 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/)
6 /****************************************************************************/
7 //
8 // This program and the accompanying materials
9 // are made available under the terms of the Eclipse Public License v2.0
10 // which accompanies this distribution, and is available at
11 // http://www.eclipse.org/legal/epl-v20.html
12 //
13 /****************************************************************************/
22 // Time manager: able to manipulate the time using Sumo's format (seconds)
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include "AGTime.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 AGTime::AGTime(const AGTime& time) {
42  sec = time.sec;
43 }
44 
45 int
46 AGTime::convert(int days, int hours, int minutes, int seconds) {
47  sec = seconds + 60 * (minutes + 60 * (hours + 24 * (days)));
48  return sec;
49 }
50 
51 int
52 AGTime::getSecondsOf(double minutes) {
53  return static_cast<int>(60.0 * minutes);
54 }
55 
56 bool
57 AGTime::operator==(const AGTime& time) {
58  if (this->sec == time.sec) {
59  return true;
60  } else {
61  return false;
62  }
63 }
64 
65 bool
66 AGTime::operator<(const AGTime& time) {
67  if (this->sec < time.sec) {
68  return true;
69  } else {
70  return false;
71  }
72 }
73 
74 bool
75 AGTime::operator<=(const AGTime& time) {
76  if (this->sec <= time.sec) {
77  return true;
78  } else {
79  return false;
80  }
81 }
82 
83 void
84 AGTime::operator+=(const AGTime& time) {
85  this->sec += time.sec;
86 }
87 
88 void
89 AGTime::operator+=(int seconds) {
90  this->sec += seconds;
91 }
92 
93 void
94 AGTime::operator-=(const AGTime& time) {
95  this->sec -= time.sec;
96 }
97 
98 AGTime
99 AGTime::operator+(const AGTime& time) {
100  AGTime newtime(time.sec + this->sec);
101  return newtime;
102 }
103 
104 int
106  return (sec / 86400);
107 }
108 
109 int
111  return ((sec / 3600) % 24);
112 }
113 
114 int
116  return ((sec / 60) % 60);
117 }
118 
119 int
121  return (sec % 60);
122 }
123 
124 int
126  return (sec % 86400);
127 }
128 
129 int
131  return this->sec;
132 }
133 
134 void
136  if (0 <= d) {
137  sec -= 86400 * getDay();
138  sec += 86400 * d;
139  }
140 }
141 
142 void
144  if (0 <= h && h < 24) {
145  sec -= 3600 * getHour();
146  sec += 3600 * h;
147  }
148 }
149 
150 void
152  if (0 <= m && m < 60) {
153  sec -= 60 * getMinute();
154  sec += 60 * m;
155  }
156 }
157 
158 void
160  if (0 <= s && s < 60) {
161  sec -= getSecond();
162  sec += s;
163  }
164 }
165 
166 void
168  this->sec = sec;
169 }
170 
171 void
173  sec += 86400 * d;
174 }
175 
176 void
178  sec += 3600 * h;
179 }
180 
181 void
183  sec += 60 * m;
184 }
185 
186 void
188  sec += s;
189 }
190 
191 /****************************************************************************/
int getHour()
Definition: AGTime.cpp:110
int convert(int days, int hours, int minutes, int seconds)
converts days, hours and minutes to seconds
Definition: AGTime.cpp:46
void setDay(int d)
Definition: AGTime.cpp:135
Definition: AGTime.h:43
void operator-=(const AGTime &time)
Definition: AGTime.cpp:94
int getSecond()
Definition: AGTime.cpp:120
void addDays(int days)
addition of days to the current moment
Definition: AGTime.cpp:172
bool operator<=(const AGTime &time)
Definition: AGTime.cpp:75
void addHours(int hours)
addition of hours to the current moment
Definition: AGTime.cpp:177
bool operator<(const AGTime &time)
Definition: AGTime.cpp:66
bool operator==(const AGTime &time)
Definition: AGTime.cpp:57
AGTime operator+(const AGTime &time)
Definition: AGTime.cpp:99
void operator+=(const AGTime &time)
Definition: AGTime.cpp:84
int sec
Definition: AGTime.h:136
void addMinutes(int min)
addition of minutes to the current moment
Definition: AGTime.cpp:182
void addSeconds(int sec)
addition of seconds to the current moment
Definition: AGTime.cpp:187
AGTime()
Definition: AGTime.h:45
void setMinute(int m)
Definition: AGTime.cpp:151
int getSecondsInCurrentDay()
Definition: AGTime.cpp:125
void setSecond(int s)
Definition: AGTime.cpp:159
int getSecondsOf(double minutes)
computes the number of seconds in the given minutes
Definition: AGTime.cpp:52
int getTime()
: returns the number of seconds from the beginning of the first day of simulation this includes ...
Definition: AGTime.cpp:130
void setHour(int h)
Definition: AGTime.cpp:143
int getMinute()
Definition: AGTime.cpp:115
void setTime(int sec)
: sets the time from the beginning of the first day of simulation in seconds
Definition: AGTime.cpp:167
int getDay()
Definition: AGTime.cpp:105