BloombergLP::bsls::TimeInterval

Each instance of this value-semantic type represents a time interval with nanosecond resolution. In the "canonical representation" of a time interval, the seconds field may have any 64-bit signed integer value, with the nanoseconds field limited to the range [ -999,999,999..999,999,999 ], and with the additional constraint that the two fields are either both non-negative or both non-positive.

Synopsis

Declared in <bsls_timeinterval.h>

class TimeInterval;

Member Functions

NameDescription
TimeInterval [constructor]Constructors
operator= Assign to this time interval the value of the specified rhs real number of seconds, and return a reference providing modifiable access to this object. The fractional part of rhs, if any, is rounded to the nearest whole number of nanoseconds. The behavior is undefined unless rhs can be converted to a valid TimeInterval object.
addDays Add to this time interval the number of seconds represented by the specified integral number of days, and return a reference providing modifiable access to this object. The behavior is undefined unless the number of seconds in days, and the total number of seconds in the resulting time interval, can both be represented with 64-bit signed integers. Note that days may be negative.
addDuration Add to this time interval the specified duration. Return a reference providing modifiable access to this object. The behavior is undefined unless the duration can be converted to a valid TimeInterval object, whose seconds field may have any 64-bit signed integer value and nanoseconds field limited to the range [ -999,999,999..999,999,999 ]. Also the behavior is undefined unless the total number of seconds in the resulting time interval can be represented with 64-bit signed integer. Note that this operation is allowed only if representation type of the duration is not a floating point type and the duration itself can be exactly represented by an integer nanoseconds.
addHours Add to this time interval the number of seconds represented by the specified integral number of hours, and return a reference providing modifiable access to this object. The behavior is undefined unless the number of seconds in hours, and the total number of seconds in the resulting time interval, can both be represented with 64-bit signed integers. Note that hours may be negative.
addInterval Add to this time interval the specified integral number of seconds, and the optionally specified integral number of nanoseconds. If unspecified, nanoseconds is 0. Return a reference providing modifiable access to this object. The behavior is undefined unless seconds() + seconds, and the total number of seconds in the resulting time interval, can both be represented with 64-bit signed integers.
addMicroseconds Add to this time interval the specified integral number of microseconds, and return a reference providing modifiable access to this object. The behavior is undefined unless the total number of seconds in the resulting time interval can be represented with a 64-bit signed integer. Note that microseconds may be negative.
addMilliseconds Add to this time interval the specified integral number of milliseconds, and return a reference providing modifiable access to this object. The behavior is undefined unless the total number of seconds in the resulting time interval can be represented with a 64-bit signed integer. Note that milliseconds may be negative.
addMinutes Add to this time interval the number of seconds represented by the specified integral number of minutes, and return a reference providing modifiable access to this object. The behavior is undefined unless the number of seconds in minutes, and the total number of seconds in the resulting time interval, can both be represented with 64-bit signed integers. Note that minutes may be negative.
addNanoseconds Add to this time interval the specified integral number of nanoseconds, and return a reference providing modifiable access to this object. The behavior is undefined unless the total number of seconds in the resulting time interval can be represented with a 64-bit signed integer. Note that nanoseconds may be negative.
addSeconds Add to this time interval the specified integral number of seconds, and return a reference providing modifiable access to this object. The behavior is undefined unless the total number of seconds in the resulting time interval can be represented with a 64-bit signed integer. Note that seconds may be negative.
asDuration Return the value of this time interval as a std::chrono::duration object. This function participates in overloading if DURATION_TYPE is actually an std::chrono::duration instance, and if it has not a floating point representation. The behavior is undefined unless the total number of nanoseconds can be represented using a DURATION_TYPE. Note that the return value may be negative.
bdexStreamIn Assign to this object the value read from the specified input stream using the specified version format, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, this object is unaltered and stream is invalidated, but otherwise unmodified. If version is supported but stream becomes invalid during this operation, this object has an undefined, but valid, state. Note that no version is read from stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
bdexStreamOut Write the value of this object, using the specified version format, to the specified output stream, and return a reference to stream. If stream is initially invalid, this operation has no effect. If version is not supported, stream is invalidated, but otherwise unmodified. Note that version is not written to stream. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.
isInDurationRange Return true if the value of this time interval is within the valid range of the parameterized DURATION_TYPE, and false otherwise. Note that this function does not participate in overload resolution unless DURATION_TYPE is an instantiation of std::chrono::duration.
nanoseconds Return the nanoseconds field in the canonical representation of the value of this time interval.
operator+= Addition assignment operators
operator-= Subtraction assignment operators
print Write the value of this object to the specified output stream in a human-readable format, and return a reference providing modifiable access to stream. Optionally specify an initial indentation level, whose absolute value is incremented recursively for nested objects. If level is specified, optionally specify spacesPerLevel, whose absolute value indicates the number of spaces per indentation level for this and all of its nested objects. If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level). If stream is not valid on entry, this operation has no effect. Note that the format is not fully specified, and can change without notice.
seconds Return the seconds field in the canonical representation of the value of this time interval.
setInterval Set this time interval to have the value given by the sum of the specified integral number of seconds, and the optionally specified integral number of nanoseconds. If unspecified, nanoseconds is 0. The behavior is undefined unless the total number of seconds in the resulting time interval can be represented with a 64-bit signed integer (see isValid). Note that there is no restriction on the sign or magnitude of either argument except that they must not violate the method's preconditions.
setIntervalRaw Set this time interval to have the value given by the sum of the specified integral number of seconds, and the optionally specified integral number of nanoseconds, where seconds and nanoseconds form a canonical representation of a time interval (see {Representation}). If unspecified, nanoseconds is 0. The behavior is undefined unless -999,999,999 <= nanoseconds <= +999,999,999 and seconds and nanoseconds are either both non-negative or both non-positive. Note that this function provides a subset of the defined behavior of setInterval chosen to minimize runtime performance cost.
setTotalDays Set the overall value of this object to indicate the specified integral number of days. The behavior is undefined unless the number of seconds in days can be represented with a 64-bit signed integer. Note that days may be negative.
setTotalHours Set the overall value of this object to indicate the specified integral number of hours. The behavior is undefined unless the number of seconds in hours can be represented with a 64-bit signed integer. Note that hours may be negative.
setTotalMicroseconds Set the overall value of this object to indicate the specified integral number of microseconds. Note that microseconds may be negative.
setTotalMilliseconds Set the overall value of this object to indicate the specified integral number of milliseconds. Note that milliseconds may be negative.
setTotalMinutes Set the overall value of this object to indicate the specified integral number of minutes. The behavior is undefined unless the number of seconds in minutes can be represented with a 64-bit signed integer. Note that minutes may be negative.
setTotalNanoseconds Set the overall value of this object to indicate the specified integral number of nanoseconds. Note that nanoseconds may be negative.
setTotalSeconds Set the overall value of this object to indicate the specified integral number of seconds. Note that seconds may be negative.
streamOut Format this time to the specified output stream, and return a reference to the modifiable stream.
totalDays Return the value of this time interval as an integral number of days, rounded towards zero. Note that the return value may be negative.
totalHours Return the value of this time interval as an integral number of hours, rounded towards zero. Note that the return value may be negative.
totalMicroseconds Return the value of this time interval as an integral number of microseconds, rounded towards zero. The behavior is undefined unless the number of microseconds can be represented with a 64-bit signed integer. Note that the return value may be negative.
totalMilliseconds Return the value of this time interval as an integral number of milliseconds, rounded towards zero. The behavior is undefined unless the number of milliseconds can be represented with a 64-bit signed integer. Note that the return value may be negative.
totalMinutes Return the value of this time interval as an integral number of minutes, rounded towards zero. Note that the return value may be negative.
totalNanoseconds Return the value of this time interval as an integral number of nanoseconds. The behavior is undefined unless the number of nanoseconds can be represented using a 64-bit signed integer. Note that the return value may be negative.
totalSeconds Return the value of this time interval as an integral number of seconds, rounded towards zero. Note that the return value may be negative. Also note that this method returns the same value as seconds.
totalSecondsAsDouble Return the value of this time interval as a real number of seconds. Note that the return value may be negative and may have a fractional part (representing the nanosecond field of this object). Also note that the conversion from the internal representation to a double may lose precision.

Static Member Functions

NameDescription
isValid isValid overloads
maxSupportedBdexVersion maxSupportedBdexVersion overloads
maxSupportedVersion Return the most current BDEX streaming version number supported by this class.

Non-Member Functions

NameDescription
operator!=Return true if the specified lhs and rhs time intervals do not have the same value, and false otherwise. Two time intervals do not have the same value if their respective second or nanosecond fields differ in value. The behavior is undefined unless operands of type double can be converted to valid TimeInterval objects.
operator!=Same as the preceding overload, converting rhs from double.
operator""_hThis user defined literal operator converts the specified hours value to the respective TimeInterval value. The behavior is undefined unless the specified number of hours can be converted to valid TimeInterval object. (See the "User-Defined Literals" section in the component-level documentation.)
operator""_minThis user defined literal operator converts the specified minutes value to the respective TimeInterval value. The behavior is undefined unless the specified number of minutes can be converted to valid TimeInterval object. (See the "User-Defined Literals" section in the component-level documentation.)
operator""_msThis user defined literal operator converts the specified milliseconds value to the respective TimeInterval value. (See the "User-Defined Literals" section in the component-level documentation.)
operator""_nsThis user defined literal operator converts the specified nanoseconds value to the respective TimeInterval value. (See the "User-Defined Literals" section in the component-level documentation.)
operator""_sThis user defined literal operator converts the specified seconds value to the respective TimeInterval value. The behavior is undefined unless the specified number of seconds can be converted to valid TimeInterval object. (See the "User-Defined Literals" section in the component-level documentation.)
operator""_usThis user defined literal operator converts the specified microseconds value to the respective TimeInterval value. (See the "User-Defined Literals" section in the component-level documentation.)
operator+Return a TimeInterval value that is the sum of the specified lhs and rhs time intervals. The behavior is undefined unless (1) operands of type double can be converted to valid TimeInterval objects, and (2) the resulting time interval can be represented with a 64-bit signed integer.
operator+Same as the preceding overload, converting lhs from double.
operator+Same as the preceding overload, converting rhs from double.
operator-Return a TimeInterval value that is the negative of the specified rhs time interval. The behavior is undefined unless LLONG_MIN != rhs.seconds().
operator-Return a TimeInterval value that is the difference between the specified lhs and rhs time intervals. The behavior is undefined unless (1) operands of type double can be converted to valid TimeInterval objects, (2) the value on the right-hand side (potentially after conversion to a TimeInterval) has a number of seconds that is not LLONG_MIN, and (3) the resulting time interval can be represented with a 64-bit signed integer.
operator-Same as the preceding overload, converting lhs from double.
operator-Same as the preceding overload, converting rhs from double.
operator<Return true if the nominal relation between the specified lhs and rhs time interval values holds, and false otherwise. The behavior is undefined unless operands of type double can be converted to valid TimeInterval objects.
operator<Same as the preceding overload, converting rhs from double.
operator<=Same as the preceding overload.
operator<=Same as the preceding overload, converting rhs from double.
operator==Same as the preceding overload, converting rhs from double.
operator==Return true if the specified lhs and rhs time intervals have the same value, and false otherwise. Two time intervals have the same value if their respective second and nanosecond fields have the same value. The behavior is undefined unless operands of type double can be converted to valid TimeInterval objects.
operator>Same as the preceding overload.
operator>Same as the preceding overload, converting rhs from double.
operator>=Same as the preceding overload, converting rhs from double.
operator>=Same as the preceding overload.
::BloombergLP::bdlt::operator+Return a Datetime object having a value that is the sum of the specified lhs (bsls::TimeInterval) and the specified rhs (Datetime). If 24 == rhs.hour(), the result is the same as if the hour attribute of rhs is 0. The behavior is undefined unless the resulting value is in the valid range for a Datetime object.