SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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.sourceforge.net/
13 // Copyright (C) 2001-2013 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
168 AGTime::setTime(int sec) {
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 /****************************************************************************/