#include <Time.h>
Inheritance diagram for Core::Time:
Public Member Functions | |
Time (int hour=0, int minute=0, int second=0, int milli=0) | |
virtual String * | className (void) const |
Answer receiver class name. | |
virtual int | hour (void) const |
virtual int | minute (void) const |
virtual int | second (void) const |
virtual int | millisecond (void) const |
virtual Time * | addHours (int hours) |
Adds the given number of hours to the current time. | |
virtual Time * | addMinutes (int minutes) |
Adds the given number of minutes to the current time. | |
virtual Time * | addSeconds (int seconds) |
Adds the given number of seconds to the current time. | |
virtual Time * | addMilliseconds (int millis) |
Adds the given number of milliseconds to the current time. | |
virtual Time * | subtractHours (int hours) |
virtual Time * | subtractMinutes (int minutes) |
virtual Time * | subtractSeconds (int seconds) |
virtual Time * | subtractMilliseconds (int millis) |
virtual Time * | differenceFrom (Time *time) |
virtual long | hash (void) const |
Answer object hash value. | |
virtual bool | isEqual (const Object *object) const |
Compare receiver with given object. | |
virtual bool | isEqual (const Object &object) const |
Compare receiver with given object. | |
virtual unsigned long | asMilliseconds (void) const |
virtual void | printOn (Stream *stream) const |
Print object identification into the stream. | |
Static Public Member Functions | |
static Time * | now () |
Returns a Time with the system's current time. | |
static Time * | midnight () |
Returns a Time of midnight (0:00:00.000). | |
static Time * | zero () |
Protected Attributes | |
unsigned long | _hours |
unsigned char | _minutes |
unsigned char | _seconds |
unsigned short | _milliseconds |
|
Definition at line 31 of file Time.cc. References _hours, _milliseconds, _minutes, and _seconds. Referenced by addHours(), addMilliseconds(), now(), subtractHours(), and subtractMilliseconds(). 00032 { 00033 _hours = hour; 00034 _minutes = minute; 00035 _seconds = second; 00036 _milliseconds = milli; 00037 }
|
|
Adds the given number of hours to the current time.
Definition at line 92 of file Time.cc. References _hours, _milliseconds, _minutes, _seconds, and Time(). 00093 { 00094 return new Time(_hours + hours, _minutes, _seconds, _milliseconds); 00095 }
|
|
Adds the given number of milliseconds to the current time. The seconds roll over if they would exceed the 1000 millisecond limit (0 - 999). Definition at line 112 of file Time.cc. References _hours, _milliseconds, _minutes, _seconds, and Time(). Referenced by addSeconds(). 00113 { 00114 int hours, minutes, seconds; 00115 millis += _milliseconds; 00116 seconds = _seconds + millis / 1000; 00117 minutes = _minutes + seconds / 60; 00118 hours = _hours + minutes / 60; 00119 minutes = minutes % 60; 00120 seconds = seconds % 60; 00121 millis = millis % 1000; 00122 return new Time(hours, minutes, seconds, millis); 00123 }
|
|
Adds the given number of minutes to the current time. The minutes roll over if they would exceed the 60 minute limit (0 - 59). Definition at line 98 of file Time.cc. References addSeconds(). 00099 { 00100 return addSeconds(minutes * 60); 00101 }
|
|
Adds the given number of seconds to the current time. The seconds roll over if they would exceed the 60 second limit (0 - 59). Definition at line 104 of file Time.cc. References addMilliseconds(). Referenced by addMinutes(). 00105 { 00106 return addMilliseconds(seconds * 1000); 00107 }
|
|
Definition at line 188 of file Time.cc. References _hours, _milliseconds, _minutes, and _seconds. Referenced by differenceFrom(). 00189 { 00190 return ((_hours * 60 + _minutes) * 60 + _seconds) * 1000 + _milliseconds; 00191 }
|
|
Answer receiver class name. Because there isn't any standard way to obtain class name this method comes to place. Every class should rewrite this method but many didn't (yet). Reimplemented from Core::Object. Definition at line 40 of file Time.cc. Referenced by isEqual(). 00041 { 00042 return new String("Time"); 00043 }
|
|
Definition at line 161 of file Time.cc. References asMilliseconds(), and zero(). 00162 { 00163 unsigned long millis = abs(asMilliseconds() - time->asMilliseconds()); 00164 return Time::zero()->addMilliseconds(millis); 00165 }
|
|
Answer object hash value. The value should be same for objects found equal with isEqual() method. So if you rewrite this method you should rewrite isEqual() method too. Reimplemented from Core::Object. Definition at line 168 of file Time.cc. References _hours, _milliseconds, _minutes, and _seconds. 00169 { 00170 long hashVal = _hours; 00171 hashVal += _minutes << 10; 00172 hashVal += _seconds << 16; 00173 hashVal += _milliseconds << 22; 00174 }
|
|
Definition at line 70 of file Time.cc. References _hours. Referenced by Core::Timestamp::fromDateAndTime(), and printOn(). 00071 { 00072 return _hours; 00073 }
|
|
Compare receiver with given object. Do not rewrite this method. It just a sugar for Object::isEqual(Object *).
Reimplemented from Core::Object. Definition at line 90 of file Time.h. References Core::Object::isEqual(). 00091 { return Object::isEqual(object); }
|
|
Compare receiver with given object. This method could compare objects with more sophisticated algorithm (eg. based on instance variables comparing or so). If you rewrite this method you should rewrite hash() too.
Reimplemented from Core::Object. Definition at line 176 of file Time.cc. References _hours, _milliseconds, _minutes, _seconds, className(), and Core::Object::className(). 00177 { 00178 if (!object->className()->isEqual(className())) return false; 00179 00180 const Time *t = dynamic_cast<const Time *>(object); 00181 return t->_hours == this->_hours && 00182 t->_minutes == this->_minutes && 00183 t->_seconds == this->_seconds && 00184 t->_milliseconds == this->_milliseconds; 00185 }
|
|
Returns a Time of midnight (0:00:00.000).
Definition at line 59 of file Time.cc. References zero(). 00060 { 00061 return Time::zero(); 00062 }
|
|
Definition at line 85 of file Time.cc. References _milliseconds. Referenced by Core::Timestamp::fromDateAndTime(), and printOn(). 00086 { 00087 return _milliseconds; 00088 }
|
|
Definition at line 75 of file Time.cc. References _minutes. Referenced by Core::Timestamp::fromDateAndTime(), and printOn(). 00076 { 00077 return _minutes; 00078 }
|
|
Returns a Time with the system's current time.
Definition at line 47 of file Time.cc. References Time(). 00048 { 00049 struct timeval timestamp; 00050 struct timezone tz; 00051 00052 gettimeofday(×tamp, &tz); 00053 const struct tm* time = localtime(×tamp.tv_sec); 00054 return new Time(time->tm_hour, time->tm_min, time->tm_sec, 00055 timestamp.tv_usec/1000); 00056 }
|
|
Print object identification into the stream. Object identification is formed from its className() by default. But complicated classes (eg. collections) may print some other information.
Reimplemented from Core::Object. Definition at line 194 of file Time.cc. References Core::String::format(), hour(), millisecond(), minute(), and second(). 00195 { 00196 String *timeStr; 00197 timeStr = String::format("%u:%02u:%02u.%03u", 00198 hour(), minute(), second(), millisecond()); 00199 stream->nextPutAll(timeStr); 00200 }
|
|
Definition at line 80 of file Time.cc. References _seconds. Referenced by Core::Timestamp::fromDateAndTime(), and printOn(). 00081 { 00082 return _seconds; 00083 }
|
|
Definition at line 125 of file Time.cc. References _hours, _milliseconds, _minutes, _seconds, and Time(). 00126 { 00127 return new Time(_hours - hours, _minutes, _seconds, _milliseconds); 00128 }
|
|
Definition at line 140 of file Time.cc. References _hours, _milliseconds, _minutes, _seconds, and Time(). Referenced by subtractSeconds(). 00141 { 00142 int seconds = millis / 1000; 00143 millis = _milliseconds - millis % 1000; 00144 while (millis < 1000) { 00145 seconds++; millis -= 1000; 00146 } 00147 int minutes = seconds / 60; 00148 seconds = _seconds - seconds % 60; 00149 while (seconds < 60) { 00150 minutes++; seconds -= 60; 00151 } 00152 int hours = minutes / 60; 00153 minutes = _minutes - minutes % 60; 00154 while (minutes < 60) { 00155 hours++; minutes -= 60; 00156 } 00157 hours = _hours - hours; 00158 return new Time(hours, minutes, seconds, millis); 00159 }
|
|
Definition at line 130 of file Time.cc. References subtractSeconds(). 00131 { 00132 return subtractSeconds(minutes * 60); 00133 }
|
|
Definition at line 135 of file Time.cc. References subtractMilliseconds(). Referenced by subtractMinutes(). 00136 { 00137 return subtractMilliseconds(seconds * 1000); 00138 }
|
|
Definition at line 64 of file Time.cc. Referenced by differenceFrom(), and midnight(). 00065 { 00066 return new Time; 00067 }
|
|
Definition at line 37 of file Time.h. Referenced by addHours(), addMilliseconds(), asMilliseconds(), hash(), hour(), isEqual(), subtractHours(), subtractMilliseconds(), and Time(). |
|
Definition at line 40 of file Time.h. Referenced by addHours(), addMilliseconds(), asMilliseconds(), hash(), isEqual(), millisecond(), subtractHours(), subtractMilliseconds(), and Time(). |
|
Definition at line 38 of file Time.h. Referenced by addHours(), addMilliseconds(), asMilliseconds(), hash(), isEqual(), minute(), subtractHours(), subtractMilliseconds(), and Time(). |
|
Definition at line 39 of file Time.h. Referenced by addHours(), addMilliseconds(), asMilliseconds(), hash(), isEqual(), second(), subtractHours(), subtractMilliseconds(), and Time(). |