time_period


An os_time_period represents a period of time with microsecond accuracy. Arithmetic operations on time periods are supported, as well as conversions to an integral number of days, hours, minutes, or seconds using one of the to_ ... () family of functions.

For backwards compatibility, you can construct a time period from a timeval (where available) or time_t . Similarly, you can convert a time period into a timeval or time_t using one of its conversion operators.

Library

Time<ToolKit>

Declaration

#include <ospace/time/tperiod.h>

class os_time_period

Interface

Constructor
os_time_period()
Constructs a zero second time period.
Constructor
os_time_period( const timeval& time )
Constructs a time period from the timeval structure time .
Constructor
os_time_period( long days , long hours , long minutes , long seconds , long microseconds )
Constructs a time period representing the sum of the days , hours , minutes , seconds, and microseconds (default 0) given. For a negative period, all values must be zero or negative.
Constructor
os_time_period( const os_time_period& time )
Constructs a copy of time .
Constructor
os_time_period( const timestruc_t& time )
Constructs a time period from the timestruc_t structure time , converting from nanoseconds to microseconds.
Constructor
os_time_period( const os_int64_t& seconds , long microseconds )
Constructs a time period with seconds seconds and microseconds (default 0) microseconds. Note that there are 1 million microseconds in a second. All values are assumed reduced such that seconds and microseconds are below these rollover points. For example, 2.3 seconds would be 2 seconds, 300000 microseconds. The value would not be accepted as 2300000 microseconds. For negative time periods, both values must be zero or negative.

Throws: os_time_toolkit_error

!=
bool operator!=( const os_time_period& time ) const
Returns true if time period is not equal to time .
%
os_time_period operator%( long value ) const
Returns the time period modulus value .
%=
os_time_period& operator%=( long value )
Applies the modulus value to time period and returns that value.
*=
os_time_period& operator*=( long value )
Multiplies the time period by value and returns the new time period.
+
os_time_period operator+( const os_time_period& time ) const
Returns time period added to time .
+=
os_time_period& operator+=( const os_time_period& time )
Adds time to time period and returns the new time period.
-
os_time_period operator-( const os_time_period& time ) const
Returns time subtracted from time period.
-
os_time_period operator-() const
Returns time period negated.
-=
os_time_period& operator-=( const os_time_period& time )
Subtracts time from time period and returns the new time period.
/
os_time_period operator/( long value ) const
Returns a time period that is value times smaller than time period.
/=
os_time_period& operator/=( long value )
Decreases time period value times and returns the new time period.
<
bool operator<( const os_time_period& time ) const
Returns true if time period is less than time .
<=
bool operator<=( const os_time_period& time ) const
Returns true if time period is less than or equal to time .
=
os_time_period& operator=( os_int64_t time )
Constructs a time period with time seconds.
=
os_time_period& operator=( const timestruc_t& time )
Assigns time period a value encoded by time .
=
os_time_period& operator=( const os_time_period& time )
Assigns time to time period.
=
os_time_period& operator=( const timeval& time )
Assigns time period a value encoded by time .
==
bool operator==( const os_time_period& time ) const
Returns true if time period is equal to time .
>
bool operator>( const os_time_period& time ) const
Returns true if time period is greater than time .
>=
bool operator>=( const os_time_period& time ) const
Returns true if time period is greater than or equal to time .
(timestruc_t)
operator timestruc_t() const
Returns time period encoded as a timestruc_t structure.
is_microsecond
/* static */ bool is_microsecond( long microsecond )
Returns true if microsecond is a valid microsecond. Note that unlike a microsecond for an os_time , microsecond can be negative.
microseconds
long microseconds() const
Returns time period in microseconds.
print
void print( ostream& stream ) const
Prints to stream .
time_period
void time_period( const timestruc_t& time )
Assigns time period a value encoded by time .
time_period
void time_period( const timeval& time )
Sets time period to time .
time_period
void time_period( const os_int64_t& seconds , long microseconds )
Sets time period to the sum of the seconds and microseconds (default 0) given. For a negative period, all values must be zero or negative.
time_period
void time_period( long days , long hours , long minutes , long seconds , long microseconds )
Sets time period to the sum of the days , hours , minutes , seconds, and microseconds (default 0) given. For a negative period, all values must be zero or negative.

Throws: os_time_toolkit_error

(timeval)
operator timeval() const
Returns time period encoded as a timeval structure.
to_days
long to_days() const
Returns the number of complete days in the time period.
to_hours
long to_hours() const
Returns the number of complete hours in the time period.
to_minutes
long to_minutes() const
Returns the number of complete minutes in the time period.
to_seconds
long to_seconds() const
Returns the number of complete seconds in the time period.
to_string
string to_string() const
Returns a string representation of time period.

Non-Member Functions

*
os_time_period operator*( long value , const os_time_period& time )
Returns a time period that is value times greater than time .
<<
ostream& operator<<( ostream& stream , const os_time_period& period )
Prints period to stream .

Universal Streaming Service

#include <ospace/uss/time.h>

<<
os_bstream& operator<<( os_bstream& stream , const os_time_period& period )
Writes period to stream .
>>
os_bstream& operator>>( os_bstream& stream , os_time_period& period )
Reads period from stream .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.