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