Present  0.9
 All Classes Files Functions Variables Typedefs Friends Macros Pages
ClockTime Struct Reference

Class or struct representing a time as seen on a clock. More...

Public Member Functions

int_hour hour () const
 Get the hour component of a ClockTime (0 to 23, inclusive). More...
 
int_minute minute () const
 Get the minute component of a ClockTime (0 to 59, inclusive). More...
 
int_second second () const
 Get the second component of a ClockTime (0 to 59, inclusive). More...
 
int_nanosecond nanosecond () const
 Get the nanosecond component of a ClockTime (less than 10^9, the number of nanoseconds in a second). More...
 
double second_decimal () const
 Get the second component of a ClockTime as a decimal, based on both the second and nanosecond components. More...
 
TimeDelta time_since_midnight () const
 Get a TimeDelta with the time since midnight of a ClockTime. More...
 
ClockTimeoperator+= (const TimeDelta &delta)
 Add a TimeDelta to a ClockTime. More...
 
ClockTimeoperator-= (const TimeDelta &delta)
 Subtract a TimeDelta from a ClockTime. More...
 

Static Public Member Functions

static ClockTime create (int_hour hour)
 Create a new ClockTime based on an hour of the day. More...
 
static ClockTime create (int_hour hour, int_minute minute)
 Create a new ClockTime based on an hour and a minute. More...
 
static ClockTime create (int_hour hour, int_minute minute, int_second second)
 Create a new ClockTime based on an hour, a minute, and a second. More...
 
static ClockTime create (int_hour hour, int_minute minute, int_second second, int_nanosecond nanosecond)
 Create a new ClockTime based on an hour, a minute, a second, and a nanosecond. More...
 
static ClockTime create_with_decimal_seconds (int_hour hour, int_minute minute, double second)
 Create a new ClockTime based on an hour, a minute, and a decimal second. More...
 
static ClockTime midnight (void)
 Create a new ClockTime initialized to midnight (00:00). More...
 
static ClockTime noon ()
 Create a new ClockTime initialized to noon (12:00). More...
 
static short compare (const ClockTime &lhs, const ClockTime &rhs)
 Compare two ClockTime instances. More...
 

Public Attributes

present_bool has_error
 This will be true if there were any errors when creating this ClockTime. More...
 
struct {
   unsigned int   hour_out_of_range: 1
 
   unsigned int   minute_out_of_range: 1
 
   unsigned int   second_out_of_range: 1
 
   unsigned int   nanosecond_out_of_range: 1
 
errors
 If there were any errors when creating this ClockTime, then one or more of these fields will be set. More...
 
struct PresentClockTimeData data_
 

Friends

const ClockTime operator+ (const ClockTime &lhs, const TimeDelta &rhs)
 
const ClockTime operator+ (const TimeDelta &lhs, const ClockTime &rhs)
 
const ClockTime operator- (const ClockTime &lhs, const TimeDelta &rhs)
 
bool operator== (const ClockTime &lhs, const ClockTime &rhs)
 Determine whether two ClockTime instances are equal (lhs == rhs). More...
 
bool operator!= (const ClockTime &lhs, const ClockTime &rhs)
 
bool operator< (const ClockTime &lhs, const ClockTime &rhs)
 Determine whether a ClockTime is earlier than another ClockTime (lhs < rhs). More...
 
bool operator<= (const ClockTime &lhs, const ClockTime &rhs)
 Determine whether a ClockTime is earlier than or or the same as another ClockTime (lhs <= rhs). More...
 
bool operator> (const ClockTime &lhs, const ClockTime &rhs)
 Determine whether a ClockTime is later than another ClockTime (lhs > rhs). More...
 
bool operator>= (const ClockTime &lhs, const ClockTime &rhs)
 Determine whether a ClockTime is later than or the same as another ClockTime (lhs >= rhs). More...
 

Detailed Description

Class or struct representing a time as seen on a clock.

This includes hours, minutes, and seconds (up to nanosecond precision). There is no date information stored with the time, nor a time zone (so a ClockTime instance is NOT tied to a specific time zone).

Member Function Documentation

static ClockTime ClockTime::create ( int_hour  hour)
static

Create a new ClockTime based on an hour of the day.

If the hour is out of range, the ClockTime will have has_error and errors set.

Attention
Make sure to check for any errors by checking if the has_error field on the returned struct is true.

If has_error is true, then at least one of the fields in the errors struct will also be true.

See Also
ClockTime::has_error
ClockTime::errors
Parameters
hourThe hour of the day (0 to 23, inclusive).
static ClockTime ClockTime::create ( int_hour  hour,
int_minute  minute 
)
static

Create a new ClockTime based on an hour and a minute.

If the hour or the minute is out of range, the ClockTime will have has_error and errors set.

Attention
Make sure to check for any errors by checking if the has_error field on the returned struct is true.

If has_error is true, then at least one of the fields in the errors struct will also be true.

See Also
ClockTime::has_error
ClockTime::errors
Parameters
hourThe hour of the day (0 to 23, inclusive).
minuteThe minute of the hour (0 to 59, inclusive).
static ClockTime ClockTime::create ( int_hour  hour,
int_minute  minute,
int_second  second 
)
static

Create a new ClockTime based on an hour, a minute, and a second.

If the hour, the minute, or the second is out of range, the ClockTime will have has_error and errors set.

Attention
Make sure to check for any errors by checking if the has_error field on the returned struct is true.

If has_error is true, then at least one of the fields in the errors struct will also be true.

See Also
ClockTime::has_error
ClockTime::errors
Parameters
hourThe hour of the day (0 to 23, inclusive).
minuteThe minute of the hour (0 to 59, inclusive).
secondThe second of the minute (0 to 59, inclusive, or possibly 60 in the case of a leap second).
static ClockTime ClockTime::create ( int_hour  hour,
int_minute  minute,
int_second  second,
int_nanosecond  nanosecond 
)
static

Create a new ClockTime based on an hour, a minute, a second, and a nanosecond.

If the hour, minute, second, or nanosecond is out of range, the ClockTime will have has_error and errors set.

Attention
Make sure to check for any errors by checking if the has_error field on the returned struct is true.

If has_error is true, then at least one of the fields in the errors struct will also be true.

See Also
ClockTime::has_error
ClockTime::errors
Parameters
hourThe hour of the day (0 to 23, inclusive).
minuteThe minute of the hour (0 to 59, inclusive).
secondThe second of the minute (0 to 59, inclusive, or possibly 60 in the case of a leap second).
nanosecondThe nanosecond (0 to 10^9-1, inclusive, i.e. no bigger than the number of nanoseconds in a second).
static ClockTime ClockTime::create_with_decimal_seconds ( int_hour  hour,
int_minute  minute,
double  second 
)
static

Create a new ClockTime based on an hour, a minute, and a decimal second.

Attention
Make sure to check for any errors by checking if the has_error field on the returned struct is true.

If has_error is true, then at least one of the fields in the errors struct will also be true.

See Also
ClockTime::has_error
ClockTime::errors
Parameters
hourThe hour of the day (0 to 23, inclusive).
minuteThe minute of the hour (0 to 59, inclusive).
secondThe second of the minute (0 up to, but not including, 60).
static ClockTime ClockTime::midnight ( void  )
static

Create a new ClockTime initialized to midnight (00:00).

static ClockTime ClockTime::noon ( )
static

Create a new ClockTime initialized to noon (12:00).

int_hour ClockTime::hour ( ) const

Get the hour component of a ClockTime (0 to 23, inclusive).

int_minute ClockTime::minute ( ) const

Get the minute component of a ClockTime (0 to 59, inclusive).

int_second ClockTime::second ( ) const

Get the second component of a ClockTime (0 to 59, inclusive).

int_nanosecond ClockTime::nanosecond ( ) const

Get the nanosecond component of a ClockTime (less than 10^9, the number of nanoseconds in a second).

double ClockTime::second_decimal ( ) const

Get the second component of a ClockTime as a decimal, based on both the second and nanosecond components.

TimeDelta ClockTime::time_since_midnight ( ) const

Get a TimeDelta with the time since midnight of a ClockTime.

ClockTime& ClockTime::operator+= ( const TimeDelta delta)

Add a TimeDelta to a ClockTime.

If the result goes above 23:59:59.999... or below 00:00, the ClockTime will wrap around.

ClockTime& ClockTime::operator-= ( const TimeDelta delta)

Subtract a TimeDelta from a ClockTime.

If the result goes above 23:59:59.999... or below 00:00, the ClockTime will wrap around.

static short ClockTime::compare ( const ClockTime lhs,
const ClockTime rhs 
)
static

Compare two ClockTime instances.

  • If lhs < rhs, then a negative integer will be returned.
  • If lhs == rhs, then 0 will be returned.
  • If lhs > rhs, then a positive integer will be returned.

Friends And Related Function Documentation

const ClockTime operator+ ( const ClockTime lhs,
const TimeDelta rhs 
)
friend
const ClockTime operator+ ( const TimeDelta lhs,
const ClockTime rhs 
)
friend
const ClockTime operator- ( const ClockTime lhs,
const TimeDelta rhs 
)
friend
bool operator== ( const ClockTime lhs,
const ClockTime rhs 
)
friend

Determine whether two ClockTime instances are equal (lhs == rhs).

bool operator!= ( const ClockTime lhs,
const ClockTime rhs 
)
friend
bool operator< ( const ClockTime lhs,
const ClockTime rhs 
)
friend

Determine whether a ClockTime is earlier than another ClockTime (lhs < rhs).

bool operator<= ( const ClockTime lhs,
const ClockTime rhs 
)
friend

Determine whether a ClockTime is earlier than or or the same as another ClockTime (lhs <= rhs).

bool operator> ( const ClockTime lhs,
const ClockTime rhs 
)
friend

Determine whether a ClockTime is later than another ClockTime (lhs > rhs).

bool operator>= ( const ClockTime lhs,
const ClockTime rhs 
)
friend

Determine whether a ClockTime is later than or the same as another ClockTime (lhs >= rhs).

Member Data Documentation

present_bool ClockTime::has_error

This will be true if there were any errors when creating this ClockTime.

For more details about the errors that occurred, see errors. For more details about the errors that occurred, see errors.

This field should be treated as read-only; DO NOT modify its contents!

unsigned int ClockTime::hour_out_of_range
unsigned int ClockTime::minute_out_of_range
unsigned int ClockTime::second_out_of_range
unsigned int ClockTime::nanosecond_out_of_range
struct { ... } ClockTime::errors

If there were any errors when creating this ClockTime, then one or more of these fields will be set.

To quickly check if any error occurred, see has_error. To quickly check if any error occurred, see has_error.

These fields should be treated as read-only; DO NOT modify their contents!

struct PresentClockTimeData ClockTime::data_

The documentation for this struct was generated from the following file: