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