OWLTime

Synopsis

#include <owl/time.h>
OWLTime a;

Description

Class OWLTime represents a time, stored internally as the struct tm (see man for localtime to learn more about that structure) with the only difference that the year attribute specifies the number of years not since 1900 but from 0. There is the only one supported string representation of the time which is dd/mm/yy hh:mm[:ss][.mksecs].

Example

This example prints out the current time and constructs the time from some test string:
#include <owl/time.h>

int main(void)
{
  OWLTime now(0);

  cout << "Current time is: " << now << endl;

  const char * test_time = "25/05/00 17:34:59";

  OWLTime test(test_time);

  cout << "Check parsed test time \'" << test_time << "\':" << endl
       << " - year = " << test.year() << endl
       << " - month = " << test.month() << endl
       << " - day = " << test.day() << endl
       << " - hour = " << test.hour() << endl
       << " - minute = " << test.min() << endl
       << " - second = " << test.sec() << endl
       << " - microseconds = " << test.mksec() << endl;

  return 0;
}

The output of the program is the following (exact value of current time differ):
Current time is: 14/11/00 17:44:31
Check parsed test time '25/05/00 17:34:59':
 - year = 2000
 - month = 4
 - day = 25
 - hour = 17
 - minute = 34
 - second = 59
 -
microseconds = 123456

Public Enumeration

enum Precision { Seconds, Microseconds };
These two constants can be used to define the precision of the newly constructed OWLTime objects.

Public Constructor

OWLTime(Precision prc = Seconds);
Constructs the object representing the current time with the prc precision. Default precision is seconds.
OWLTime(const char * );
OWLTime(const struct tm &);
Constructs a time from reference to struct tm (it is expected that that struct was filled by one of the system functions like localtime or gmtime).
OWLTime (time_t seconds, time_t microseconds = 0)
Constructs a time from number of seconds and microseconds since epoch (00:00:00.000000 01/01/70).

Public Member Functions

long year() const;
The number of years since 0.
unsigned short month() const;
The number of months since January, in the range  0 to 11.
unsigned short day() const;
The day of the month, in the range 1 to 31.
unsigned short hour() const;
The number of hours past midnight, in the range 0 to 23.
unsigned short min() const;
The number of minutes after the hour, in the  range 0 to 59.
unsigned short sec() const;
The number of seconds after the minute, normally in the range 0 to 59, but can be up to 61 to allow for leap seconds.
unsigned long mksec() const;
The number of microseconds after the seconds, in the range 0 to 999999.
long long total_mksec_utc() const;
The total number of microseconds sinse epoch in UTC.
char * c_str() const;
Returns time as a C-string. The user is responsible to delete (i.e. call delete[]) this string when it is not needed.

Related Operators

int /* bool */ operator==(const OWLTime &) const;
int /* bool */ operator!=(const OWLTime &t) const;
int /* bool */ operator<(const OWLTime &) const;
int /* bool */ operator<=(const OWLTime &t) const;
int /* bool */ operator>(const OWLTime &t) const;
int /* bool */ operator>=(const OWLTime &t) const;
Logical compare operators.
ostream& operator<<(ostream&, const OWLTime&);
Output stream operator.