nlib
nn::nlib::TimeSpan Class Referencefinal

The class for representing the time. More...

#include "nn/nlib/DateTime.h"

Public Member Functions

void Get (int *days, int *seconds, int *milliseconds, int *microseconds) noexcept
 Gets the time, separated out into units of days, seconds, milliseconds, and microseconds. More...
 
TimeValue ToTimeValue () const noexcept
 Converts to a TimeValue object.
 
int ToDays () const noexcept
 Returns the time in terms of a number of days. Fractions are truncated.
 
int ToHours () const noexcept
 Returns the time span as a number of hours. Fractions are truncated.
 
int64_t ToMinutes () const noexcept
 Returns the time as a number of minutes. Fractions are truncated.
 
int64_t ToSeconds () const noexcept
 Returns the time in terms of a number of seconds. Fractions are truncated.
 
int64_t ToMilliSeconds () const noexcept
 Returns the time in terms of a number of milliseconds. Fractions are truncated.
 
int64_t ToMicroSeconds () const noexcept
 Returns the time in terms of a number of microseconds. Fractions are truncated.
 
 TimeSpan (const struct timespec *tm) noexcept
 Instantiates the object from the timespec structure.
 
void ToTimeSpec (struct timespec *tm) const noexcept
 Converts to a value of the timespec structure.
 
TimeSpanoperator+= (const TimeSpan &rhs) noexcept
 Adds time.
 
TimeSpanoperator-= (const TimeSpan &rhs) noexcept
 Subtracts time.
 
TimeSpanoperator*= (int i) noexcept
 Multiplies the time by i.
 
TimeSpanoperator*= (double d) noexcept
 Multiplies the time by d.
 
TimeSpan operator- () const noexcept
 A unary operator.
 
TimeSpan operator+ () const noexcept
 A unary operator.
 
Basic Member Functions
constexpr TimeSpan () noexcept
 Instantiates the object and initializes the time to 0.
 
 TimeSpan (const TimeValue &rhs) noexcept
 Initializes using a TimeValue object.
 
constexpr TimeSpan (int days) noexcept
 Initializes the object with a number of days specified for the period of time. More...
 
constexpr TimeSpan (int days, int seconds) noexcept
 Initializes the object with a number of days and a number of seconds specified for the period of time. More...
 
constexpr TimeSpan (int days, int seconds, int milliseconds, int microseconds=0) noexcept
 Initializes the object with a number of days, seconds, milliseconds, and microseconds specified for the period of time. More...
 

Detailed Description

The class for representing the time.

Description
Displays the time in units of 100 nanoseconds as a 64-bit integer value. You can use various operators to perform operations like addition, subtraction, and comparisons on TimeSpan objects.
DateTime& dt = ....;
TimeSpan span(0, 60 * 60 * 10); // 10 hours
DateTime dt_plus_10 = dt + span; // Advances 10 hours.
Note that a leap second is not taken into account.
Examples:
misc/datetime/datetime.cpp, misc/threading/callonce/callonce.cpp, misc/threading/simpleringbuffer/simpleringbuffer.cpp, misc/threading/tls/tls.cpp, msgpack/jsonrpc/jsonrpc.cpp, and msgpack/jsonrpc/server.cpp.

Definition at line 97 of file DateTime.h.

Constructor & Destructor Documentation

◆ TimeSpan() [1/3]

nn::nlib::TimeSpan::TimeSpan ( int  days)
inlineexplicitnoexcept

Initializes the object with a number of days specified for the period of time.

Parameters
[in]daysA number of days.

Definition at line 101 of file DateTime.h.

◆ TimeSpan() [2/3]

nn::nlib::TimeSpan::TimeSpan ( int  days,
int  seconds 
)
inlinenoexcept

Initializes the object with a number of days and a number of seconds specified for the period of time.

Parameters
[in]daysA number of days.
[in]secondsA number of seconds.

Definition at line 103 of file DateTime.h.

◆ TimeSpan() [3/3]

nn::nlib::TimeSpan::TimeSpan ( int  days,
int  seconds,
int  milliseconds,
int  microseconds = 0 
)
inlinenoexcept

Initializes the object with a number of days, seconds, milliseconds, and microseconds specified for the period of time.

Parameters
[in]daysA number of days.
[in]secondsSeconds.
[in]millisecondsMilliseconds.
[in]microsecondsMicroseconds.

Definition at line 106 of file DateTime.h.

Member Function Documentation

◆ Get()

nn::nlib::TimeSpan::Get ( int *  days,
int *  seconds,
int *  milliseconds,
int *  microseconds 
)
noexcept

Gets the time, separated out into units of days, seconds, milliseconds, and microseconds.

Parameters
[out]daysSets the number of days.
[out]secondsSets the number of seconds.
[out]millisecondsSets the number of milliseconds.
[out]microsecondsSets the number of microseconds.

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