vpr::DateTime Class Reference

Simple wrapper around time since the UNIX Epoch (00:00 UTC January 1, 1970). More...

#include <vpr/Util/DateTime.h>

List of all members.

Public Member Functions

 DateTime ()
 Constructs an empty time object.
void setNow ()
 Updates this object to reflect the current time.
vpr::Uint32 getSeconds ()
 Get the seconds since the Epoch for this object.
double getSecondsf ()
 Get the seconds (and microseconds) since the Epoch for this object.
vpr::Uint32 getMinutes ()
 Get the minutes since the Epoch for this object.
double getMinutesf ()
 Get the minutes since the Epoch for this object with floating-point precision.
vpr::Uint32 getHours ()
 Get the hours since the Epoch for this object.
double getHoursf ()
 Get the hours since the Epoch for this object with floating-point precision.
vpr::Uint32 getDays ()
 Get the days since the Epoch for this object.
double getDaysf ()
 Get the days since the Epoch for this object with floating-point precision.
vpr::Uint32 getWeeks ()
 Get the weeks since the Epoch for this object.
double getWeeksf ()
 Get the weeks since the Epoch for this object with floating-point precision.
DateTime operator+ (const DateTime &o) const
 Overloaded addition operator for adding this and another DateTime object.
DateTime operator- (const DateTime &o) const
 Overloaded addition operator for subtracting another DateTime object from this one.


Detailed Description

Simple wrapper around time since the UNIX Epoch (00:00 UTC January 1, 1970).

Definition at line 57 of file DateTime.h.


Constructor & Destructor Documentation

vpr::DateTime::DateTime (  )  [inline]

Constructs an empty time object.

To assign this object the current time, invoke setNow on it.

See also:
setNow

Definition at line 66 of file DateTime.h.

Referenced by operator+(), and operator-().

00067       : mSeconds(0)
00068       , mMicroSeconds(0)
00069    {
00070       /* Do nothing. */ ;
00071    }


Member Function Documentation

void vpr::DateTime::setNow (  )  [inline]

Updates this object to reflect the current time.

Postcondition:
The member variables are updated the time returned by vpr::System::gettimeofday.

Definition at line 79 of file DateTime.h.

References vpr::SystemPosix::gettimeofday(), vpr::TimeVal::tv_sec, and vpr::TimeVal::tv_usec.

Referenced by vpr::StatCollector< TYPE, TimeBased >::addSample(), vpr::SampleLimitedStatCollector< TYPE, TimeBased >::addSample(), vpr::StatCollector< TYPE, TimeBased >::getMean(), and vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getMean().

00080    {
00081       vpr::TimeVal tv;
00082 
00083       vpr::System::gettimeofday(&tv);
00084       mSeconds      = tv.tv_sec;
00085       mMicroSeconds = tv.tv_usec;
00086    }

vpr::Uint32 vpr::DateTime::getSeconds (  )  [inline]

Get the seconds since the Epoch for this object.

Returns:
An unsigned integer representing the seconds since the Epoch. If 0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 95 of file DateTime.h.

00096    {
00097       return mSeconds;
00098    }

double vpr::DateTime::getSecondsf (  )  [inline]

Get the seconds (and microseconds) since the Epoch for this object.

Returns:
A floating-point value representing the seconds since the Epoch. If 0.0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 107 of file DateTime.h.

Referenced by getDaysf(), getHoursf(), vpr::StatCollector< TYPE, TimeBased >::getMean(), vpr::SampleLimitedStatCollector< TYPE, TimeBased >::getMean(), getMinutesf(), and getWeeksf().

00108    {
00109       double sec_f, usec_f, usec_f_div;
00110 
00111       sec_f      = (double) mSeconds;
00112       usec_f     = (double) mMicroSeconds;
00113       usec_f_div = usec_f / 1000000.0f;
00114 
00115       return sec_f + usec_f_div;
00116    }

vpr::Uint32 vpr::DateTime::getMinutes (  )  [inline]

Get the minutes since the Epoch for this object.

Returns:
An unsigned integer representing the minutes since the Epoch. If 0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 125 of file DateTime.h.

00126    {
00127       return mSeconds / 60;
00128    }

double vpr::DateTime::getMinutesf (  )  [inline]

Get the minutes since the Epoch for this object with floating-point precision.

Returns:
A floating-point value representing the minutes since the Epoch. If 0.0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 138 of file DateTime.h.

References getSecondsf().

Referenced by vpr::StatCollector< TYPE, TimeBased >::print(), and vpr::SampleLimitedStatCollector< TYPE, TimeBased >::print().

00139    {
00140       return getSecondsf() / 60.0f;
00141    }

vpr::Uint32 vpr::DateTime::getHours (  )  [inline]

Get the hours since the Epoch for this object.

Returns:
An unsigned integer representing the hours since the Epoch. If 0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 150 of file DateTime.h.

00151    {
00152       return mSeconds / 3600;
00153    }

double vpr::DateTime::getHoursf (  )  [inline]

Get the hours since the Epoch for this object with floating-point precision.

Returns:
A floating-point value representing the hours since the Epoch. If 0.0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 163 of file DateTime.h.

References getSecondsf().

00164    {
00165       return getSecondsf() / 3600.0f;
00166    }

vpr::Uint32 vpr::DateTime::getDays (  )  [inline]

Get the days since the Epoch for this object.

Returns:
An unsigned integer representing the days since the Epoch. If 0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 175 of file DateTime.h.

00176    {
00177       return mSeconds / 86400;
00178    }

double vpr::DateTime::getDaysf (  )  [inline]

Get the days since the Epoch for this object with floating-point precision.

Returns:
A floating-point value representing the days since the Epoch. If 0.0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 188 of file DateTime.h.

References getSecondsf().

00189    {
00190       return getSecondsf() / 86400.0f;
00191    }

vpr::Uint32 vpr::DateTime::getWeeks (  )  [inline]

Get the weeks since the Epoch for this object.

Returns:
An unsigned integer representing the weeks since the Epoch. If 0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 200 of file DateTime.h.

00201    {
00202       return mSeconds / 608400;
00203    }

double vpr::DateTime::getWeeksf (  )  [inline]

Get the weeks since the Epoch for this object with floating-point precision.

Returns:
A floating-point value representing the weeks since the Epoch. If 0.0 (zero) is returned, this object has not been initialized using setNow.

Definition at line 213 of file DateTime.h.

References getSecondsf().

00214    {
00215       return getSecondsf() / 608400.0f;
00216    }

DateTime vpr::DateTime::operator+ ( const DateTime o  )  const [inline]

Overloaded addition operator for adding this and another DateTime object.

Definition at line 222 of file DateTime.h.

References DateTime(), mMicroSeconds, and mSeconds.

00223    {
00224       const vpr::Uint32 us = mMicroSeconds + o.mMicroSeconds;
00225       if ( us > 1000000 )
00226       {
00227          return DateTime(mSeconds + o.mSeconds + 1, us - 1000000);
00228       }
00229       else 
00230       {
00231          return DateTime(mSeconds + o.mSeconds, us);
00232       }
00233    }

DateTime vpr::DateTime::operator- ( const DateTime o  )  const [inline]

Overloaded addition operator for subtracting another DateTime object from this one.

Definition at line 239 of file DateTime.h.

References DateTime(), mMicroSeconds, and mSeconds.

00240    {
00241       if ( mMicroSeconds > o.mMicroSeconds )
00242       {
00243          return DateTime(mSeconds - o.mSeconds,
00244                          mMicroSeconds - o.mMicroSeconds);
00245       }
00246       else
00247       {
00248          return DateTime(mSeconds - o.mSeconds - 1,
00249                          1000000 + mMicroSeconds - o.mMicroSeconds);
00250       }
00251    }


The documentation for this class was generated from the following file:
Generated on Thu Jan 4 10:56:02 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1