BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt::EpochUtil Struct Reference

#include <bdlt_epochutil.h>

Public Types

typedef bsls::Types::Int64 TimeT64
 

Static Public Member Functions

static const Datetimeepoch ()
 
static Datetime convertFromTimeT (bsl::time_t time)
 
static void convertFromTimeT (Datetime *result, bsl::time_t time)
 
static bsl::time_t convertToTimeT (const Datetime &datetime)
 
static int convertToTimeT (bsl::time_t *result, const Datetime &datetime)
 
static Datetime convertFromTimeT64 (TimeT64 time)
 
static int convertFromTimeT64 (Datetime *result, TimeT64 time)
 
static TimeT64 convertToTimeT64 (const Datetime &datetime)
 
static void convertToTimeT64 (TimeT64 *result, const Datetime &datetime)
 
static Datetime convertFromTimeInterval (const bsls::TimeInterval &timeInterval)
 
static void convertFromTimeInterval (Datetime *result, const bsls::TimeInterval &timeInterval)
 
static bsls::TimeInterval convertToTimeInterval (const Datetime &datetime)
 
static Datetime convertFromDatetimeInterval (const DatetimeInterval &datetimeInterval)
 
static void convertFromDatetimeInterval (Datetime *result, const DatetimeInterval &datetimeInterval)
 
static DatetimeInterval convertToDatetimeInterval (const Datetime &datetime)
 
static int convertToTimeInterval (bsls::TimeInterval *result, const Datetime &datetime)
 
static int convertToDatetimeInterval (DatetimeInterval *result, const Datetime &datetime)
 

Detailed Description

This struct provides a namespace for a suite of non-primitive functions providing conversions between absolute Datetime values and corresponding relative time intervals with respect to the Unix standard epoch time, returned by the epoch method. These methods are alias-safe, thread-safe, and exception-neutral. Functions are provided for returning converted values by value or through a result pointer.

Member Typedef Documentation

◆ TimeT64

TimeT64 is an alias for a 64-bit integral type representing seconds from the epoch in UTC. Note that, in contrast with bsl::time_t, this type can be used in conversions to and from Datetime values that are less than the epoch (corresponding to negative TimeT64 values).

Member Function Documentation

◆ convertFromDatetimeInterval() [1/2]

Datetime bdlt::EpochUtil::convertFromDatetimeInterval ( const DatetimeInterval datetimeInterval)
inlinestatic

Return, as a Datetime, the absolute datetime computed as the sum of the specified relative datetimeInterval and the epoch. The behavior is undefined unless the conversion result can be represented as a Datetime.

◆ convertFromDatetimeInterval() [2/2]

void bdlt::EpochUtil::convertFromDatetimeInterval ( Datetime result,
const DatetimeInterval datetimeInterval 
)
inlinestatic

Load into the specified result the absolute datetime converted to a Datetime, computed as the sum of the specified relative datetimeInterval and the epoch. The behavior is undefined unless the conversion result can be represented as a Datetime.

◆ convertFromTimeInterval() [1/2]

Datetime bdlt::EpochUtil::convertFromTimeInterval ( const bsls::TimeInterval timeInterval)
inlinestatic

Return, as a Datetime, the absolute datetime computed as the sum of the specified relative timeInterval and the epoch. The behavior is undefined unless the conversion result can be represented as a Datetime. Note that the conversion is potentially lossy as the resolution of bsls::TimeInterval is greater than that of Datetime.

◆ convertFromTimeInterval() [2/2]

void bdlt::EpochUtil::convertFromTimeInterval ( Datetime result,
const bsls::TimeInterval timeInterval 
)
inlinestatic

Load into the specified result the absolute datetime converted to a Datetime, computed as the sum of the specified relative timeInterval and the epoch. The behavior is undefined unless the conversion result can be represented as a Datetime. Note that the conversion is potentially lossy as the resolution of bsls::TimeInterval is greater than that of Datetime.

◆ convertFromTimeT() [1/2]

Datetime bdlt::EpochUtil::convertFromTimeT ( bsl::time_t  time)
inlinestatic

Return, as a Datetime, the absolute datetime computed as the sum of the specified relative time and the epoch. The behavior is undefined unless 0 <= time and, for the resultant Datetime dt, 0 == convertToTimeT(&time, dt) (i.e., time is representable as a 32-bit int). Note that the returned value will use Coordinated Universal Time (UTC) as a reference.

◆ convertFromTimeT() [2/2]

void bdlt::EpochUtil::convertFromTimeT ( Datetime result,
bsl::time_t  time 
)
inlinestatic

Load into the specified result the absolute datetime converted to a Datetime, computed as the sum of the specified relative time and the epoch. The behavior is undefined unless 0 <= time and 0 == convertToTimeT(&time, *result) (i.e., time is representable as a 32-bit int). Note that result will use Coordinated Universal Time (UTC) as a reference.

◆ convertFromTimeT64() [1/2]

int bdlt::EpochUtil::convertFromTimeT64 ( Datetime result,
TimeT64  time 
)
inlinestatic

Load into the specified result the absolute datetime converted to a Datetime, computed as the sum of the specified relative time and the epoch. Return 0 on success, and a non-zero value (with no effect on result) if time cannot be represented in the destination format. Note that result will use Coordinated Universal Time (UTC) as a reference.

◆ convertFromTimeT64() [2/2]

Datetime bdlt::EpochUtil::convertFromTimeT64 ( TimeT64  time)
inlinestatic

Return, as a Datetime, the absolute datetime computed as the sum of the specified relative time and the epoch. The behavior is undefined unless the converted time can be represented in the destination format. Note that the returned value will use Coordinated Universal Time (UTC) as a reference. Also note that if error detection is desired, the overloaded version that loads the converted time into a supplied destination object should be used.

◆ convertToDatetimeInterval() [1/2]

DatetimeInterval bdlt::EpochUtil::convertToDatetimeInterval ( const Datetime datetime)
inlinestatic

Return, as a DatetimeInterval, the relative time computed as the difference between the specified absolute datetime and the epoch.

◆ convertToDatetimeInterval() [2/2]

int bdlt::EpochUtil::convertToDatetimeInterval ( DatetimeInterval result,
const Datetime datetime 
)
inlinestatic
Deprecated:
Use convertToDatetimeInterval(datetime) instead.

If datetime - epoch() >= DatetimeInterval(), load into the specified result the relative time converted to a DatetimeInterval, computed as the difference between the specified absolute datetime and the epoch, and return 0. Otherwise, return a non-zero value (with no effect on result).

◆ convertToTimeInterval() [1/2]

int bdlt::EpochUtil::convertToTimeInterval ( bsls::TimeInterval result,
const Datetime datetime 
)
inlinestatic
Deprecated:
Use convertToTimeInterval(datetime) instead.

If datetime - epoch() >= DatetimeInterval(), load into the specified result the relative time converted to a bsls::TimeInterval, computed as the difference between the specified absolute datetime and the epoch, and return 0. Otherwise, return a non-zero value (with no effect on result).

◆ convertToTimeInterval() [2/2]

bsls::TimeInterval bdlt::EpochUtil::convertToTimeInterval ( const Datetime datetime)
inlinestatic

Return, as a bsls::TimeInterval, the relative time computed as the difference between the specified absolute datetime and the epoch.

◆ convertToTimeT() [1/2]

int bdlt::EpochUtil::convertToTimeT ( bsl::time_t *  result,
const Datetime datetime 
)
inlinestatic

Load into the specified result the relative time computed as the difference between the specified absolute datetime and the epoch. Return 0 on success, and a non-zero value (with no effect on result) if datetime - epoch() < DatetimeInterval() or datetime cannot be represented in the destination format on all supported platforms (i.e., the computed *result is not representable as a 32-bit int). Note that datetime is assumed to use Coordinated Universal Time (UTC) as a reference.

◆ convertToTimeT() [2/2]

bsl::time_t bdlt::EpochUtil::convertToTimeT ( const Datetime datetime)
inlinestatic

Return the relative time computed as the difference between the specified absolute datetime and the epoch. The behavior is undefined unless datetime - epoch() >= DatetimeInterval() and the converted datetime can be represented in the destination format on all supported platforms (i.e., the resultant value is representable as a 32-bit int). Note that datetime is assumed to use Coordinated Universal Time (UTC) as a reference. Also note that if error detection is desired, the overloaded version that loads the converted datetime into a supplied destination object should be used.

◆ convertToTimeT64() [1/2]

EpochUtil::TimeT64 bdlt::EpochUtil::convertToTimeT64 ( const Datetime datetime)
inlinestatic

Return the relative time computed as the difference between the specified absolute datetime and the epoch. Note that datetime is assumed to use Coordinated Universal Time (UTC) as a reference.

◆ convertToTimeT64() [2/2]

void bdlt::EpochUtil::convertToTimeT64 ( TimeT64 result,
const Datetime datetime 
)
inlinestatic

Load into the specified result the relative time computed as the difference between the specified absolute datetime and the epoch. Note that datetime is assumed to use Coordinated Universal Time (UTC) as a reference.

◆ epoch()

const Datetime & bdlt::EpochUtil::epoch ( )
inlinestatic

Return a reference providing non-modifiable access to the epoch time: midnight on January 1, 1970. Note that this value exists before any code is executed and will continue to exist, unchanged, until the program exits.


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