Quick Links:

bal | bbl | bdl | bsl

Public Member Functions | Static Public Member Functions | Friends

bdlt::Time Class Reference

#include <bdlt_time.h>

List of all members.

Public Member Functions

 Time ()
 Time (int hour, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 Time (const Time &original)
 ~Time ()
Timeoperator= (const Time &rhs)
Timeoperator+= (const DatetimeInterval &rhs)
Timeoperator-= (const DatetimeInterval &rhs)
int addHours (int hours)
int addMinutes (int minutes)
int addSeconds (int seconds)
int addMilliseconds (int milliseconds)
int addMicroseconds (bsls::Types::Int64 microseconds)
int addInterval (const DatetimeInterval &interval)
int addTime (int hours, int minutes=0, int seconds=0, int milliseconds=0, bsls::Types::Int64 microseconds=0)
void setHour (int hour)
int setHourIfValid (int hour)
void setMinute (int minute)
int setMinuteIfValid (int minute)
void setSecond (int second)
int setSecondIfValid (int second)
void setMillisecond (int millisecond)
int setMillisecondIfValid (int millisecond)
void setMicrosecond (int microsecond)
int setMicrosecondIfValid (int microsecond)
void setTime (int hour, int minute=0, int second=0, int millisecond=0, int microsecond=0)
int setTimeIfValid (int hour, int minute=0, int second=0, int millisecond=0, int microsecond=0)
template<class STREAM >
STREAM & bdexStreamIn (STREAM &stream, int version)
void getTime (int *hour, int *minute=0, int *second=0, int *millisecond=0, int *microsecond=0) const
int hour () const
int minute () const
int second () const
int millisecond () const
int microsecond () const
int printToBuffer (char *result, int numBytes, int fractionalSecondPrecision=6) const
template<class STREAM >
STREAM & bdexStreamOut (STREAM &stream, int version) const
bsl::ostream & print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
bsl::ostream & streamOut (bsl::ostream &stream) const
int validateAndSetTime (int hour, int minute=0, int second=0, int millisecond=0)

Static Public Member Functions

static bool isValid (int hour, int minute=0, int second=0, int millisecond=0, int microsecond=0)
static int maxSupportedBdexVersion (int versionSelector)
static int maxSupportedBdexVersion ()
static int maxSupportedVersion ()

Friends

DatetimeInterval operator- (const Time &, const Time &)
bool operator== (const Time &, const Time &)
bool operator!= (const Time &, const Time &)
bool operator< (const Time &, const Time &)
bool operator<= (const Time &, const Time &)
bool operator>= (const Time &, const Time &)
bool operator> (const Time &, const Time &)
template<class HASHALG >
void hashAppend (HASHALG &hashAlg, const Time &)

Detailed Description

This class implements a value-semantic type that represents the time of day to a resolution of one microsecond. Each object of this (almost) simply constrained attribute class always represents a valid time value to a resolution of one microsecond. The valid range for times is 00:00:00.000000 through 23:59:59.999999, except that 24:00:00.000000 represents the default-constructed value. The value 24:00:00.000000 behaves, in most cases, as if it were the value 00:00:00.000000; however, for all relational comparison operators, 24:00:00.000000 is not a valid argument and, therefore, would result in undefined behavior. Each add operation on a Time object returns the (signed) number of times that the 23:59:59.999999 - 00:00:00.000000 boundary was crossed while performing the operation. Attempting to construct a Time with any attribute outside its valid range (or with an hour attribute value of 24 and any other attribute non-zero) has undefined behavior.

See Component bdlt_time


Constructor & Destructor Documentation

bdlt::Time::Time (  ) 

Create a Time object having the value 24:00:00.000000.

bdlt::Time::Time ( int  hour,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
) [explicit]

Create a Time object having the (valid) value represented by the specified hour, and the optionally specified minute, second, millisecond, and microsecond. Unspecified arguments default to 0. The behavior is undefined unless all of the specified values are within their valid ranges (see isValid).

bdlt::Time::Time ( const Time original  ) 

Create a Time object having the value of the specified original time.

bdlt::Time::~Time (  ) 

Destroy this Time object.


Member Function Documentation

static bool bdlt::Time::isValid ( int  hour,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
) [static]

Return true if the specified hour, and the optionally specified minute, second, millisecond, and microsecond, represent a valid Time value, and false otherwise. Unspecified arguments default to 0. The hour, minute, second, millisecond, and microsecond attributes comprise a valid Time value if 0 <= hour < 24, 0 <= minute < 60, 0 <= second < 60, 0 <= millisecond < 1000, and 0 <= microsecond < 1000. Additionally, 24:00:00.000000 also represents a valid Time value.

static int bdlt::Time::maxSupportedBdexVersion ( int  versionSelector  )  [static]

Return the maximum valid BDEX format version, as indicated by the specified versionSelector, to be passed to the bdexStreamOut method. Note that it is highly recommended that versionSelector be formatted as "YYYYMMDD", a date representation. Also note that versionSelector should be a compile-time-chosen value that selects a format version supported by both externalizer and unexternalizer. See the bslx package-level documentation for more information on BDEX streaming of value-semantic types and containers.

Time& bdlt::Time::operator= ( const Time rhs  ) 

Assign to this time object the value of the specified rhs object, and return a reference providing modifiable access to this object.

Time& bdlt::Time::operator+= ( const DatetimeInterval rhs  ) 

Add to this time object the value of the specified rhs datetime interval, and return a reference providing modifiable access to this object.

Time& bdlt::Time::operator-= ( const DatetimeInterval rhs  ) 

Subtract from this time object the value of the specified rhs datetime interval, and return a reference providing modifiable access to this object.

int bdlt::Time::addHours ( int  hours  ) 

Increase the value of this time object by the specified number of hours, and return the (signed) number of times that the 23:59:59.999999 - 00:00:00.000000 boundary was crossed in performing the operation. Note that hours may be negative.

int bdlt::Time::addMinutes ( int  minutes  ) 

Increase the value of this time object by the specified number of minutes, and return the (signed) number of times that the 23:59:59.999999 - 00:00:00.000000 boundary was crossed in performing the operation. Note that minutes may be negative.

int bdlt::Time::addSeconds ( int  seconds  ) 

Increase the value of this time object by the specified number of seconds, and return the (signed) number of times that the 23:59:59.999999 - 00:00:00.000000 boundary was crossed in performing the operation. Note that seconds may be negative.

int bdlt::Time::addMilliseconds ( int  milliseconds  ) 

Increase the value of this time object by the specified number of milliseconds, and return the (signed) number of times that the 23:59:59.999999 - 00:00:00.000000 boundary was crossed in performing the operation. Note that milliseconds may be negative.

int bdlt::Time::addMicroseconds ( bsls::Types::Int64  microseconds  ) 

Increase the value of this time object by the specified number of microseconds, and return the (signed) number of times that the 23:59:59.999999 - 00:00:00.000000 boundary was crossed in performing the operation. Note that microseconds may be negative.

int bdlt::Time::addInterval ( const DatetimeInterval interval  ) 

Increase the value of this time object by the specified interval of time, and return the (signed) number of times that the 23:59:59.999999 - 00:00:00.000000 boundary was crossed in performing the operation. The behavior is undefined unless the number of crossings that would be returned can be represented by an int.

int bdlt::Time::addTime ( int  hours,
int  minutes = 0,
int  seconds = 0,
int  milliseconds = 0,
bsls::Types::Int64  microseconds = 0 
)

Add to the value of this time object the specified (signed) number of hours, and the optionally specified (signed) numbers of minutes, seconds, milliseconds, and microseconds; return the (signed) number of times that the 23:59:59.999999 - 00:00:00.000000 boundary was crossed in performing the operation. Unspecified arguments default to 0.

void bdlt::Time::setHour ( int  hour  ) 

Set the "hour" attribute of this time object to the specified hour; if hour is 24, set the remaining attributes of this object to 0. The behavior is undefined unless 0 <= hour <= 24.

int bdlt::Time::setHourIfValid ( int  hour  ) 

Set the "hour" attribute of this time object to the specified hour value if 0 <= hour <= 24. If 24 == hour, set the remaining attributes to 0. Return 0 on success, and a non-zero value (with no effect) otherwise.

void bdlt::Time::setMinute ( int  minute  ) 

Set the "minute" attribute of this time object to the specified minute; if the hour attribute is 24, set the hour attribute to 0. The behavior is undefined unless 0 <= minute < 60.

int bdlt::Time::setMinuteIfValid ( int  minute  ) 

Set the "minute" attribute of this time object to the specified minute if 0 <= minute < 60; if the hour attribute is 24, set the hour attribute to 0. Return 0 on success, and a non-zero value (with no effect) otherwise.

void bdlt::Time::setSecond ( int  second  ) 

Set the "second" attribute of this time object to the specified second; if the hour attribute is 24, set the hour attribute to 0. The behavior is undefined unless 0 <= second < 60.

int bdlt::Time::setSecondIfValid ( int  second  ) 

Set the "second" attribute of this time object to the specified second if 0 <= second < 60; if the hour attribute is 24, set the hour attribute to 0. Return 0 on success, and a non-zero value (with no effect) otherwise.

void bdlt::Time::setMillisecond ( int  millisecond  ) 

Set the "millisecond" attribute of this time object to the specified millisecond; if the hour attribute is 24, set the hour attribute to 0. The behavior is undefined unless 0 <= millisecond < 1000.

int bdlt::Time::setMillisecondIfValid ( int  millisecond  ) 

Set the "millisecond" attribute of this time object to the specified millisecond if 0 <= millisecond < 1000; if the hour attribute is 24, set the hour attribute to 0. Return 0 on success, and a non-zero value (with no effect) otherwise.

void bdlt::Time::setMicrosecond ( int  microsecond  ) 

Set the "microsecond" attribute of this time object to the specified microsecond; if the hour attribute is 24, set the hour attribute to 0. The behavior is undefined unless 0 <= microsecond < 1000.

int bdlt::Time::setMicrosecondIfValid ( int  microsecond  ) 

Set the "microsecond" attribute of this time object to the specified microsecond if 0 <= microsecond < 1000; if the hour attribute is 24, set the hour attribute to 0. Return 0 on success, and a non-zero value (with no effect) otherwise.

void bdlt::Time::setTime ( int  hour,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
)

Set the value of this time object to the specified hour, and the optionally specified minute, second, millisecond, and microsecond. Unspecified arguments default to 0. The behavior is undefined unless all of the specified values are within their valid ranges (see isValid).

int bdlt::Time::setTimeIfValid ( int  hour,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
)

Set the value of this time object to the specified hour, and the optionally specified minute, second, millisecond, and microsecond, if they would comprise a valid Time value (see isValid). Return 0 on success, and a non-zero value (with no effect) otherwise. Unspecified arguments default to 0.

template<class STREAM >
STREAM& bdlt::Time::bdexStreamIn ( STREAM &  stream,
int  version 
)

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.

void bdlt::Time::getTime ( int *  hour,
int *  minute = 0,
int *  second = 0,
int *  millisecond = 0,
int *  microsecond = 0 
) const

Load, into the specified hour, and the optionally specified minute, second, millisecond, and microsecond, the respective hour, minute, second, millisecond, and microsecond attribute values from this time object. Unspecified arguments default to 0. Supplying 0 for an address argument suppresses the loading of the value for the corresponding attribute, but has no effect on the loading of other attribute values.

int bdlt::Time::hour (  )  const

Return the value of the hour attribute of this time object.

int bdlt::Time::minute (  )  const

Return the value of the minute attribute of this time object.

int bdlt::Time::second (  )  const

Return the value of the second attribute of this time object.

int bdlt::Time::millisecond (  )  const

Return the value of the millisecond attribute of this time object.

int bdlt::Time::microsecond (  )  const

Return the value of the microsecond attribute of this time object.

int bdlt::Time::printToBuffer ( char *  result,
int  numBytes,
int  fractionalSecondPrecision = 6 
) const

Efficiently write to the specified result buffer no more than the specified numBytes of a representation of the value of this object. Optionally specify fractionalSecondPrecision digits to indicate how many fractional second digits to output. If fractionalSecondPrecision is not specified then 6 fractional second digits will be output (3 digits for milliseconds and 3 digits for microseconds). Return the number of characters (not including the null character) that would have been written if the limit due to numBytes were not imposed. result is null-terminated unless numBytes is 0. The behavior is undefined unless 0 <= numBytes, 0 <= fractionalSecondPrecision <= 6, and result refers to at least numBytes contiguous bytes. Note that the return value is greater than or equal to numBytes if the output representation was truncated to avoid result overrun.

template<class STREAM >
STREAM& bdlt::Time::bdexStreamOut ( STREAM &  stream,
int  version 
) const

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.

bsl::ostream& bdlt::Time::print ( bsl::ostream &  stream,
int  level = 0,
int  spacesPerLevel = 4 
) const

Write the value of this object to the specified output stream in a human-readable format, and return a reference 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 this human-readable format is not fully specified, and can change without notice.

static int bdlt::Time::maxSupportedBdexVersion (  )  [static]

DEPRECATED: Use maxSupportedBdexVersion(int) instead.

Return the most current BDEX streaming version number supported by this class.

static int bdlt::Time::maxSupportedVersion (  )  [static]

DEPRECATED: Use maxSupportedBdexVersion(int) instead.

Return the most current BDEX streaming version number supported by this class.

bsl::ostream& bdlt::Time::streamOut ( bsl::ostream &  stream  )  const

DEPRECATED: Use print instead.

Format this time to the specified output stream, and return a reference to the modifiable stream.

int bdlt::Time::validateAndSetTime ( int  hour,
int  minute = 0,
int  second = 0,
int  millisecond = 0 
)

DEPRECATED: Use setTimeIfValid instead.

Set the value of this time object to the specified hour, and the optionally specified minute, second, and millisecond, if they would comprise a valid Time value (see isValid). Return 0 on success, and a non-zero value (with no effect) otherwise. Unspecified arguments default to 0.


Friends And Related Function Documentation

DatetimeInterval operator- ( const Time ,
const Time  
) [friend]

Return a DatetimeInterval object initialized with the difference between the specified lhs and rhs time values.

bool operator== ( const Time ,
const Time  
) [friend]

Return true if the specified lhs and rhs time objects have the same value, and false otherwise. Two time objects have the same value if each of their corresponding hour, minute, second, millisecond, and microsecond attributes respectively have the same value.

bool operator!= ( const Time ,
const Time  
) [friend]

Return true if the specified lhs and rhs time objects do not have the same value, and false otherwise. Two time objects do not have the same value if any of their corresponding hour, minute, second, millisecond, and microsecond attributes respectively do not have the same value.

bool operator< ( const Time ,
const Time  
) [friend]

Return true if the specified lhs time value is less than the specified rhs time value, and false otherwise. The behavior is undefined unless lhs != Time() and rhs != Time() (i.e., they do not have the, default, value 24:00:00.000000).

bool operator<= ( const Time ,
const Time  
) [friend]

Return true if the specified lhs time value is less than or equal to the specified rhs time value, and false otherwise. The behavior is undefined unless lhs != Time() and rhs != Time() (i.e., they do not have the, default, value 24:00:00.000000).

bool operator>= ( const Time ,
const Time  
) [friend]

Return true if the specified lhs time value is greater than or equal to the specified rhs time value, and false otherwise. The behavior is undefined unless lhs != Time() and rhs != Time() (i.e., they do not have the, default, value 24:00:00.000000).

bool operator> ( const Time ,
const Time  
) [friend]

Return true if the specified lhs time value is greater than the specified rhs time value, and false otherwise. The behavior is undefined unless lhs != Time() and rhs != Time() (i.e., they do not have the, default, value 24:00:00.000000).

template<class HASHALG >
void hashAppend ( HASHALG &  hashAlg,
const Time  
) [friend]

Pass the specified object to the specified hashAlg. This function integrates with the bslh modular hashing system and effectively provides a bsl::hash specialization for Time.


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