BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlt::Datetime Class Reference

#include <bdlt_datetime.h>

Public Member Functions

 Datetime ()
 
 Datetime (const Date &date)
 
 Datetime (const Date &date, const Time &time)
 
 Datetime (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 
 Datetime (const Datetime &original)
 
 ~Datetime ()=default
 
Datetimeoperator= (const Datetime &rhs)
 
Datetimeoperator+= (const bsls::TimeInterval &rhs)
 
Datetimeoperator-= (const bsls::TimeInterval &rhs)
 
Datetimeoperator+= (const DatetimeInterval &rhs)
 
Datetimeoperator-= (const DatetimeInterval &rhs)
 
void setDatetime (const Date &date, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 
void setDatetime (const Date &date, const Time &time)
 
void setDatetime (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 
int setDatetimeIfValid (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 
int setDatetimeIfValid (const Date &date, int hour=0, int minute=0, int second=0, int millisecond=0, int microsecond=0)
 
void setDate (const Date &date)
 
void setYearDay (int year, int dayOfYear)
 
int setYearDayIfValid (int year, int dayOfYear)
 
void setYearMonthDay (int year, int month, int day)
 
int setYearMonthDayIfValid (int year, int month, int day)
 
void setTime (const Time &time)
 
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)
 
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)
 
DatetimeaddDays (int days)
 
int addDaysIfValid (int days)
 
DatetimeaddTime (bsls::Types::Int64 hours, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
 
int addTimeIfValid (bsls::Types::Int64 hours, bsls::Types::Int64 minutes=0, bsls::Types::Int64 seconds=0, bsls::Types::Int64 milliseconds=0, bsls::Types::Int64 microseconds=0)
 
DatetimeaddHours (bsls::Types::Int64 hours)
 
int addHoursIfValid (bsls::Types::Int64 hours)
 
DatetimeaddMinutes (bsls::Types::Int64 minutes)
 
int addMinutesIfValid (bsls::Types::Int64 minutes)
 
DatetimeaddSeconds (bsls::Types::Int64 seconds)
 
int addSecondsIfValid (bsls::Types::Int64 seconds)
 
DatetimeaddMilliseconds (bsls::Types::Int64 milliseconds)
 
int addMillisecondsIfValid (bsls::Types::Int64 milliseconds)
 
DatetimeaddMicroseconds (bsls::Types::Int64 microseconds)
 
int addMicrosecondsIfValid (bsls::Types::Int64 microseconds)
 
template<class STREAM >
STREAM & bdexStreamIn (STREAM &stream, int version)
 
Date date () const
 Return the value of the "date" part of this object.
 
int day () const
 
DayOfWeek::Enum dayOfWeek () const
 
int dayOfYear () const
 Return the value of the dayOfYear attribute of this object.
 
void getTime (int *hour, int *minute=0, int *second=0, int *millisecond=0, int *microsecond=0) const
 
int hour () const
 Return the value of the hour attribute of this object.
 
int microsecond () const
 Return the value of the microsecond attribute of this object.
 
int millisecond () const
 Return the value of the millisecond attribute of this object.
 
int minute () const
 Return the value of the minute attribute of this object.
 
int month () const
 Return the value of the month attribute of this object.
 
int second () const
 Return the value of the second attribute of this object.
 
Time time () const
 Return the value of the "time" part of this object.
 
int year () const
 Return the value of the year attribute of this object.
 
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 validateAndSetDatetime (int year, int month, int day, int hour=0, int minute=0, int second=0, int millisecond=0)
 

Static Public Member Functions

static bool isValid (int year, int month, int day, int hour=0, 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 Datetime &, const Datetime &)
 
bool operator== (const Datetime &, const Datetime &)
 
bool operator!= (const Datetime &, const Datetime &)
 
bool operator< (const Datetime &, const Datetime &)
 
bool operator<= (const Datetime &, const Datetime &)
 
bool operator> (const Datetime &, const Datetime &)
 
bool operator>= (const Datetime &, const Datetime &)
 
template<class HASHALG >
void hashAppend (HASHALG &hashAlg, const Datetime &)
 

Detailed Description

This class implements a simply-constrained value-semantic type representing the composition of date and time values. Valid date values for the "date" part of a Datetime object are the same as those defined for Date objects; similarly, valid time values for the "time" part of a Datetime object are similar to those defined for Time objects (but with additional precision). Relational operators are disallowed on Datetime objects whose "time" part has the same value as that of a default constructed Time object.

See bdlt_datetime

Constructor & Destructor Documentation

◆ Datetime() [1/5]

bdlt::Datetime::Datetime ( )
inline

Create a Datetime object whose "date" and "time" parts have their respective default-constructed values, "0001/01/01" and "24:00:00.000000".

◆ Datetime() [2/5]

bdlt::Datetime::Datetime ( const Date date)
inline

Create a Datetime object whose "date" part has the value of the specified date and whose "time" part has the value "00:00:00.000000".

◆ Datetime() [3/5]

bdlt::Datetime::Datetime ( const Date date,
const Time time 
)
inline

Create a Datetime object whose "date" and "time" parts have the values of the specified date and time, respectively.

◆ Datetime() [4/5]

bdlt::Datetime::Datetime ( int  year,
int  month,
int  day,
int  hour = 0,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
)
inline

Create a Datetime object whose "date" part has the value represented by the specified year, month, and day attributes, and whose "time" part has the value represented by the optionally specified hour, minute, second, millisecond, and microsecond attributes. Unspecified trailing optional parameters default to 0. The behavior is undefined unless the eight attributes (collectively) represent a valid Datetime value (see isValid).

◆ Datetime() [5/5]

bdlt::Datetime::Datetime ( const Datetime original)
inline

Create a Datetime object having the value of the specified original object.

◆ ~Datetime()

bdlt::Datetime::~Datetime ( )
default

Member Function Documentation

◆ addDays()

Datetime & bdlt::Datetime::addDays ( int  days)
inline

Add the specified number of days to the value of this object. Return a reference providing modifiable access to this object. The behavior is undefined unless the resulting value is in the valid range for a Datetime object. Note that this method has no effect on the "time" part of this object. Also note that days may be positive, 0, or negative.

◆ addDaysIfValid()

int bdlt::Datetime::addDaysIfValid ( int  days)
inline

Add the specified number of days to the value of this object, if the resulting value is in the valid range for a Datetime object. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that this method has no effect on the "time" part of this object. Also note that days may be positive, 0, or negative.

◆ addHours()

Datetime & bdlt::Datetime::addHours ( bsls::Types::Int64  hours)
inline

Add the specified number of hours to the value of this object, adjusting the "date" part of the object accordingly. Return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. The behavior is undefined unless the resulting value is in the valid range for a Datetime object. Note that hours may be positive, negative, or 0.

◆ addHoursIfValid()

int bdlt::Datetime::addHoursIfValid ( bsls::Types::Int64  hours)
inline

Add the specified number of hours to the value of this object, adjusting the "date" part of the object accordingly, if the resulting value is in the valid range for a Datetime object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that hours may be positive, negative, or 0.

◆ addMicroseconds()

Datetime & bdlt::Datetime::addMicroseconds ( bsls::Types::Int64  microseconds)
inline

Add the specified number of microseconds to the value of this object, adjusting the "date" part of the object accordingly. Return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. The behavior is undefined unless the resulting value is in the valid range for a Datetime object. Note that microseconds may be positive, negative, or 0.

◆ addMicrosecondsIfValid()

int bdlt::Datetime::addMicrosecondsIfValid ( bsls::Types::Int64  microseconds)
inline

Add the specified number of microseconds to the value of this object, adjusting the "date" part of the object accordingly, if the resulting value is in the valid range for a Datetime object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that microseconds may be positive, negative, or 0.

◆ addMilliseconds()

Datetime & bdlt::Datetime::addMilliseconds ( bsls::Types::Int64  milliseconds)
inline

Add the specified number of milliseconds to the value of this object, adjusting the "date" part of the object accordingly. Return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. The behavior is undefined unless the resulting value is in the valid range for a Datetime object. Note that milliseconds may be positive, negative, or 0.

◆ addMillisecondsIfValid()

int bdlt::Datetime::addMillisecondsIfValid ( bsls::Types::Int64  milliseconds)
inline

Add the specified number of milliseconds to the value of this object, adjusting the "date" part of the object accordingly, if the resulting value is in the valid range for a Datetime object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that milliseconds may be positive, negative, or 0.

◆ addMinutes()

Datetime & bdlt::Datetime::addMinutes ( bsls::Types::Int64  minutes)
inline

Add the specified number of minutes to the value of this object, adjusting the "date" part of the object accordingly. Return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. The behavior is undefined unless the resulting value is in the valid range for a Datetime object. Note that minutes may be positive, negative, or 0.

◆ addMinutesIfValid()

int bdlt::Datetime::addMinutesIfValid ( bsls::Types::Int64  minutes)
inline

Add the specified number of minutes to the value of this object, adjusting the "date" part of the object accordingly, if the resulting value is in the valid range for a Datetime object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that minutes may be positive, negative, or 0.

◆ addSeconds()

Datetime & bdlt::Datetime::addSeconds ( bsls::Types::Int64  seconds)
inline

Add the specified number of seconds to the value of this object, adjusting the "date" part of the object accordingly. Return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. The behavior is undefined unless the resulting value is in the valid range for a Datetime object. Note that seconds may be positive, negative, or 0.

◆ addSecondsIfValid()

int bdlt::Datetime::addSecondsIfValid ( bsls::Types::Int64  seconds)
inline

Add the specified number of seconds to the value of this object, adjusting the "date" part of the object accordingly, if the resulting value is in the valid range for a Datetime object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that seconds may be positive, negative, or 0.

◆ addTime()

Datetime & bdlt::Datetime::addTime ( bsls::Types::Int64  hours,
bsls::Types::Int64  minutes = 0,
bsls::Types::Int64  seconds = 0,
bsls::Types::Int64  milliseconds = 0,
bsls::Types::Int64  microseconds = 0 
)
inline

Add the specified number of hours, and the optionally specified number of minutes, seconds, milliseconds, and microseconds to the value of this object, adjusting the "date" part of this object accordingly. Unspecified trailing optional parameters default to 0. Return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. The behavior is undefined unless the resulting value is in the valid range for a Datetime object. Note that each argument independently may be positive, negative, or 0.

◆ addTimeIfValid()

int bdlt::Datetime::addTimeIfValid ( bsls::Types::Int64  hours,
bsls::Types::Int64  minutes = 0,
bsls::Types::Int64  seconds = 0,
bsls::Types::Int64  milliseconds = 0,
bsls::Types::Int64  microseconds = 0 
)
inline

Add the specified number of hours, and the optionally specified number of minutes, seconds, milliseconds, and microseconds to the value of this object, adjusting the "date" part of this object accordingly, if the resulting value is in the valid range for a Datetime object. Unspecified trailing optional parameters default to 0. If 24 == hour() on entry, set the hour attribute to 0 before performing the addition. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that each argument independently may be positive, negative, or 0.

◆ bdexStreamIn()

template<class STREAM >
STREAM & bdlt::Datetime::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.

◆ bdexStreamOut()

template<class STREAM >
STREAM & bdlt::Datetime::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.

◆ date()

Date bdlt::Datetime::date ( ) const
inline

◆ day()

int bdlt::Datetime::day ( ) const
inline

Return the value of the day (of the month) attribute of this object.

◆ dayOfWeek()

DayOfWeek::Enum bdlt::Datetime::dayOfWeek ( ) const
inline

Return the value of the dayOfWeek attribute associated with the day (of the month) attribute of this object.

◆ dayOfYear()

int bdlt::Datetime::dayOfYear ( ) const
inline

◆ getTime()

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

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.

◆ hour()

int bdlt::Datetime::hour ( ) const
inline

◆ isValid()

bool bdlt::Datetime::isValid ( int  year,
int  month,
int  day,
int  hour = 0,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
)
inlinestatic

Return true if the specified year, month, and day attribute values, and the optionally specified hour, minute, second, millisecond, and microsecond attribute values, represent a valid Datetime value, and false otherwise. Unspecified trailing optional parameters default to 0. year, month, day, hour, minute, second, millisecond, and microsecond attribute values represent a valid Datetime value if true == Date::isValidYearMonthDay(year, month, day), 0 <= hour < 24, 0 <= minute < 60, 0 <= second < 60, 0 <= millisecond < 1000, and 0 <= microsecond < 1000. Additionally, a valid year, month, day with the time portion equal to 24:00:00.000000 also represents a valid Datetime value.

◆ maxSupportedBdexVersion() [1/2]

int bdlt::Datetime::maxSupportedBdexVersion ( )
inlinestatic
Deprecated:
Use maxSupportedBdexVersion(int) instead.

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

◆ maxSupportedBdexVersion() [2/2]

int bdlt::Datetime::maxSupportedBdexVersion ( int  versionSelector)
inlinestatic

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.

◆ maxSupportedVersion()

int bdlt::Datetime::maxSupportedVersion ( )
inlinestatic
Deprecated:
Use maxSupportedBdexVersion(int) instead.

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

◆ microsecond()

int bdlt::Datetime::microsecond ( ) const
inline

◆ millisecond()

int bdlt::Datetime::millisecond ( ) const
inline

◆ minute()

int bdlt::Datetime::minute ( ) const
inline

◆ month()

int bdlt::Datetime::month ( ) const
inline

◆ operator+=() [1/2]

Datetime & bdlt::Datetime::operator+= ( const bsls::TimeInterval rhs)
inline

Add to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute of this object to 0 before performing the addition. The behavior is undefined unless the resulting value is valid for Datetime (see isValid).

◆ operator+=() [2/2]

Datetime & bdlt::Datetime::operator+= ( const DatetimeInterval rhs)
inline

Add to this object the value of the specified rhs object, and return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute of this object to 0 before performing the addition. The behavior is undefined unless the resulting value is valid for Datetime (see isValid).

◆ operator-=() [1/2]

Datetime & bdlt::Datetime::operator-= ( const bsls::TimeInterval rhs)
inline

Subtract from this object the value of the specified rhs object, and return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute of this object to 0 before performing the subtraction. The behavior is undefined unless the resulting value is valid for Datetime (see isValid).

◆ operator-=() [2/2]

Datetime & bdlt::Datetime::operator-= ( const DatetimeInterval rhs)
inline

Subtract from this object the value of the specified rhs object, and return a reference providing modifiable access to this object. If 24 == hour() on entry, set the hour attribute of this object to 0 before performing the subtraction. The behavior is undefined unless the resulting value is valid for Datetime (see isValid).

◆ operator=()

Datetime & bdlt::Datetime::operator= ( const Datetime rhs)
inline

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

◆ print()

bsl::ostream & bdlt::Datetime::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.

◆ printToBuffer()

int bdlt::Datetime::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.

◆ second()

int bdlt::Datetime::second ( ) const
inline

◆ setDate()

void bdlt::Datetime::setDate ( const Date date)
inline

Set the "date" part of this object to have the value of the specified date. Note that this method has no effect on the "time" part of this object.

◆ setDatetime() [1/3]

void bdlt::Datetime::setDatetime ( const Date date,
const Time time 
)
inline

Set the value of this object to a Datetime whose "date" part has the value represented by the specified date, and whose "time" part has the value represented by the specified time.

◆ setDatetime() [2/3]

void bdlt::Datetime::setDatetime ( const Date date,
int  hour = 0,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
)
inline

Set the value of this object to a Datetime whose "date" part has the value represented by the specified date, and whose "time" part has the value represented by the optionally specified hour, minute, second, millisecond, and microsecond attributes. Unspecified trailing optional parameters default to 0. The behavior is undefined unless the attributes (collectively) represent a valid Datetime value (see isValid).

◆ setDatetime() [3/3]

void bdlt::Datetime::setDatetime ( int  year,
int  month,
int  day,
int  hour = 0,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
)
inline

Set the value of this object to a Datetime whose "date" part has the value represented by the specified year, month, and day attributes, and whose "time" part has the value represented by the optionally specified hour, minute, second, millisecond, and microsecond attributes. Unspecified trailing optional parameters default to 0. The behavior is undefined unless the eight attributes (collectively) represent a valid Datetime value (see isValid).

◆ setDatetimeIfValid() [1/2]

int bdlt::Datetime::setDatetimeIfValid ( const Date date,
int  hour = 0,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
)
inline

Set the value of this object to a Datetime whose "date" part has the value represented by the specified date, and whose "time" part has the value represented by the optionally specified hour, minute, second, millisecond, and microsecond attributes, if the attribute values (collectively) represent a valid Datetime value (see isValid). Unspecified trailing optional parameters default to 0. Return 0 on success, and a non-zero value (with no effect) otherwise.

◆ setDatetimeIfValid() [2/2]

int bdlt::Datetime::setDatetimeIfValid ( int  year,
int  month,
int  day,
int  hour = 0,
int  minute = 0,
int  second = 0,
int  millisecond = 0,
int  microsecond = 0 
)
inline

Set the "date" part of this object to have the value represented by the specified year, month, and day attributes, and set the "time" part to have the value represented by the optionally specified hour, minute, second, millisecond, and microsecond attributes, if the eight attribute values (collectively) represent a valid Datetime value (see isValid). Unspecified trailing optional parameters default to 0. Return 0 on success, and a non-zero value (with no effect) otherwise.

◆ setHour()

void bdlt::Datetime::setHour ( int  hour)
inline

Set the "hour" attribute of this object to the specified hour value. If 24 == hour, set the minute, second, millisecond, and microsecond attributes to 0. The behavior is undefined unless 0 <= hour <= 24. Note that this method has no effect on the "date" part of this object.

◆ setHourIfValid()

int bdlt::Datetime::setHourIfValid ( int  hour)
inline

Set the "hour" attribute of this object to the specified hour value if 0 <= hour <= 24. If 24 == hour, set the minute, second, millisecond, and microsecond attributes to 0. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that this method has no effect on the "date" part of this object.

◆ setMicrosecond()

void bdlt::Datetime::setMicrosecond ( int  microsecond)
inline

Set the "microsecond" attribute of this object to the specified microsecond value. If 24 == hour(), set the hour attribute to 0. The behavior is undefined unless 0 <= microsecond <= 999. Note that this method has no effect on the "date" part of this object.

◆ setMicrosecondIfValid()

int bdlt::Datetime::setMicrosecondIfValid ( int  microsecond)
inline

Set the "microsecond" attribute of this object to the specified microsecond value if 0 <= microsecond <= 999. If 24 == hour(), set the hour attribute to 0. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that this method has no effect on the "date" part of this object.

◆ setMillisecond()

void bdlt::Datetime::setMillisecond ( int  millisecond)
inline

Set the "millisecond" attribute of this object to the specified millisecond value. If 24 == hour(), set the hour attribute to 0. The behavior is undefined unless 0 <= millisecond <= 999. Note that this method has no effect on the "date" part of this object.

◆ setMillisecondIfValid()

int bdlt::Datetime::setMillisecondIfValid ( int  millisecond)
inline

Set the "millisecond" attribute of this object to the specified millisecond value if 0 <= millisecond <= 999. If 24 == hour(), set the hour attribute to 0. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that this method has no effect on the "date" part of this object.

◆ setMinute()

void bdlt::Datetime::setMinute ( int  minute)
inline

Set the "minute" attribute of this object to the specified minute value. If 24 == hour(), set the hour attribute to 0. The behavior is undefined unless 0 <= minute <= 59. Note that this method has no effect on the "date" part of this object.

◆ setMinuteIfValid()

int bdlt::Datetime::setMinuteIfValid ( int  minute)
inline

Set the "minute" attribute of this object to the specified minute value if 0 <= minute <= 59. If 24 == hour(), set the hour attribute to 0. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that this method has no effect on the "date" part of this object.

◆ setSecond()

void bdlt::Datetime::setSecond ( int  second)
inline

Set the "second" attribute of this object to the specified second value. If 24 == hour(), set the hour attribute to 0. The behavior is undefined unless 0 <= second <= 59. Note that this method has no effect on the "date" part of this object.

◆ setSecondIfValid()

int bdlt::Datetime::setSecondIfValid ( int  second)
inline

Set the "second" attribute of this object to the specified second value if 0 <= second <= 59. If 24 == hour(), set the hour attribute to 0. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that this method has no effect on the "date" part of this object.

◆ setTime() [1/2]

void bdlt::Datetime::setTime ( const Time time)
inline

Set the "time" part of this object to have the value of the specified time. Note that this method has no effect on the "date" part of this object.

◆ setTime() [2/2]

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

Set the "time" part of this object to have the value represented by the specified hour attribute value and the optionally specified minute, second, millisecond, and microsecond attribute values. Unspecified trailing optional parameters default to 0. The behavior is undefined unless hour, minute, second, millisecond, and microsecond represent a valid "time" portion of a Datetime value. Note that this method has no effect on the "date" part of this object.

◆ setTimeIfValid()

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

Set the "time" part of this object to have the value represented by the specified hour attribute value and the optionally specified minute, second, millisecond, and microsecond attribute values if they comprise a valid "time" portion of a DateTime value. Unspecified trailing optional parameters default to 0. Return 0 on success, and a non-zero value (with no effect) otherwise. Note that this method has no effect on the "date" part of this object.

◆ setYearDay()

void bdlt::Datetime::setYearDay ( int  year,
int  dayOfYear 
)
inline

Set the "date" part of this object to have the value represented by the specified year and dayOfYear attribute values. The behavior is undefined unless year and dayOfYear represent a valid Date value (i.e., true == Date::isValidYearDay(year, dayOfYear)). Note that this method has no effect on the "time" part of this object.

◆ setYearDayIfValid()

int bdlt::Datetime::setYearDayIfValid ( int  year,
int  dayOfYear 
)
inline

Set this object to have the value represented by the specified year and dayOfYear if they comprise a valid Date value (see Date::isValidYearDay). Return 0 on success, and a non-zero value (with no effect) otherwise.

◆ setYearMonthDay()

void bdlt::Datetime::setYearMonthDay ( int  year,
int  month,
int  day 
)
inline

Set the "date" part of this object to have the value represented by the specified year, month, and day attribute values. The behavior is undefined unless year, month, and day represent a valid Date value (i.e., true == Date::isValidYearMonthDay(year, month, day)). Note that this method has no effect on the "time" part of this object.

◆ setYearMonthDayIfValid()

int bdlt::Datetime::setYearMonthDayIfValid ( int  year,
int  month,
int  day 
)
inline

Set this object to have the value represented by the specified year, month, and day if they comprise a valid Date value (see Date::isValidYearMonthDay). Return 0 on success, and a non-zero value (with no effect) otherwise.

◆ streamOut()

bsl::ostream & bdlt::Datetime::streamOut ( bsl::ostream &  stream) const
inline
Deprecated:
Use print instead.

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

◆ time()

Time bdlt::Datetime::time ( ) const
inline

◆ validateAndSetDatetime()

int bdlt::Datetime::validateAndSetDatetime ( int  year,
int  month,
int  day,
int  hour = 0,
int  minute = 0,
int  second = 0,
int  millisecond = 0 
)
inline
Deprecated:
Use setDatetimeIfValid instead.

Set the "date" part of this object's value to the specified year, month, and day, and the "time" part to the optionally specified hour, minute, second, and millisecond, if they represent a valid Datetime value, with trailing fields that are not specified set to 0. Return 0 on success, and a non-zero value (with no effect) otherwise.

◆ year()

int bdlt::Datetime::year ( ) const
inline

Friends And Related Symbol Documentation

◆ hashAppend

template<class HASHALG >
void hashAppend ( HASHALG &  hashAlg,
const Datetime  
)
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 Datetime.

◆ operator!=

bool operator!= ( const Datetime ,
const Datetime  
)
friend

Return true if the specified lhs and rhs Datetime objects do not have the same value, and false otherwise. Two Datetime objects do not have the same value if they do not have the same values for either of their "date" or "time" parts, respectively.

◆ operator-

DatetimeInterval operator- ( const Datetime ,
const Datetime  
)
friend

Return a DatetimeInterval object having a value that is the difference between the specified lhs (Datetime) and the specified rhs (Datetime). If the hour attribute of either operand is 24, the result is the same as if that hour attribute is 0. The behavior is undefined unless the resulting value is in the valid range for a DatetimeInterval object.

◆ operator<

bool operator< ( const Datetime ,
const Datetime  
)
friend

Return true if the value of the specified lhs object is less than the value of the specified rhs object, and false otherwise. A Datetime object a is less than a Datetime object b if a.date() < b.date(), or if a.date() == b.date() and the time portion of a is less than the time portion of b. The behavior is undefined unless 24 != lhs.hour() && 24 != rhs.hour().

◆ operator<=

bool operator<= ( const Datetime ,
const Datetime  
)
friend

Return true if the value of the specified lhs object is less than or equal to the value of the specified rhs object, and false otherwise. The behavior is undefined unless 24 != lhs.hour() && 24 != rhs.hour().

◆ operator==

bool operator== ( const Datetime ,
const Datetime  
)
friend

Return true if the specified lhs and rhs objects have the same value, and false otherwise. Two Datetime objects have the same value if they have the same values for their "date" and "time" parts, respectively.

◆ operator>

bool operator> ( const Datetime ,
const Datetime  
)
friend

Return true if the value of the specified lhs object is greater than the value of the specified rhs object, and false otherwise. A Datetime object a is greater than a Datetime object b if a.date() > b.date(), or if a.date() == b.date() and the time portion of a is greater than the time portion of b. The behavior is undefined unless 24 != lhs.hour() && 24 != rhs.hour().

◆ operator>=

bool operator>= ( const Datetime ,
const Datetime  
)
friend

Return true if the value of the specified lhs object is greater than or equal to the value of the specified rhs object, and false otherwise. The behavior is undefined unless 24 != lhs.hour() && 24 != rhs.hour().


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