|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Time manager: able to manipulate the time using Sumo's format (seconds) 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 // activitygen module 00012 // Copyright 2010 TUM (Technische Universitaet Muenchen, http://www.tum.de/) 00013 /****************************************************************************/ 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; either version 2 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include "AGTime.h" 00033 00034 00035 // =========================================================================== 00036 // method definitions 00037 // =========================================================================== 00038 AGTime::AGTime(const AGTime& time) { 00039 sec = time.sec; 00040 } 00041 00042 int 00043 AGTime::convert(int days, int hours, int minutes, int seconds) { 00044 sec = seconds +60*(minutes + 60*(hours + 24*(days))); 00045 return sec; 00046 } 00047 00048 int 00049 AGTime::getSecondsOf(SUMOReal minutes) { 00050 return static_cast<int>(60.0 * minutes); 00051 } 00052 00053 bool 00054 AGTime::operator==(const AGTime& time) { 00055 if (this->sec == time.sec) { 00056 return true; 00057 } else { 00058 return false; 00059 } 00060 } 00061 00062 bool 00063 AGTime::operator<(const AGTime& time) { 00064 if (this->sec < time.sec) { 00065 return true; 00066 } else { 00067 return false; 00068 } 00069 } 00070 00071 bool 00072 AGTime::operator<=(const AGTime& time) { 00073 if (this->sec <= time.sec) { 00074 return true; 00075 } else { 00076 return false; 00077 } 00078 } 00079 00080 void 00081 AGTime::operator+=(const AGTime& time) { 00082 this->sec += time.sec; 00083 } 00084 00085 void 00086 AGTime::operator+=(int seconds) { 00087 this->sec += seconds; 00088 } 00089 00090 void 00091 AGTime::operator-=(const AGTime& time) { 00092 this->sec -= time.sec; 00093 } 00094 00095 AGTime 00096 AGTime::operator+(const AGTime& time) { 00097 AGTime newtime(time.sec + this->sec); 00098 return newtime; 00099 } 00100 00101 int 00102 AGTime::getDay() { 00103 return (sec / 86400); 00104 } 00105 00106 int 00107 AGTime::getHour() { 00108 return ((sec / 3600) % 24); 00109 } 00110 00111 int 00112 AGTime::getMinute() { 00113 return ((sec / 60) % 60); 00114 } 00115 00116 int 00117 AGTime::getSecond() { 00118 return (sec % 60); 00119 } 00120 00121 int 00122 AGTime::getSecondsInCurrentDay() { 00123 return (sec % 86400); 00124 } 00125 00126 int 00127 AGTime::getTime() { 00128 return this->sec; 00129 } 00130 00131 void 00132 AGTime::setDay(int d) { 00133 if (0 <= d) { 00134 sec -= 86400 * getDay(); 00135 sec += 86400 * d; 00136 } 00137 } 00138 00139 void 00140 AGTime::setHour(int h) { 00141 if (0 <= h && h < 24) { 00142 sec -= 3600 * getHour(); 00143 sec += 3600 * h; 00144 } 00145 } 00146 00147 void 00148 AGTime::setMinute(int m) { 00149 if (0 <= m && m < 60) { 00150 sec -= 60 * getMinute(); 00151 sec += 60 * m; 00152 } 00153 } 00154 00155 void 00156 AGTime::setSecond(int s) { 00157 if (0 <= s && s < 60) { 00158 sec -= getSecond(); 00159 sec += s; 00160 } 00161 } 00162 00163 void 00164 AGTime::setTime(int sec) { 00165 this->sec = sec; 00166 } 00167 00168 void 00169 AGTime::addDays(int d) { 00170 sec += 86400 * d; 00171 } 00172 00173 void 00174 AGTime::addHours(int h) { 00175 sec += 3600 * h; 00176 } 00177 00178 void 00179 AGTime::addMinutes(int m) { 00180 sec += 60 * m; 00181 } 00182 00183 void 00184 AGTime::addSeconds(int s) { 00185 sec += s; 00186 } 00187 00188 /****************************************************************************/