#include <Time.h>
Public Types | |
UTC | |
Local | |
enum | Zone { UTC, Local } |
Type for time zone designation. More... | |
Public Member Functions | |
Time () | |
Default constructor makes zero (epoch) time. | |
Time (time_t sec_since_1970_01_01, uint32_t nsec=0) | |
Construct from UNIX time. | |
Time (int year, int month, int day, int hour, int min, int sec, uint32_t nsec=0, Zone zone=Local) | |
Construct from broken-down representation. | |
Time (struct timespec &ts) | |
Constructs a time from the timespec struct (for high resolution time). | |
Time (struct tm &tms, Zone zone=Local) | |
Constructs a time from the tm struct (broken-down time) and zone. | |
Time (const std::string &str) | |
Constructs a time from the string representation. | |
Duration | operator- (const Time &t) const |
Subtract two times and return duration. | |
Time & | operator+= (const Duration &d) |
Add duration to time. | |
Time & | operator-= (const Duration &d) |
Subtract duration from time. | |
bool | operator!= (const Time &t) const |
Compare two times. | |
bool | operator== (const Time &t) const |
Compare two times. | |
bool | operator< (const Time &t) const |
Compare two times. | |
bool | operator> (const Time &t) const |
Compare two times. | |
bool | operator>= (const Time &t) const |
Compare two times. | |
bool | operator<= (const Time &t) const |
Compare two times. | |
time_t | sec () const |
POSIX sec. since 00:00:00 Jan. 1, 1970 UTC. | |
uint32_t | nsec () const |
returns nanoseconds value | |
timespec | getTimeSpec () const |
Returns the Time object content via high-resolution time timespec structure. | |
tm | gettm (Zone zone=Local) const |
Returns the Time object content via broken-down time tm structure for indicated zone. | |
std::string | asString (Zone zone=Local, int nsecPrecision=9) const |
Return time representation in extended ISO8601 format. | |
std::string | asStringCompact (Zone zone=Local, int nsecPrecision=0) const |
Return time representation in basic ISO8601 format. | |
std::string | asStringFormat (const std::string &fmt="%Y-%m-%d %H:%M:%S%f%z", Zone zone=Local) const |
Format time according the supplied format string. | |
Static Public Member Functions | |
static Time | now () |
Returns current time. |
The transformation to/from human-readable time format, required by I/O, is based on the standard ISO8601 time presentation.
This is essentially a wrap-up for clock_gettime() [UNIX/POSIX time] access to high-resolution time method, utilizing "struct timespec" and "struct tm" from <time.h> Some arithmetics between PSTime and PSDuration objects is also available.
This software was developed for the LCLS project. If you use all or part of it, please give an appropriate acknowledgment.
Definition at line 74 of file Time.h.
enum PSTime::Time::Zone |
Type for time zone designation.
There are several methods in Time class which can produce time representation in either local or UTC time zones. By default all these methods assume local time zone, use UTC enum value as the parameter to those methods to produce UTC representation.
PSTime::Time::Time | ( | ) |
PSTime::Time::Time | ( | time_t | sec_since_1970_01_01, | |
uint32_t | nsec = 0 | |||
) | [explicit] |
PSTime::Time::Time | ( | int | year, | |
int | month, | |||
int | day, | |||
int | hour, | |||
int | min, | |||
int | sec, | |||
uint32_t | nsec = 0 , |
|||
Zone | zone = Local | |||
) |
Construct from broken-down representation.
[in] | year | Calendar year C.E. (e.g., 2010). |
[in] | month | Month in the range [1,12]. |
[in] | day | Day of the month in the range [1,31]. |
[in] | hour | Hours in the range [0,23]. |
[in] | min | Minutes after the hour in the range [0,59]. |
[in] | sec | Seconds in the range [0,59*] (*) might be up to 61 for leap seconds. |
[in] | nsec | Nanoseconds after the second in the range [0,999999999]. |
[in] | zone | Time zone, default is local time zone. |
Definition at line 65 of file Time.cpp.
References PSTime::TimeUtils::timegm(), and UTC.
PSTime::Time::Time | ( | struct timespec & | ts | ) | [explicit] |
PSTime::Time::Time | ( | struct tm & | tms, | |
Zone | zone = Local | |||
) | [explicit] |
Constructs a time from the tm struct (broken-down time) and zone.
Definition at line 98 of file Time.cpp.
References PSTime::TimeUtils::timegm(), and UTC.
PSTime::Time::Time | ( | const std::string & | str | ) | [explicit] |
Constructs a time from the string representation.
Accepts the time stamp in format:
YYYY-MM-DD
, YYYYMMDD
, YYYY-MM
, YYYYMM
, or YYYY
, if month or day is missing they are assumed to be 1; HH:MM:SS
, HHMMSS
, HH:MM
, HHMM
, HH
, if minutes or seconds are missing they are assumed to be 0; Z
for UTC or in format {sign}HH
[:MM] or {sign}HHMM, if this field is missing time is assumed to be in local time zone.TimeParseException |
Definition at line 110 of file Time.cpp.
References PSTime::TimeFormat::parseTime(), and mpids_test::t.
std::string PSTime::Time::asString | ( | Zone | zone = Local , |
|
int | nsecPrecision = 9 | |||
) | const |
Return time representation in extended ISO8601 format.
Output will look like "2011-01-30 17:52:50.123456789-08". This format is acceptable for human-readable output.
[in] | zone | Time zone to use for string representation |
[in] | nsecPrecision | Precision of nanoseconds field, if 0 then nanoseconds will not be shown. |
Definition at line 247 of file Time.cpp.
References PSTime::TimeFormat::format().
Referenced by main().
std::string PSTime::Time::asStringCompact | ( | Zone | zone = Local , |
|
int | nsecPrecision = 0 | |||
) | const |
Return time representation in basic ISO8601 format.
Output will look like "20110130T175250-08". This format is intended for machine-readable output, such as timestamps in file names, etc.
[in] | zone | Time zone to use for string representation |
[in] | nsecPrecision | Precision of nanoseconds field, if 0 then nanoseconds will not be shown. |
Definition at line 263 of file Time.cpp.
References PSTime::TimeFormat::format().
Referenced by main().
std::string PSTime::Time::asStringFormat | ( | const std::string & | fmt = "%Y-%m-%d %H:%M:%S%f%z" , |
|
Zone | zone = Local | |||
) | const |
Format time according the supplied format string.
For full description of the acceptable format codes see TimeFormat::format() method.
[in] | fmt | Format string |
[in] | zone | Time zone to use for string representation |
Definition at line 279 of file Time.cpp.
References PSTime::TimeFormat::format().
Referenced by main().
struct timespec PSTime::Time::getTimeSpec | ( | ) | const |
struct tm PSTime::Time::gettm | ( | Zone | zone = Local |
) | const |
Returns the Time object content via broken-down time tm structure for indicated zone.
Definition at line 231 of file Time.cpp.
Referenced by PSTime::TimeFormat::format().
Time PSTime::Time::now | ( | ) | [static] |
uint32_t PSTime::Time::nsec | ( | ) | const [inline] |
returns nanoseconds value
Definition at line 210 of file Time.h.
Referenced by PSTime::TimeFormat::format(), main(), and operator-().
bool PSTime::Time::operator!= | ( | const Time & | t | ) | const [inline] |
Add duration to time.
Definition at line 197 of file Time.cpp.
References PSTime::Duration::getNsec(), PSTime::Duration::getSec(), and nsecInASec.
Subtract duration from time.
Definition at line 170 of file Time.cpp.
References PSTime::Duration::getNsec(), PSTime::Duration::getSec(), and nsecInASec.
bool PSTime::Time::operator< | ( | const Time & | t | ) | const [inline] |
bool PSTime::Time::operator<= | ( | const Time & | t | ) | const [inline] |
bool PSTime::Time::operator== | ( | const Time & | t | ) | const [inline] |
bool PSTime::Time::operator> | ( | const Time & | t | ) | const [inline] |
bool PSTime::Time::operator>= | ( | const Time & | t | ) | const [inline] |
time_t PSTime::Time::sec | ( | ) | const [inline] |
POSIX sec. since 00:00:00 Jan. 1, 1970 UTC.
Definition at line 207 of file Time.h.
Referenced by PSTime::TimeFormat::format(), main(), and operator-().