Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Hydra Core Library Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

rwsf::DateTime

Group:  General

Local Index

Members

Non-Members

Header File

#include <rwsf/core/DateTime.h>

Description

Class rwsf::DateTime represents a date and time, stored in milliseconds, from January 1, 1901 00:00:00:000 UTC. Milliseconds are stored in a 64-bit integral type, which is represented by the global typedef rwsfint64.

rwsf::DateTime supports the ISO 8601 international standard for the formatting of dates and times.

rwsf::DateTime is based on the Gregorian Calendar. The Gregorian calendar was introduced by Pope Gregory XIII in 1582, and was adopted in various places at various times. It was adopted by England on September 14, 1752, and thus came to the United States. rwsf::DateTime was designed for use with dates after September 14, 1752.

Four public member functions, all starting with julian, let you manipulate the date via Modified Julian days (MJD). Note that the Modified Julian day number is not the same as a date according to the Julian calendar. The Modified Julian day number is calculated using Algorithm 199 from Communications of the ACM, Volume 6, No. 8, (Aug. 1963), p. 444 and is valid for any valid Gregorian date in the Gregorian calendar.


NOTE -- The modern Modified Julian Day (MJD) was introduced in the 1950's and starts at midnight, as opposed to the historic Julian Day (JD), which began at 12 noon. It is defined as
MJD = JD - 2400000.5
.
The half day is subtracted so that the day starts at midnight in conformance with civil time reckoning.

Modified Julian days in the rwsf::DateTime function correctly from Modified Julian day 0, but can only be converted to month, date, year for Modified Julian days that fall within the Gregorian Calendar.

Note that two-digit year specifiers assume the century 1900, so you will want to create programs that use four-digit year specifiers.

rwsf::DateTimes can be converted to and from the Standard C Library type struct tm defined in <time.h>,and listed here in Table 2.

Table 2: Elements of struct tm

int tm_sec;

seconds after the minute - [0,59]

int tm_min;

minutes after the hour - [0,59]

int tm_hour;

hours since midnight - [0,23]

int tm_mday;

day of the month - [1,31]

int tm_mon;

months since January - [0,11]

int tm_year;

years since 1900

int tm_wday;

days since Sunday - [0,6]

int tm_yday;

days since January 1 - [0,365]

int tm_isdst;

daylight savings time flag

The default constructor for this class creates an instance with an invalid date and time, which facilitates creating a large array, as follows:

rwsf::DateTime objects can hold a variety of sentinel values that do not refer to actual dates. Consequently it is important to know whether an object holds an actual date before performing many operations. The isSentinel() function returns true when an object it is applied to hold a sentinel value.

Note that the use of the isValid() function does not determine whether a member function can be successfully applied to an object since the null sentinel value represents a valid rwsf::DateTime whose value is not yet determined.

Example


Program output:


Enumerations

enum
InitialState { invalid, null, setCurrentTime }
enum
setType { setDate, setTime, setBoth }
enum 
Format { iso8601, http };
enum
ImplType { implDouble, implLong };

Static Constant Data Members

static const rwsfint64 DateTime::futureSentinel
static const rwsfint64 DateTime::invalidSentinel
static const rwsfint64 DateTime::maxDateTime
static const rwsfint64 DateTime::millisecsInDay
static const rwsfint64 DateTime::millisecsInHour
static const rwsfint64 DateTime::millisecsInMin
static const rwsfint64 DateTime::millisecsInSec
static const rwsfint64 DateTime::minDateTime
static const rwsfint64 DateTime::nullSentinel
static const rwsfint64 DateTime::pastSentinel 
static const rwsfint64 DateTime::userSentinelStart 
static const rwsfint64 DateTime::jday0 
static const rwsfint64 DateTime::midnightJday0 

Public Constructors

DateTime(InitialState init_state = invalid);
DateTime(const DateTime& dt);
DateTime(rwsfint64 msec);
DateTime(const struct tm*, unsigned ms=0,
          const rwsf::TimeZone& = rwsf::TimeZone::local());
DateTime(unsigned, const char* month, unsigned year, 
     unsigned h, unsigned m, unsigned s,
     unsigned ms, 
     const rwsf::Locale& loc = rwsf::Locale::global(),
     const rwsf::TimeZone& zone = rwsf::TimeZone::local());
DateTime(unsigned day, unsigned month, unsigned year, 
    unsigned h=0, unsigned m=0, unsigned s=0,
    unsigned ms=0, 
    const rwsf::TimeZone& = rwsf::TimeZone::local());
DateTime(const std::string& str, SetType set_type = setBoth,
    const rwsf::Locale& loc = rwsf::Locale::global(),
    const rwsf::TimeZone& zone = rwsf::TimeZone::local());
DateTime(const std::string& str, Format f,
const rwsf::Locale& loc = rwsf::Locale::global(),
const rwsf::TimeZone& zone = rwsf::TimeZone::
local());

Operators

DateTime&
operator=(const DateTime& dt);

Public Member Functions

std::string
asString(char format, 
         const rwsf::Locale& loc = rwsf::Locale::global(),
         const rwsf::TimeZone& = rwsf::TimeZone::
local()) const;
std::string
asString(const char* format,
    const rwsf::Locale& loc = rwsf::Locale::global()
    const rwsf::TimeZone& = rwsf::TimeZone::local()) const;
std::string 
asString(Format f,
const rwsf::Locale& loc = rwsf::Locale::global(),
const rwsf::TimeZone& = rwsf::TimeZone::local()) const;
bool
between(const DateTime& a, const DateTime& b) const;
int 
compareTo(const DateTime& dt) const;
int 
compareTo(const DateTime* dt) const;
unsigned 
correctedJulian() const; 

NOTE -- The method correctedJulian() is the only rwsf::DateTime method that uses the original Julian day number, instead of the Modified Julian day number.
unsigned 
day(const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
unsigned
dayGMT() const; 
unsigned 
dayOfMonth(const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
unsigned
dayOfMonthGMT();
DateTime& 
decrementHour(const rwsfint64 hour); 
DateTime& 
decrementMillisecond(const rwsfint64 millisecond);
DateTime& 
decrementMinute(const rwsfint64 minute); 
DateTime& 
decrementSecond((const rwsfint64 second); 

NOTE -- The decrement operations can cause rwsf::DateTime to cross a Daylight Saving Time boundary; if so, the returned rwsf::DateTime will have a daylight-saving offset.
void 
extract(struct tm* tmbuf, 
        const rwsf::TimeZone& = rwsf::TimeZone::
local()) const;
void 
extractGMT(struct tm* tmbuf) const; 
unsigned
firstDayOfMonth(unsigned mon, 
                 const rwsf::TimeZone& = rwsf::TimeZone::
local()) const;
unsigned
firstDayOfMonth(const rwsf::TimeZone& = rwsf::TimeZone::
local()) const;
unsigned
hash() const; 
unsigned
hour(const rwsf::TimeZone& = rwsf::TimeZone::local())  const;
unsigned
hourGMT() const;
DateTime& 
incrementHour(const rwsfint64 hour); 
DateTime&
incrementMillisecond(const rwsfint64 millisecond);
DateTime& 
incrementMinute(const rwsfint64 minute); 
DateTime& 
incrementSecond(const rwsfint64 second);

NOTE -- The increment operations can cause rwsf::DateTime to cross a Daylight Saving Time boundary; if so, the returned rwsf::DateTime will have a daylight-saving offset.
bool
isDST(const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
bool
isFuture() const;
bool
isInvalid() const;
bool
isNull() const;
bool
isPast() const;
bool
isSentinel() const;
bool
isValid() const;

NOTE -- The next four functions let you manipulate the date via Modified Julian days. Note that the Modified Julian day number is not the same as a date according to the Julian calendar. The Modified Julian day number is calculated using Algorithm 199 from Communications of the ACM, Volume 6, No. 8, (Aug. 1963), p. 444 and is valid for any valid Gregorian date in the Gregorian calendar.
unsigned
julian() const; 
void
julian(unsigned j);
double
julianDay() const;
void
julianDay(double j);
bool
leap(const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
bool 
leapGMT();
DateTime
max(const DateTime& t) const; 
DateTime
min(const DateTime& t) const; 
unsigned
milliSecond() const; 
rwsfint64
milliSeconds() const; 
unsigned
minute(const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
unsigned 
minuteGMT() const; 
unsigned
month(const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
unsigned
monthGMT() const; 
std::string
monthName(const rwsf::Locale loc, 
          const rwsf::TimeZone& = rwsf::TimeZone::
local()) const;
DateTime
next(unsigned dayNum, const rwsf::TimeZone& = rwsf::TimeZone::
local()) const;
DateTime
next(const char* dayName,
     const rwsf::Locale loc = rwsf::Locale::global();
     const rwsf::TimeZone& = rwsf::TimeZone::local()) const;
DateTime
previous(unsigned dayNum, 
     const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
DateTime
previous(const char* dayName, 
const rwsf::Locale& loc = rwsf::Locale::global(),
const rwsf::TimeZone& = rwsf::TimeZone::local()const;
unsigned
second() const; 
unsigned
weekDay(const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
unsigned
weekDayGMT() const; 
std::string
weekDayName(const rwsf::Locale& loc = rwsf::Locale::global(),
     const rwsf::TimeZone& = rwsf::TimeZone::local()) const;
unsigned
year(const rwsf::TimeZone& = rwsf::TimeZone::local()) const; 
unsigned 
yearGMT() const; 

Static Public Member Functions

static DateTime
beginDST(unsigned year, const rwsf::TimeZone& =
rwsf::TimeZone::local());
static unsigned
dayOfWeek(const char* day,
     const rwsf::Locale& loc = rwsf::Locale::global());
static unsigned
daysInMonthYear(unsigned month, unsigned year); 
static unsigned
daysInYear(unsigned year); 
static bool
dayWithinMonth(unsigned month, unsigned day, unsigned yr) ;
static DateTime
endDST(unsigned year,const 
     rwsf::TimeZone&=rwsf::TimeZone::local());
static unsigned
hash(const DateTime& dt);
static unsigned
indexOfMonth(const char* month,
     const rwsf::Locale& loc = rwsf::Locale::global());
static bool
leapYear(unsigned year); 
static std::string
nameOfMonth(unsigned monthNum,
     const rwsf::Locale& loc = rwsf::Locale::global());
static DateTime
now();
static DateTime
userSentinel(int i);
static std::string
weekDayName(unsigned dayNum, 
     const rwsf::Locale& loc = rwsf::Locale::global());

Related Global Operators

rwsfint64
operator-(const DateTime &dt1, const DateTime &dt2);
bool
operator<(const DateTime& t1, const DateTime& t2);
bool
operator<=(const DateTime& l, const DateTime& r);
bool
operator>(const DateTime& l, const DateTime& r);
bool
operator>=(const DateTime& l, const DateTime& r);
bool
operator==(const DateTime& t1, const DateTime& t2);
bool
operator!=(const DateTime& l, const DateTime& r);
DateTime
operator+(const DateTime& dt, rwsfint64 ms);
DateTime
operator+(rwsfint64 ms, const DateTime& dt);
DateTime
operator-(const DateTime& dt, rwsfint64 ms);


Previous fileTop of DocumentContentsIndex pageNext file

©2004-2007 Copyright Quovadx, Inc. All Rights Reserved.
Quovadx and Rogue Wave are registered trademarks and HydraSDO is a trademark of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.