C++ UTC Time Library
A class to hold UTC times, and associated functionality.
 All Classes Namespaces Files Functions Pages
Public Member Functions | List of all members
utctime::UTCTime Class Reference

#include <utctime.h>

Public Member Functions

 UTCTime ()
 Default constructor.
 UTCTime (const std::tm &utc_tm)
 Constructor taking a std::tm struct.
 UTCTime (const int year, const int month, const int day, const int hour, const int minute, const int second)
 Constructor taking individual date values.
std::tm get_tm () const
 Returns a std::tm struct containing the UTC datetime.
std::string time_string () const
 Returns a std::string containing the UTC datetime.
std::string time_string_inet () const
 Returns a std::string containing the UTC datetime in RFC3339 format.
time_t timestamp () const
 Returns a time_t timestamp for the UTC datetime.
bool operator< (const UTCTime &rhs) const
 Overloaded less than operator.
bool operator>= (const UTCTime &rhs) const
 Overloaded greater than or equal to operator.
bool operator> (const UTCTime &rhs) const
 Overloaded greater than operator.
bool operator<= (const UTCTime &rhs) const
 Overloaded less than or equal to operator.
bool operator== (const UTCTime &rhs) const
 Overloaded equality operator.
bool operator!= (const UTCTime &rhs) const
 Overloaded inequality operator.
double operator- (const UTCTime &rhs) const
 Overloaded subtraction operator.

Detailed Description

A class for holding a UTC time.

Constructor & Destructor Documentation

UTCTime::UTCTime ( )
explicit

Default constructor, which initializes to the current time.

Exceptions
bad_time_initif unable to get the current time.
UTCTime::UTCTime ( const std::tm &  utc_tm)
explicit

Constructor taking a std::tm struct.

Parameters
utc_tmA std::tm struct containing the desired initialization time.
Exceptions
bad_time_initif unable to get the current time.
invalid_dateif the supplied date is bad.
UTCTime::UTCTime ( const int  year,
const int  month,
const int  day,
const int  hour,
const int  minute,
const int  second 
)
explicit

Constructor taking individual date values.

Parameters
yearThe year
monthThe month, 1 to 12
dayThe day, 1 to 31, depending on month
hourThe hour, 0 to 23
minuteThe minute, 0 to 59
secondThe second, 0 to 59. Leap seconds are not supported.
Exceptions
bad_time_initif unable to get the current time.
invalid_dateif the supplied date is bad.

Member Function Documentation

std::tm UTCTime::get_tm ( ) const

Returns a std::tm struct containing the UTC datetime.

Returns
A std::tm struct containing the UTC datetime.
bool UTCTime::operator!= ( const UTCTime rhs) const

Overloaded inequality operator

Parameters
rhsThe UTCTime instance to which to compare
Returns
true if the instance is not equal to rhs, false otherwise.
double UTCTime::operator- ( const UTCTime rhs) const

Overloaded subtraction operator

Parameters
rhsThe UTCTime instance to subtract from the instance
Returns
The difference, in seconds, between the two instances.
bool UTCTime::operator< ( const UTCTime rhs) const

Overloaded less than operator

Parameters
rhsThe UTCTime instance to which to compare
Returns
true if the instance is less than rhs, false otherwise.
bool UTCTime::operator<= ( const UTCTime rhs) const

Overloaded less than or equal to operator

Parameters
rhsThe UTCTime instance to which to compare
Returns
true if the instance is less than or equal to rhs, false otherwise.
bool UTCTime::operator== ( const UTCTime rhs) const

Overloaded equality operator

Parameters
rhsThe UTCTime instance to which to compare
Returns
true if the instance is equal to rhs, false otherwise.
bool UTCTime::operator> ( const UTCTime rhs) const

Overloaded greater than operator

Parameters
rhsThe UTCTime instance to which to compare
Returns
true if the instance is greater than rhs, false otherwise.
bool UTCTime::operator>= ( const UTCTime rhs) const

Overloaded greater than or equal to operator

Parameters
rhsThe UTCTime instance to which to compare
Returns
true if the instance is greater than or equal to rhs, false otherwise.
std::string UTCTime::time_string ( ) const

Returns a std::string containing the UTC datetime.

Returns
A std::string containing the UTC datetime.
Exceptions
bad_timeif unable to get the time.
std::string UTCTime::time_string_inet ( ) const

Returns a std::string containing the UTC datetime in RFC3339 format.

Returns
A std::string containing the UTC datetime in RFC3339 format.
Exceptions
bad_timeif unable to get the time.
time_t UTCTime::timestamp ( ) const

Returns a time_t timestamp for the UTC datetime.

Returns
A time_t timestamp for the UTC datetime.

The documentation for this class was generated from the following files: