Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 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 are made available under the 7 : // terms of the Eclipse Public License 2.0 which is available at 8 : // https://www.eclipse.org/legal/epl-2.0/ 9 : // This Source Code may also be made available under the following Secondary 10 : // Licenses when the conditions for such availability set forth in the Eclipse 11 : // Public License 2.0 are satisfied: GNU General Public License, version 2 12 : // or later which is available at 13 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 14 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 15 : /****************************************************************************/ 16 : /// @file AGTime.cpp 17 : /// @author Piotr Woznica 18 : /// @author Daniel Krajzewicz 19 : /// @author Michael Behrisch 20 : /// @author Walter Bamberger 21 : /// @date July 2010 22 : /// 23 : // Time manager: able to manipulate the time using Sumo's format (seconds) 24 : /****************************************************************************/ 25 : #include <config.h> 26 : 27 : #include "AGTime.h" 28 : 29 : 30 : // =========================================================================== 31 : // method definitions 32 : // =========================================================================== 33 0 : AGTime::AGTime(const AGTime& time) { 34 0 : mySeconds = time.mySeconds; 35 0 : } 36 : 37 : int 38 5832 : AGTime::convert(int days, int hours, int minutes, int seconds) { 39 5832 : mySeconds = seconds + 60 * (minutes + 60 * (hours + 24 * (days))); 40 5832 : return mySeconds; 41 : } 42 : 43 : int 44 0 : AGTime::getSecondsOf(double minutes) { 45 0 : return static_cast<int>(60.0 * minutes); 46 : } 47 : 48 : bool 49 0 : AGTime::operator==(const AGTime& time) { 50 0 : if (this->mySeconds == time.mySeconds) { 51 : return true; 52 : } else { 53 0 : return false; 54 : } 55 : } 56 : 57 : bool 58 0 : AGTime::operator<(const AGTime& time) { 59 0 : if (this->mySeconds < time.mySeconds) { 60 : return true; 61 : } else { 62 0 : return false; 63 : } 64 : } 65 : 66 : bool 67 0 : AGTime::operator<=(const AGTime& time) { 68 0 : if (this->mySeconds <= time.mySeconds) { 69 : return true; 70 : } else { 71 0 : return false; 72 : } 73 : } 74 : 75 : void 76 0 : AGTime::operator+=(const AGTime& time) { 77 0 : this->mySeconds += time.mySeconds; 78 0 : } 79 : 80 : void 81 4616 : AGTime::operator+=(int seconds) { 82 4616 : this->mySeconds += seconds; 83 4616 : } 84 : 85 : void 86 0 : AGTime::operator-=(const AGTime& time) { 87 0 : this->mySeconds -= time.mySeconds; 88 0 : } 89 : 90 : AGTime 91 0 : AGTime::operator+(const AGTime& time) { 92 0 : AGTime newtime(time.mySeconds + this->mySeconds); 93 0 : return newtime; 94 : } 95 : 96 : int 97 10944 : AGTime::getDay() { 98 10944 : return (mySeconds / 86400); 99 : } 100 : 101 : int 102 14 : AGTime::getHour() { 103 14 : return ((mySeconds / 3600) % 24); 104 : } 105 : 106 : int 107 14 : AGTime::getMinute() { 108 14 : return ((mySeconds / 60) % 60); 109 : } 110 : 111 : int 112 14 : AGTime::getSecond() { 113 14 : return (mySeconds % 60); 114 : } 115 : 116 : int 117 4616 : AGTime::getSecondsInCurrentDay() { 118 4616 : return (mySeconds % 86400); 119 : } 120 : 121 : int 122 3916 : AGTime::getTime() { 123 3916 : return this->mySeconds; 124 : } 125 : 126 : void 127 82 : AGTime::setDay(int d) { 128 82 : if (0 <= d) { 129 82 : mySeconds -= 86400 * getDay(); 130 82 : mySeconds += 86400 * d; 131 : } 132 82 : } 133 : 134 : void 135 0 : AGTime::setHour(int h) { 136 0 : if (0 <= h && h < 24) { 137 0 : mySeconds -= 3600 * getHour(); 138 0 : mySeconds += 3600 * h; 139 : } 140 0 : } 141 : 142 : void 143 0 : AGTime::setMinute(int m) { 144 0 : if (0 <= m && m < 60) { 145 0 : mySeconds -= 60 * getMinute(); 146 0 : mySeconds += 60 * m; 147 : } 148 0 : } 149 : 150 : void 151 0 : AGTime::setSecond(int s) { 152 0 : if (0 <= s && s < 60) { 153 0 : mySeconds -= getSecond(); 154 0 : mySeconds += s; 155 : } 156 0 : } 157 : 158 : void 159 38 : AGTime::setTime(int seconds) { 160 38 : mySeconds = seconds; 161 38 : } 162 : 163 : void 164 50 : AGTime::addDays(int d) { 165 50 : mySeconds += 86400 * d; 166 50 : } 167 : 168 : void 169 0 : AGTime::addHours(int h) { 170 0 : mySeconds += 3600 * h; 171 0 : } 172 : 173 : void 174 999 : AGTime::addMinutes(int m) { 175 999 : mySeconds += 60 * m; 176 999 : } 177 : 178 : void 179 999 : AGTime::addSeconds(int s) { 180 999 : mySeconds += s; 181 999 : } 182 : 183 : 184 : /****************************************************************************/