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