blocxx
BLOCXX_NAMESPACE::DateTime Class Reference

The DateTime class is an abstraction for date time data. More...

#include <DateTime.hpp>

Public Types

enum  ETimeOffset { E_LOCAL_TIME , E_UTC_TIME }
 The values of this enum are passed to various functions to as a flag to indicate the timezone context desired. More...
 

Public Member Functions

 DateTime ()
 Create a new DateTime object that represents the Epoch (00:00:00 UTC, January 1, 1970)
 
 DateTime (const String &str)
 Create a new DateTime object from a string that contains one of: (1) a CIM DateTime formated string (e.g.
 
 DateTime (time_t t, UInt32 microseconds=0)
 Create a DateTime object that represents the given time.
 
 DateTime (int year, int month, int day, int hour=0, int minute=0, int second=0, UInt32 microsecond=0, ETimeOffset timeOffset=E_LOCAL_TIME)
 Create a new DateTime object that represent the given date and time.
 
 ~DateTime ()
 Destructor.
 
int getHour (ETimeOffset timeOffset=E_LOCAL_TIME) const
 Get the hour of the day for this DateTime object 0-23.
 
int getMinute (ETimeOffset timeOffset=E_LOCAL_TIME) const
 Get the minute of the hour for this DateTime object 0-59.
 
int getSecond (ETimeOffset timeOffset=E_LOCAL_TIME) const
 Get the second of the minute for this DateTime object normally in the range 0-59, but can be up to 60 to allow for leap seconds.
 
UInt32 getMicrosecond () const
 Get the microsecond of the second for this DateTime object.
 
int getDay (ETimeOffset timeOffset=E_LOCAL_TIME) const
 Get the day of the month (1-31)
 
int getDow (ETimeOffset timeOffset=E_LOCAL_TIME) const
 
int getMonth (ETimeOffset timeOffset=E_LOCAL_TIME) const
 
int getYear (ETimeOffset timeOffset=E_LOCAL_TIME) const
 
time_t get () const
 
void setHour (int hour, ETimeOffset timeOffset=E_LOCAL_TIME)
 Set the hour component of this DateTime object.
 
void setMinute (int minute, ETimeOffset timeOffset=E_LOCAL_TIME)
 Set the minute component of this DateTime object.
 
void setSecond (int second, ETimeOffset timeOffset=E_LOCAL_TIME)
 Set the second component of this DateTime object.
 
void setMicrosecond (UInt32 microsecond)
 Set the microsecond component of this DateTime object.
 
void setTime (int hour, int minute, int second, ETimeOffset timeOffset=E_LOCAL_TIME)
 Set the time component of this DateTime object.
 
void setDay (int day, ETimeOffset timeOffset=E_LOCAL_TIME)
 Set the day component of this DateTime object.
 
void setMonth (int month, ETimeOffset timeOffset=E_LOCAL_TIME)
 Set the month component of this DateTime object.
 
void setYear (int year, ETimeOffset timeOffset=E_LOCAL_TIME)
 Set the year component of this DateTime object.
 
void set (time_t t, UInt32 microseconds=0)
 Set this DateTime object with a time_t value.
 
void set (int year, int month, int day, int hour, int minute, int second, UInt32 microseconds, ETimeOffset timeOffset=E_LOCAL_TIME)
 Set the date and time for this DateTime.
 
void setToCurrent ()
 Set this DateTime to the current system time.
 
void addDays (int days)
 Add days to the date represented by this object.
 
void addWeeks (int weeks)
 Add week to the date represented by this object.
 
void addMonths (int months)
 Add months to the date represented by this object.
 
void addYears (int years)
 Add years to the date represent by this object.
 
void addSeconds (long seconds)
 Add seconds to the date represented by this object.
 
void addMinutes (long minutes)
 Add minutes to the date represented by this object.
 
void addMicroseconds (long microseconds)
 Add microseconds to the date represented by this object.
 
void addMilliseconds (long milliseconds)
 Add milliseconds to the date represented by this object.
 
void addHours (long hours)
 Add hours to the date represented by this object.
 
bool operator< (const DateTime &tm) const
 Less than operator.
 
bool operator> (const DateTime &tm) const
 Greater than operator.
 
bool operator== (const DateTime &tm) const
 Equality operator.
 
bool operator!= (const DateTime &tm) const
 Inequality operator.
 
bool operator<= (const DateTime &tm) const
 Less than or equal operator.
 
bool operator>= (const DateTime &tm) const
 Greate than or equal operator.
 
DateTimeoperator+= (long seconds)
 Add a given number of seconds to this DateTime object.
 
DateTimeoperator-= (long seconds)
 Subtract a given number of seconds from this DateTime object.
 
String toString (ETimeOffset timeOffset=E_LOCAL_TIME) const
 
String toString (char const *format, ETimeOffset timeOffset=E_LOCAL_TIME) const
 
String toStringGMT () const BLOCXX_DEPRECATED
 This is the same as toString(E_UTC_TIME).
 
Int16 toLocal (struct tm &tt) const
 Converts date/time specified by *this to local time, stored in tt as per the C localtime function, and returns the corresponding GMT offset in minutes.
 

Static Public Member Functions

static Int16 getGMTOffsetMinutesNow ()
 Returns the GMT offset (number of minutes) of the system's timezone at the current moment.
 
static DateTime getCurrent ()
 Gets a DateTime instance set to the current system time.
 

Static Public Attributes

static char const DEFAULT_FORMAT [] = "%c"
 A default date/time format to use with toString().
 

Private Member Functions

tm getTm (ETimeOffset timeOffset) const
 
void setTime (tm &tmarg, ETimeOffset timeOffset)
 

Static Private Member Functions

static Int16 localTimeAndOffset (time_t t, struct tm &tt)
 

Private Attributes

time_t m_time
 
UInt32 m_microseconds
 

Detailed Description

The DateTime class is an abstraction for date time data.

It allows easy date/time adjustment, date/time arithmetic and comparison. All functions which operate on a time_t are based on seconds since the Epoch, and the timezone is irrelevant. DateTime cannot represent dates before the Epoch (00:00:00 UTC, January 1, 1970), and the upper limit is system dependent. On a system where time_t is 32-bits, the latest date that can be represented is Mon Jan 18 20:14:07 2038. If time_t is 64-bits, then it's a date so far in the future, that the sun will probably turn into a black hole before then. (About 500 billion years.) If an invalid time is created, then get() will return time_t(-1), and the DateTime represented will be 1 second before the Epoch (23:59:59 UTC, December 31, 1969)

If the non-standard function timegm() is available, it will be used, otherwise this class' implementation relies on the global variable timezone (from time.h) which reflects the system's timezone.

For constructor or setter member functions, if parameter values are outside their legal interval, they will be normalized (so that, e.g., 40 October is changed into 9 November).

Definition at line 80 of file DateTime.hpp.

Member Enumeration Documentation

◆ ETimeOffset

The values of this enum are passed to various functions to as a flag to indicate the timezone context desired.

E_LOCAL_TIME means the operation will apply the local system timezone (which may include an offset for daylight saving time). E_UTC_TIME means the operation will apply to UTC (or GMT) time.

Enumerator
E_LOCAL_TIME 
E_UTC_TIME 

Definition at line 90 of file DateTime.hpp.

Constructor & Destructor Documentation

◆ DateTime() [1/4]

BLOCXX_NAMESPACE::DateTime::DateTime ( )

Create a new DateTime object that represents the Epoch (00:00:00 UTC, January 1, 1970)

Definition at line 122 of file DateTime.cpp.

References m_microseconds, and m_time.

Referenced by getCurrent(), operator!=(), operator+=(), operator-=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().

◆ DateTime() [2/4]

BLOCXX_NAMESPACE::DateTime::DateTime ( const String & str)
explicit

Create a new DateTime object from a string that contains one of: (1) a CIM DateTime formated string (e.g.

"19980525133015.000000-300") (2) a ctime() formatted string (e.g. "Wed Jun 30 21:49:08 1993") The current local timezone is assumed. (3) a free-form date which must have a month, day, year, and time. Optional fields are a weekday, and timezone, and the seconds subfield of the time field.

There are no restrictions on the ordering of fields, with the exception of the day of month and year.

Assumptions made: The first free-standing number found is assumed to be the day of month. The second is the day of year.

Fields:

Month (required) The month field may be one of the three-letter English abbreviations (eg. Jan, Feb, Mar, etc), or the full English month name (eg. January, February, March, etc). Note that they are case sensitive, and only the first character is uppercase.

  Day of month (required)
  A number.  Currently, the first free-standing number found is
  assumed to be the day of month.

  Year (required)
  A number.  Currently, the second free-standing number found is
  assumed to be the year.

  Time (required)
  The hours, minutes, and optionally seconds of the time.  It is
  in the form HH:MM or HH:MM:SS.  The hour is expressed in the
  24 hour format (eg. 4pm would be hour 16).

  Day of week (optional)
  The day of week field may be one of the three-letter English
  abbreviations (eg. Sun, Mon, Tue, etc), or the full English
  day name (eg. Sunday, Monday, Tuesday, etc).  Note that they
  are case sensitive, and only the first character is uppercase.

  Timezone (optional)
  The timezone of the date.  The date and time will be
  transformed into UTC by this time zone.  If the time zone is
  not present, then the date is assumed to be in local time.

  The following time zones are recognized (case sensitive):
    UTC, GMT, BST, IST, WET, WEST, CET, CEST, EET, EEST, MSK,
    MSD, AST, ADT, EST, EDT, ET, CST, CDT, CT, MST, MDT, MT,
    PST, PDT, PT, HST, AKST, AKDT, WST, and single letters [A-Z]

  Timezones ET, CT, MT, and PT are all assumed to be standard
  (not daylight) time.
  NOTE: Some Australian time zones (EST, and CST), which
  conflict with US time zones are assumed to be in the US.

Valid Examples of free-form date strings:
  Thu Jan 29 11:02:42 MST 2004
  Oct 3 17:52:56 EDT 1998
  5:41:26 PDT Aug 15 1984 
  7 November 2003 13:35:03 GMT
  Monday May 1 8:27:39 UTC 2003
  June 1 23:49 2003 

Note that DateTime cannot hold an interval, so you cannot construct one from an CIM DateTime interval. If str is a CIM DateTime, the timezone is part of the string and will be honored. Otherwise, if str is a ctime() formatted string, the current C timezone will be used.

Parameters
strAn String object that contains the DateTime string
Exceptions
DateTimeExceptionif str does not contain a valid DateTime

Definition at line 743 of file DateTime.cpp.

References BLOCXX_NAMESPACE::Array< T >::begin(), E_LOCAL_TIME, E_UTC_TIME, BLOCXX_NAMESPACE::String::empty(), BLOCXX_NAMESPACE::Array< T >::end(), BLOCXX_NAMESPACE::String::length(), BLOCXX_NAMESPACE::String::npos, set(), BLOCXX_NAMESPACE::Array< T >::size(), BLOCXX_NAMESPACE::String::substring(), BLOCXX_NAMESPACE::String::toInt32(), and BLOCXX_NAMESPACE::String::tokenize().

◆ DateTime() [3/4]

BLOCXX_NAMESPACE::DateTime::DateTime ( time_t t,
UInt32 microseconds = 0 )
explicit

Create a DateTime object that represents the given time.

Parameters
tThe epoch time that this DateTime object will respresent This is the number of seconds since the Epoch, and should not be adjusted for time zone.
microsecondsThe microsecond component of the time. Valid values are 0..999999
Exceptions
DateTimeExceptionif t == time_t(-1)

Definition at line 965 of file DateTime.cpp.

References m_microseconds, and m_time.

◆ DateTime() [4/4]

BLOCXX_NAMESPACE::DateTime::DateTime ( int year,
int month,
int day,
int hour = 0,
int minute = 0,
int second = 0,
UInt32 microsecond = 0,
ETimeOffset timeOffset = E_LOCAL_TIME )

Create a new DateTime object that represent the given date and time.

Parameters
yearThe year component of the date. Valid values are >= 1970
monthThe month component of the date. Valid values are >= 1
dayThe day component of the date. Valid values are >= 1
hourThe hour component of the time. Valid values are >= 1
minuteThe minute component of the time. Any value is valid.
secondThe second component of the time. Any value is valid.
microsecondThe microsecond component of the time. Valid values are 0..999999
timeOffsetIndicates whether to use the local timezone or UTC.
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime.

Definition at line 971 of file DateTime.cpp.

References set().

◆ ~DateTime()

BLOCXX_NAMESPACE::DateTime::~DateTime ( )

Destructor.

Definition at line 977 of file DateTime.cpp.

Member Function Documentation

◆ addDays()

void BLOCXX_NAMESPACE::DateTime::addDays ( int days)

Add days to the date represented by this object.

Parameters
daysThe number of days to add to this object.
Exceptions
DateTimeExceptionif the resulting DateTime don't represent a valid DateTime.

Definition at line 1225 of file DateTime.cpp.

References E_UTC_TIME, getTm(), and setTime().

Referenced by addWeeks().

◆ addHours()

void BLOCXX_NAMESPACE::DateTime::addHours ( long hours)
inline

Add hours to the date represented by this object.

Parameters
hoursThe number of hours to add to this object.

Definition at line 455 of file DateTime.hpp.

References m_time.

◆ addMicroseconds()

void BLOCXX_NAMESPACE::DateTime::addMicroseconds ( long microseconds)
inline

Add microseconds to the date represented by this object.

Parameters
microsecondsThe number of microseconds to add to this object.

Definition at line 437 of file DateTime.hpp.

References m_microseconds, and m_time.

Referenced by addMilliseconds().

◆ addMilliseconds()

void BLOCXX_NAMESPACE::DateTime::addMilliseconds ( long milliseconds)
inline

Add milliseconds to the date represented by this object.

Parameters
millisecondsThe number of milliseconds to add to this object.

Definition at line 447 of file DateTime.hpp.

References addMicroseconds().

◆ addMinutes()

void BLOCXX_NAMESPACE::DateTime::addMinutes ( long minutes)
inline

Add minutes to the date represented by this object.

Parameters
minutesThe number of minutes to add to this object.

Definition at line 429 of file DateTime.hpp.

References m_time.

◆ addMonths()

void BLOCXX_NAMESPACE::DateTime::addMonths ( int months)

Add months to the date represented by this object.

Parameters
monthsThe number of months to add to this object.
Exceptions
DateTimeExceptionif the resulting DateTime don't represent a valid DateTime.

Definition at line 1241 of file DateTime.cpp.

References E_UTC_TIME, getTm(), and setTime().

◆ addSeconds()

void BLOCXX_NAMESPACE::DateTime::addSeconds ( long seconds)
inline

Add seconds to the date represented by this object.

Parameters
secondsThe number of seconds to add to this object.
Exceptions
DateTimeExceptionif the resulting DateTime don't represent a valid DateTime.

Definition at line 421 of file DateTime.hpp.

References m_time.

Referenced by operator+=(), and operator-=().

◆ addWeeks()

void BLOCXX_NAMESPACE::DateTime::addWeeks ( int weeks)
inline

Add week to the date represented by this object.

Parameters
weeksThe number of weeks to add to this object.
Exceptions
DateTimeExceptionif the resulting DateTime don't represent a valid DateTime.

Definition at line 397 of file DateTime.hpp.

References addDays().

◆ addYears()

void BLOCXX_NAMESPACE::DateTime::addYears ( int years)

Add years to the date represent by this object.

Parameters
yearsThe number of years to add to this object.
Exceptions
DateTimeExceptionif the resulting DateTime don't represent a valid DateTime.

Definition at line 1233 of file DateTime.cpp.

References E_UTC_TIME, getTm(), and setTime().

◆ get()

time_t BLOCXX_NAMESPACE::DateTime::get ( ) const
Returns
The number of seconds since Jan 1, 1970.

Definition at line 1094 of file DateTime.cpp.

References m_time.

Referenced by BLOCXX_NAMESPACE::TimeoutTimer::calcSeconds(), and BLOCXX_NAMESPACE::operator-().

◆ getCurrent()

DateTime BLOCXX_NAMESPACE::DateTime::getCurrent ( )
static

Gets a DateTime instance set to the current system time.

Definition at line 1329 of file DateTime.cpp.

References DateTime(), and setToCurrent().

Referenced by BLOCXX_NAMESPACE::TimeoutTimer::getCurrentTime().

◆ getDay()

int BLOCXX_NAMESPACE::DateTime::getDay ( ETimeOffset timeOffset = E_LOCAL_TIME) const

Get the day of the month (1-31)

Parameters
timeOffsetIndicates whether to use the local timezone or UTC
Returns

Definition at line 1070 of file DateTime.cpp.

References getTm().

◆ getDow()

int BLOCXX_NAMESPACE::DateTime::getDow ( ETimeOffset timeOffset = E_LOCAL_TIME) const
Parameters
timeOffsetIndicates whether to use the local timezone or UTC
Returns
The day of the week for the date represented by this object. This will be a value in the range 0-6.

Definition at line 1076 of file DateTime.cpp.

References getTm().

◆ getGMTOffsetMinutesNow()

static Int16 BLOCXX_NAMESPACE::DateTime::getGMTOffsetMinutesNow ( )
inlinestatic

Returns the GMT offset (number of minutes) of the system's timezone at the current moment.

Replacement for getGMTOffset(), if anyone is using it.

Definition at line 588 of file DateTime.hpp.

References localTimeAndOffset().

◆ getHour()

int BLOCXX_NAMESPACE::DateTime::getHour ( ETimeOffset timeOffset = E_LOCAL_TIME) const

Get the hour of the day for this DateTime object 0-23.

Parameters
timeOffsetIndicates whether to use the local timezone or UTC
Returns

Definition at line 1046 of file DateTime.cpp.

References getTm().

◆ getMicrosecond()

UInt32 BLOCXX_NAMESPACE::DateTime::getMicrosecond ( ) const

Get the microsecond of the second for this DateTime object.

In the range 0..999999. There are 1 million (1000000) microseconds per second.

Returns

Definition at line 1064 of file DateTime.cpp.

References m_microseconds.

Referenced by BLOCXX_NAMESPACE::TimeoutTimer::calcSeconds(), BLOCXX_NAMESPACE::SocketBaseImpl::connect(), BLOCXX_NAMESPACE::SocketBaseImpl::disconnect(), BLOCXX_NAMESPACE::operator-(), BLOCXX_NAMESPACE::SocketBaseImpl::read(), and BLOCXX_NAMESPACE::SocketBaseImpl::write().

◆ getMinute()

int BLOCXX_NAMESPACE::DateTime::getMinute ( ETimeOffset timeOffset = E_LOCAL_TIME) const

Get the minute of the hour for this DateTime object 0-59.

Parameters
timeOffsetIndicates whether to use the local timezone or UTC
Returns

Definition at line 1052 of file DateTime.cpp.

References getTm().

◆ getMonth()

int BLOCXX_NAMESPACE::DateTime::getMonth ( ETimeOffset timeOffset = E_LOCAL_TIME) const
Parameters
timeOffsetIndicates whether to use the local timezone or UTC
Returns
The month of the year. This will be a value in the range 1-12.

Definition at line 1082 of file DateTime.cpp.

References getTm().

◆ getSecond()

int BLOCXX_NAMESPACE::DateTime::getSecond ( ETimeOffset timeOffset = E_LOCAL_TIME) const

Get the second of the minute for this DateTime object normally in the range 0-59, but can be up to 60 to allow for leap seconds.

Parameters
timeOffsetIndicates whether to use the local timezone or UTC
Returns

Definition at line 1058 of file DateTime.cpp.

References getTm().

◆ getTm()

tm BLOCXX_NAMESPACE::DateTime::getTm ( ETimeOffset timeOffset) const
inlineprivate

◆ getYear()

int BLOCXX_NAMESPACE::DateTime::getYear ( ETimeOffset timeOffset = E_LOCAL_TIME) const
Parameters
timeOffsetIndicates whether to use the local timezone or UTC
Returns
The year. This value will include the century (e.g. 2001).

Definition at line 1088 of file DateTime.cpp.

References getTm().

◆ localTimeAndOffset()

Int16 BLOCXX_NAMESPACE::DateTime::localTimeAndOffset ( time_t t,
struct tm & tt )
staticprivate

Definition at line 1280 of file DateTime.cpp.

References BLOCXX_THROW, gmtime_r(), and localtime_r().

Referenced by getGMTOffsetMinutesNow(), and toLocal().

◆ operator!=()

bool BLOCXX_NAMESPACE::DateTime::operator!= ( const DateTime & tm) const
inline

Inequality operator.

Parameters
tmThe DateTime object to compare this one to.
Returns
true if this object is not equal to the given DateTime object.

Definition at line 493 of file DateTime.hpp.

References DateTime().

◆ operator+=()

DateTime & BLOCXX_NAMESPACE::DateTime::operator+= ( long seconds)
inline

Add a given number of seconds to this DateTime object.

Parameters
secondsThe number of seconds to add to this object.
Returns
A reference to this object.

Definition at line 522 of file DateTime.hpp.

References addSeconds(), and DateTime().

◆ operator-=()

DateTime & BLOCXX_NAMESPACE::DateTime::operator-= ( long seconds)
inline

Subtract a given number of seconds from this DateTime object.

Parameters
secondsThe number of seconds to subtract from this object.
Returns
A reference to this object.

Definition at line 532 of file DateTime.hpp.

References addSeconds(), and DateTime().

◆ operator<()

bool BLOCXX_NAMESPACE::DateTime::operator< ( const DateTime & tm) const
inline

Less than operator.

Parameters
tmThe DateTime object to compare this one to.
Returns
true if this object is less than the given DateTime object.

Definition at line 461 of file DateTime.hpp.

References DateTime(), m_microseconds, and m_time.

◆ operator<=()

bool BLOCXX_NAMESPACE::DateTime::operator<= ( const DateTime & tm) const
inline

Less than or equal operator.

Parameters
tmThe DateTime object to compare this one to.
Returns
true if this object is less than or equal to the given DateTime object.

Definition at line 503 of file DateTime.hpp.

References DateTime().

◆ operator==()

bool BLOCXX_NAMESPACE::DateTime::operator== ( const DateTime & tm) const
inline

Equality operator.

Parameters
tmThe DateTime object to compare this one to.
Returns
true if this object is equal to the given DateTime object.

Definition at line 484 of file DateTime.hpp.

References DateTime(), m_microseconds, and m_time.

◆ operator>()

bool BLOCXX_NAMESPACE::DateTime::operator> ( const DateTime & tm) const
inline

Greater than operator.

Parameters
tmThe DateTime object to compare this one to.
Returns
true if this object is greater than the given DateTime object.

Definition at line 475 of file DateTime.hpp.

References DateTime().

◆ operator>=()

bool BLOCXX_NAMESPACE::DateTime::operator>= ( const DateTime & tm) const
inline

Greate than or equal operator.

Parameters
tmThe DateTime object to compare this one to.
Returns
true if this object is greater than or equal to the given DateTime object.

Definition at line 513 of file DateTime.hpp.

References DateTime().

◆ set() [1/2]

void BLOCXX_NAMESPACE::DateTime::set ( int year,
int month,
int day,
int hour,
int minute,
int second,
UInt32 microseconds,
ETimeOffset timeOffset = E_LOCAL_TIME )

Set the date and time for this DateTime.

Parameters
yearThe new year component for this object. Valid values are >= 1970.
monthThe new month component for this object.
dayThe new day component for this object.
hourThe new hour component for this object.
minuteThe new minute component for this object.
secondThe new second component for this object.
microsecondsThe new microseconds component for this object. Valid values are 0..999999.
timeOffsetIndicates whether to use the local timezone or UTC
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime.

Definition at line 1173 of file DateTime.cpp.

References E_UTC_TIME, m_microseconds, and setTime().

◆ set() [2/2]

void BLOCXX_NAMESPACE::DateTime::set ( time_t t,
UInt32 microseconds = 0 )

Set this DateTime object with a time_t value.

Parameters
tA time_t value that represents the number of seconds from Jan 1, 1970.
microsecondsThe microsecond component of the time. Valid values are 0..999999.
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime.

Definition at line 1315 of file DateTime.cpp.

References BLOCXX_THROW, m_microseconds, and m_time.

Referenced by DateTime(), and DateTime().

◆ setDay()

void BLOCXX_NAMESPACE::DateTime::setDay ( int day,
ETimeOffset timeOffset = E_LOCAL_TIME )

Set the day component of this DateTime object.

Parameters
dayThe new day for this DateTime object.
timeOffsetIndicates whether to use the local timezone or UTC
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime.

Definition at line 1144 of file DateTime.cpp.

References getTm(), and setTime().

◆ setHour()

void BLOCXX_NAMESPACE::DateTime::setHour ( int hour,
ETimeOffset timeOffset = E_LOCAL_TIME )

Set the hour component of this DateTime object.

Parameters
hourThe new hour for this DateTime object.
timeOffsetIndicates whether to use the local timezone or UTC
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime.

Definition at line 1100 of file DateTime.cpp.

References getTm(), and setTime().

◆ setMicrosecond()

void BLOCXX_NAMESPACE::DateTime::setMicrosecond ( UInt32 microsecond)

Set the microsecond component of this DateTime object.

Parameters
microsecondThe new microsecond for this DateTime object. Acceptable range is 0..999999
Exceptions
DateTimeExceptionif microsecond is out of range.

Definition at line 1124 of file DateTime.cpp.

References BLOCXX_THROW, and m_microseconds.

◆ setMinute()

void BLOCXX_NAMESPACE::DateTime::setMinute ( int minute,
ETimeOffset timeOffset = E_LOCAL_TIME )

Set the minute component of this DateTime object.

Parameters
minuteThe new minute for this DateTime object.
timeOffsetIndicates whether to use the local timezone or UTC
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime.

Definition at line 1108 of file DateTime.cpp.

References getTm(), and setTime().

◆ setMonth()

void BLOCXX_NAMESPACE::DateTime::setMonth ( int month,
ETimeOffset timeOffset = E_LOCAL_TIME )

Set the month component of this DateTime object.

Parameters
monthThe new month for this DateTime object. Valid values are >= 1.
timeOffsetIndicates whether to use the local timezone or UTC
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime or month == 0.

Definition at line 1152 of file DateTime.cpp.

References BLOCXX_THROW, getTm(), and setTime().

◆ setSecond()

void BLOCXX_NAMESPACE::DateTime::setSecond ( int second,
ETimeOffset timeOffset = E_LOCAL_TIME )

Set the second component of this DateTime object.

Parameters
secondThe new second for this DateTime object.
timeOffsetIndicates whether to use the local timezone or UTC
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime.

Definition at line 1116 of file DateTime.cpp.

References getTm(), and setTime().

◆ setTime() [1/2]

void BLOCXX_NAMESPACE::DateTime::setTime ( int hour,
int minute,
int second,
ETimeOffset timeOffset = E_LOCAL_TIME )

Set the time component of this DateTime object.

Parameters
hourThe hour component of the time.
minuteThe minute component of the time.
secondThe second component of the time.
timeOffsetIndicates whether to use the local timezone or UTC
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime.

Definition at line 1134 of file DateTime.cpp.

References getTm(), and setTime().

Referenced by addDays(), addMonths(), addYears(), set(), setDay(), setHour(), setMinute(), setMonth(), setSecond(), setTime(), and setYear().

◆ setTime() [2/2]

void BLOCXX_NAMESPACE::DateTime::setTime ( tm & tmarg,
ETimeOffset timeOffset )
inlineprivate

Definition at line 1000 of file DateTime.cpp.

References asctime_r(), BLOCXX_THROW, E_LOCAL_TIME, m_time, and toString().

◆ setToCurrent()

void BLOCXX_NAMESPACE::DateTime::setToCurrent ( )

◆ setYear()

void BLOCXX_NAMESPACE::DateTime::setYear ( int year,
ETimeOffset timeOffset = E_LOCAL_TIME )

Set the year component of this DateTime object.

Parameters
yearThe new year for this DateTime object. Valid values are >= 1970.
timeOffsetIndicates whether to use the local timezone or UTC
Exceptions
DateTimeExceptionif the parameters don't represent a valid DateTime

Definition at line 1165 of file DateTime.cpp.

References getTm(), and setTime().

◆ toLocal()

Int16 BLOCXX_NAMESPACE::DateTime::toLocal ( struct tm & tt) const
inline

Converts date/time specified by *this to local time, stored in tt as per the C localtime function, and returns the corresponding GMT offset in minutes.

Parameters
ttThe tm struct where to store the date/time.

Definition at line 601 of file DateTime.hpp.

References localTimeAndOffset(), and m_time.

◆ toString() [1/2]

String BLOCXX_NAMESPACE::DateTime::toString ( char const * format,
ETimeOffset timeOffset = E_LOCAL_TIME ) const
Parameters
formatis a date/time format string such as used by strftime(). Note that the underlying representation uses strftime(), so some conversion specifiers may be available which aren't portable. For maximum portability, restrict usage to those defined in ANSI C.
timeOffsetIndicates whether to use the local timezone or UTC
Returns
Conversion of this DateTime to String using format. REQUIRE: formatted time has length at most 1023.

Definition at line 1259 of file DateTime.cpp.

References getTm().

◆ toString() [2/2]

String BLOCXX_NAMESPACE::DateTime::toString ( ETimeOffset timeOffset = E_LOCAL_TIME) const
Parameters
timeOffsetIndicates whether to use the local timezone or UTC
Returns
The string representation of this DateTime object. The format is like "Wed Jun 30 21:49:08 1993\n" as returned by ctime().

Definition at line 1249 of file DateTime.cpp.

References asctime_r(), and getTm().

Referenced by BLOCXX_NAMESPACE::SocketBaseImpl::connect(), BLOCXX_NAMESPACE::SocketBaseImpl::disconnect(), BLOCXX_NAMESPACE::SocketBaseImpl::read(), setTime(), toStringGMT(), and BLOCXX_NAMESPACE::SocketBaseImpl::write().

◆ toStringGMT()

String BLOCXX_NAMESPACE::DateTime::toStringGMT ( ) const

This is the same as toString(E_UTC_TIME).

This function is deprecated and exists for backward compatibility purposes.

Definition at line 1274 of file DateTime.cpp.

References E_UTC_TIME, and toString().

Member Data Documentation

◆ DEFAULT_FORMAT

char const BLOCXX_NAMESPACE::DateTime::DEFAULT_FORMAT = "%c"
static

A default date/time format to use with toString().

The value is "%c", which is "The preferred date and time representation for the current locale."

Definition at line 563 of file DateTime.hpp.

◆ m_microseconds

UInt32 BLOCXX_NAMESPACE::DateTime::m_microseconds
private

◆ m_time

time_t BLOCXX_NAMESPACE::DateTime::m_time
private

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