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