Module: Essential Tools Module Group: Date and Time Classes
Does not inherit
operator!=() operator>>() operator>() |
operator>=() operator<<() operator<() |
operator<=() operator+() operator-() |
operator==() |
#include <rw/tools/datetime.h> RWDateTime dt(RWDateTime::setCurrentTime); // construct // today's date
Class RWDateTime 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 rwint64.
RWDateTime now supports the ISO 8601 international standard for the formatting of dates and times. For information and formatting syntax, see Section 3.3, "International Standards for Dates and Times," in the Essential Tools Module User's Guide.
RWDateTime is based on the Gregorian Calendar, and its range extends for thousands of years beyond that of RWTime. 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. RWDateTime 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. The Essential Tools Module User's Guide provides more information.
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 Essential Tools Module RWDateTime 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.
RWDateTime can be converted to and from RWTimes and RWDates. Because of the greater accuracy and range, RWDateTime is the preferred class to use for dates and times.
NOTE -- RWTime and RWDate are deprecated and so are all methods that either take or return instances of these two classes. Deprecation means that these classes and related methods are no longer supported, and may be removed in a future release.
RWDateTimes can also be converted to and from the Standard C Library type struct tm defined in <time.h>,and listed here in Table 17.
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, unlike RWDate and RWTime, both of which hold the current date by default. Consequently, it is much quicker to create a large array using RWDateTime than it is using RWDate. The example below illustrates the difference:
RWDate v[5000]; // Figures out the current date 5000 times RWDateTime v[5000]; // Creates an array with 5000 undefined dates // and times
RWDateTime 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 RWDateTime whose value is not yet determined. For more information about RWDateTime sentinels, see Section 3.5.2, "RWDateTime Sentinels," in the Essential Tools Module User's Guide.
Simple
#include <rw/tools/datetime.h> #include <iostream> int main() { // Today's date RWDateTime dt(RWDateTime::setCurrentTime); // Last Sunday's date RWDateTime lastSunday = dt.previous("Sunday"); std::cout << dt << std::endl << lastSunday << std::endl; }
Program output (when run on June 9, 2009):
Tue Jun 9 21:14:31 2009 Sun Jun 7 21:14:31 2009
enum RWDateTime::InitialState { invalid, null, setCurrentTime }
Specifies whether the constructor should construct an invalid, null, or current RWDateTime. Default is to set an invalid RWDateTime, with an undefined date and time.
enum RWDateTime::setType { setDate, setTime, setBoth }
Specifies whether the constructor should set just the date, just the time or both. Default is to set both.
enum
RWDateTime::Format { iso8601 };
Specifies the format to be used for converting between RWCString and RWDateTime using the ISO 8601standard. This standard converts any date and time to a locale-nonspecific numeric format.
static const rwint64 RWDateTime::futureSentinel
Sentinel values representing future RWDateTimes.
static const rwint64 RWDateTime::invalidSentinel
Sentinel values for invalid RWDateTime sentinels.
static const rwint64 RWDateTime::maxDateTime
The maximum number of milliseconds that an RWDateTime may hold.
static const rwint64 RWDateTime::millisecsInDay
The number of milliseconds in a day.
static const rwint64 RWDateTime::millisecsInHour
The number of milliseconds in a hour.
static const rwint64 RWDateTime::millisecsInMin
The number of milliseconds in a minute.
static const rwint64 RWDateTime::millisecsInSec
The number of milliseconds in a second.
static const rwint64 RWDateTime::minDateTime
The minimum number of milliseconds that an RWDateTime may hold.
static const rwint64 RWDateTime::nullSentinel
Sentinel values for null RWDateTime sentinels.
static const rwint64 RWDateTime::pastSentinel
Sentinel values representing past RWDateTimes.
static const rwint64 RWDateTime::userSentinelStart
The starting value for user-defined sentinels.
RWDateTime(InitialState init_state = invalid);
Default constructor. Constructs an RWDateTime with undefined date and time. If init_state is set to RWDateTime::setCurrentTime, an instance with the current date and time is created. If init_state is set to RWDateTime::null, an instance set to null is created.
RWDateTime(const RWDateTime& dt);
Copy constructor.
explicit RWDateTime(rwint64 milliseconds);
Constructs an RWDateTime from the number of milliseconds since 1 January 1901 00:00:00:000 UTC. rwint64 is at least a 64-bit integral type. msec may be negative for representing times prior to midnight 01/01/1901.
RWDateTime(const struct tm*, unsigned milliseconds = 0, const RWZone& = RWZone::local());
Constructs an RWDateTime from the tm_year, tm_mon, tm_mday, tm_hour, tm_min, tm_sec components of the struct tm argument with the milliseconds portion of the RWDateTime as specified by msec. The components are understood to be relative to the time zone passed in, which defaults to local time. Note that the numbering of the months and years in a struct tm differs from that used in RWDateTime arguments, which start at the number 1. The arguments included in struct tm are shown above in Table 17.
It tests as a precondition the struct tm pointer which cannot be null. If null, it asserts in debug builds and throws an object of type RWInternalErr in optimized builds.'
RWDateTime(unsigned month_day, const char* month, unsigned year, unsigned hours, unsigned minutes, unsigned seconds, unsigned milliseconds, const RWLocale& loc = RWLocale::global(), const RWZone& zone = RWZone::local());
Constructs an RWDateTime using the specified day, month, year, hour, minute, second, and millisecond, all relative to the time zone specified, which defaults to local time. The optional locale argument is used to convert the month name.
RWDateTime(unsigned day, unsigned month, unsigned year, unsigned hours=0, unsigned minutes=0, unsigned seconds=0, unsigned milliseconds=0, const RWZone& = RWZone::local());
Constructs an RWDateTime using the specified day, month, year, hour, minute, second, and millisecond, all relative to the time zone specified, which defaults to local time.
explicit RWDateTime(const RWCString& str, SetType set_type = setBoth, const RWLocale& loc = RWLocale::global(), const RWZone& zone = RWZone::local());
Converts the string str to a date and/or time as indicated by set_type, all relative to the time zone specified, which defaults to local time. By default, both the date and time are set using RWLocale locale. The constructor expects the date and time portions of the RWCString to be separated by a semicolon when both date and time are being set. The locale argument is used to convert the month name. The member function isValid() must be used to test whether the results are a valid date. Because RWLocale cannot rigorously check date input, dates created this way should also be recon-firmed by the user.
Example:
RWDateTime("April 4, 1998; 10:00 am", RWDateTime::setBoth, RWLocale::global()); // sets date and time RWDateTime("April 4, 1998", RWDateTime::setDate, RWLocale::global()); // sets date and initializes // time to 00:00:00 RWDateTime("10:00 am", RWDateTime::setTime, RWLocale::global()); // initializes date to // today at time 10:00
RWDateTime(std::istream& s, SetType set_type, const RWLocale& loc = RWLocale::global(); const RWZone& zone = RWZone::local());
Reads a full line and converts it to a date and/or time as indicated by the set_type, all relative to the specified time zone, which defaults to local time. By default, both the date and time are set using the global RWLocale locale. The constructor expects the date and time portions of the RWCString to be separated by semico-lon when both day and time are being set. The locale argument is used to convert the month name. The member function isValid() must be used to test whether the results are a valid date. Because RWLocale cannot rigorously check date input, dates created this way should be recon-firmed by the user.
RWDateTime(const RWTime& t, unsigned milliseconds=0);
WARNING: This method is deprecated and no longer supported, as RWTime is deprecated.
Constructs an RWDateTime from the given RWTime using the msec argument for the number of milliseconds.
RWDateTime(const RWDate& d, unsigned hours=0, unsigned minutes=0, unsigned seconds=0, unsigned milliseconds=0, const RWZone& = RWZone::local());
WARNING: This method is deprecated and no longer supported, as RWDate is deprecated.
Constructs an RWDateTime using the RWDate d and the time h:m:s:ms. The time specified defaults to local time.
RWDateTime(const RWCString& str, Format format, const RWLocale& = RWLocale::global(),
const RWZone& = RWZone::local());
Constructs an RWDateTime from the string str using the format specified by f. RWDateTime currently supports the ISO 8601 format which is numeric and locale-neutral; as such the RWLocale argument is ignored for ISO 8601, but is reserved for future use. The constructor uses the RWZone argument unless the string specifies the UTC time zone or an offset from UTC, in which case the RWZone argument is ignored in favor of UTC. For more information, see Section 3.3.2.1, "Applying the ISO Standard to Time Zone Offsets," in the Essential Tools Module User's Guide
Please note that confusion can occur when using a string that contains only a date or only a time indication, since it is not possible to differentiate between some representations of the two formats. For example. the string 190415 could represent either or both of the following:
date: the 15th day of the 4th month of the 19th year in the default century
time 19:04:15
You can avoid such confusions by using more explicit formats. For example, you can completely and safely avoid all confusions if you are careful to prepend "T" (allowed by the standard in time-only indications) for all times or if you always use extended formats. (See Section 3.3.2.1, "Applying the ISO Standard to Time Zone Offsets," in the Essential Tools Module User's Guide)
Two Examples:
// Construct an RWDateTime of 11:59:59 PM on December 24th, // 2001 in the RWZone::local() time zone. RWDateTime dt ("2001-12-24T23:59:59", RWDateTime::iso8601); // Construct an RWDateTime of 8 AM, April 12th, 1985 // in the GMT time zone
RWDateTime gmt ("1985-04-12T08:00:00Z", RWDateTime::iso8601);
For a date or time supplied singly (for example, "2001-12-24" or "23:59:59"), RWDateTime calls the system to retrieve the current date or time.
RWDateTime& operator=(const RWDateTime&);
Assignment operator.
RWCString asString(char format, const RWLocale& loc = RWLocale::global(), const RWZone& = RWZone::local()) const;
Returns the date and time as a string, formatted by the optional locale argument. The function defaults to using the RWLocale global locale.
Formats are as defined in the C99 Standard C Library function strftime(), explained in the description for RWLocale.
RWCString asString(const char* format, const RWLocale& loc = RWLocale::global() const RWZone& = RWZone::local()) const;
Returns the date and time as a string, formatted by the optional locale argument. The function defaults to using the RWLocale global locale.
Formats are as defined in the C99 Standard C Library function strftime(), explained in the description for RWLocale.
RWCString asString(Format f,
const RWLocale& loc = RWLocale::global(),
const RWZone& = RWZone::local()) const;
Returns the date and time as a string, using the specified format.
Currently supports the ISO 8601 format. This format is numeric and locale-neutral, and as such does not use the RWLocale argument. For more information, see Section 3.3, "International Standards for Dates and Times," in the Essential Tools Module User's Guide.
bool between(const RWDateTime& a, const RWDateTime& b) const;
Returns true if self is between a and b, inclusive.
RWSpace binaryStoreSize() const;
Returns the number of bytes necessary to store the object using the global function:
RWFile& operator<<(RWFile&, const RWDateTime&);
int compareTo(const RWDateTime& d) const;
Compares self to the RWDateTime referenced by d and returns:
0 if self == d; 1 if self > d; -1 if self < d.
int compareTo(const RWDateTime* d) const;
Compares self to the RWDateTime pointed to by d and returns:
0 if self == *d; 1 if self > *d; -1 if self < *d.
unsigned correctedJulian() const;
Returns the value of the Julian day number. This value is one day less than the value of RWDateTime::julian() if the time is before noon UTC (GMT).
NOTE -- The method correctedJulian() is the only RWDateTime method that uses the original Julian day number, instead of the Modified Julian day number.
unsigned day(const RWZone& = RWZone::local()) const;
Returns the day of the year (1-366) for this date. Default for optional time zone argument is local.
unsigned dayGMT() const;
Returns the day of the year (1-366) for this date relative to UTC (GMT).
unsigned dayOfMonth(const RWZone& = RWZone::local()) const;
Returns the day of the month (1-31) for this date. Default for optional time zone argument is local.
unsigned dayOfMonthGMT();
Returns the day of the month (1-31) for this date relative to UTC (GMT).
RWDateTime& decrementDay(const rwint64 day);
Decrements the classes' milliseconds data member by d*RWDateTime::millisecsInDay, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
RWDateTime& decrementHour(const rwint64 hour);
Decrements the classes' milliseconds data member by h*RWDateTime::millisecsInHour, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
RWDateTime&
decrementMillisecond(const rwint64 msec);
Decrements the classes' milliseconds data member by msec, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
RWDateTime& decrementMinute(const rwint64 minute);
Decrements the classes' milliseconds data member by m*RWDateTime::millisecsInMin, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
RWDateTime& decrementSecond((const rwint64 second);
Decrements the classes' milliseconds data member by s*RWDateTime::millisecsInSec, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
NOTE -- The decrement operations can cause RWDateTime to cross a Daylight Saving Time boundary; if so, the returned RWDateTime will have a daylight-saving offset.
void extract(struct tm* tmbuf, const RWZone& = RWZone::local()) const;
Returns with the struct tm argument filled out completely. Note that the encoding for months and days of the week used in struct tm differs from that used elsewhere in RWDateTime. If the date is a sentinel, the function throws an exception of type RWInternalErr.
void extractGMT(struct tm* tmbuf) const;
Returns with the struct tm argument filled out completely, relative to UTC (GMT). Note that the encoding for months and days of the week used in struct tm differs from that used elsewhere in RWDateTime. If the date is a sentinel, the function throws an exception of type RWInternalErr.
unsigned firstDayOfMonth(unsigned mon, const RWZone& = RWZone::local()) const;
Returns the day of the year (1-366) corresponding to the first day of mon in this RWDateTime's year. Default for optional time zone argument is local.
unsigned firstDayOfMonth(const RWZone& = RWZone::local()) const;
Returns the day of the year (1-366) corresponding to the first day of this RWDateTime's month and year.
unsigned hash() const;
Returns a suitable hashing value.
unsigned hour(const RWZone& = RWZone::local()) const;
Returns the hour relative to the time zone specified. Default for optional time zone argument is local.
unsigned hourGMT() const;
Returns the hour relative to UTC (GMT).
RWDateTime& incrementDay(const rwint64 day);
Increments the classes' milliseconds data member by d*RWDateTime::millisecsInDay, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
RWDateTime& incrementHour(const rwint64 hour);
Increments the classes' milliseconds data member by h*RWDateTime::millisecsInHour, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
RWDateTime&
incrementMillisecond(const rwint64 msec);
Increments the classes' milliseconds data member by msec, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
RWDateTime& incrementMinute(const rwint64 minute);
Increments the classes' milliseconds data member by m*RWDateTime::millisecsInMin, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
RWDateTime& incrementSecond(const rwint64 second);
Increments the classes' milliseconds data member by s*RWDateTime::millisecsInSec, then returns self. Note: if this operation results in crossing a DST boundary in the instance's time zone, outputting the date will present with a DST offset as well.
NOTE -- The increment operations can cause RWDateTime to cross a Daylight Saving Time boundary; if so, the returned RWDateTime will have a daylight-saving offset.
bool isDST(const RWZone& = RWZone::local()) const;
Returns true if self is during daylight saving time in the time zone given by zone, false otherwise.
bool isFuture() const;
Returns true if self is a future sentinel.
bool isInvalid() const;
Returns true if self is an invalid sentinel.
bool isNull() const;
Returns true if self is a null sentinel.
bool isPast() const;
Returns true if self is a past sentinel.
bool isSentinel() const;
Returns true if self is a sentinel of any kind.
bool isValid() const;
Returns true if self represents an actual time or is the null sentinel, false otherwise.
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. The Essential Tools Module User's Guide provides more information.
unsigned julian() const;
Returns the value of the Modified Julian day number.
void julian(unsigned j);
Sets the value of the Modified Julian day number to j.
double julianDay() const;
Returns the value of the current date and time as a Modified Julian day number. The integer/whole number part of the double indicates the day, and the fractional part indicates the time. For example, the Modified Julian day number for 1/1/1901 is 2415386. Since Modified Julian days start at midnight GMT, 12 a.m. is 2415386.5 and 6 p.m. is 2415386.75 (these values are computed for Greenwich meridian - a different timezone modifies the result of julianDay).
void julianDay(double j);
Sets the value of the date and time to the Modified Julian day number j. The integer/whole number part of the double indicates the day, and the fractional part indicates the time. For example, the Julian day number for 1/1/1901 is 2415386. Since Julian days start at midnight GMT, 12 a.m. is 2415386.5 and 6 p.m. is 2415386.75 (these values are interpreted differently in RWDateTime objects that have different timezones).
bool leap(const RWZone& = RWZone::local()) const;
Returns true if self is a leap year relative to the RWZone argument.
bool leapGMT();
Returns true if self is a leap year relative to UTC (GMT).
RWDateTime max(const RWDateTime& t) const;
Returns the later RWDateTime of self or t.
unsigned milliSecond() const;
Returns the millisecond part of self.
rwint64 milliSeconds() const;
Returns the number of milliseconds since 00:00:00:000 January 1, 1901 UTC.
RWDateTime min(const RWDateTime& t) const;
Returns the earlier RWDateTime of self or t.
unsigned minute(const RWZone& = RWZone::local()) const;
Returns the minute, adjusted to the time zone specified.
unsigned minuteGMT() const;
Returns the minute relative to UTC (GMT).
unsigned month(const RWZone& = RWZone::local()) const;
Returns the month (1-12) for this date. Default for optional time zone argument is local.
unsigned monthGMT() const;
Returns the month (1-12) for this date relative to UTC (GMT).
RWCString monthName(const RWLocale loc, const RWZone& = RWZone::local()) const;
Returns the name of the month for this date, according to the optional locale argument. The function defaults to using the RWLocale global locale.
RWDateTime next(unsigned dayNum, const RWZone& = RWZone::local()) const;
Returns the date of the next day of the week, where Monday = 1, ..., Sunday = 7. The variable dayNum must be between 1 and 7, inclusive. Default for optional time zone argument is local.
RWDateTime next(const char* dayName, const RWLocale loc = RWLocale::global(); const RWZone& = RWZone::local()) const;
Returns the date of the next dayName (for example, the date of the next Monday). The weekday name is interpreted according to the optional locale argument.
RWDateTime previous(unsigned dayNum, const RWZone& = RWZone::local()) const;
Returns the date of the previous numbered day of the week, where Monday = 1, ..., Sunday = 7. The variable dayNum must be between 1and 7, inclusive. Default for optional time zone argument is local.
RWDateTime previous(const char* dayName,
const RWLocale& loc = RWLocale::global(),
const RWZone& = RWZone::local()const;
Returns the day of the previous dayName; for example, the date of the previous Monday. The weekday name is interpreted according to the optional locale argument. The function defaults to using the RWLocale global locale.
std::istream& readDate(std::istream& is);
Reads a full line and converts to a date according to the locale imbued on the stream. The member function isValid() must be used to test whether the results are a valid date.
std::istream& readTime(std::istream& is);
Reads a full line and convert it to a time according to the locale imbued on the stream. The member function isValid() must be used to test whether the results are a valid time.
void restoreFrom(RWFile&);
Restores an instance of RWDateTime from a reference to an RWFile into which an instance has been persisted using the method RWDateTime::saveOn(RWFile&) const.
void restoreFrom(RWvistream&);
Restores an instance of RWDateTime from a reference to a virtual stream into which an instance has been persisted using the method RWDateTime::saveOn(RWvostream&) const.
void saveOn(RWFile&) const;
Saves an instance of RWDateTime to the indicated RWFile object reference. The RWDateTime can be restored using RWDateTime::restoreFrom(RWFile&).
void saveOn(RWvostream&) const;
Saves an instance of RWDateTime to the indicated virtual stream. The RWDateTime can be restored using RWDateTime::restoreFrom(RWvistream&).
unsigned second() const;
Returns the second; local time or UTC (GMT).
RWDate toRWDate(const RWZone& = RWZone::local()) const;
Converts self to an RWDate.
RWTime toRWTime() const;
NOTE -- This method is deprecated and no longer supported, as RWTime is deprecated.
Converts self to an RWTime.
unsigned weekDay(const RWZone& = RWZone::local()) const;
Returns the number of the day of the week for this date, where Monday = 1, ..., Sunday = 7.
unsigned weekDayGMT() const;
Returns the number of the day of the week for this date relative to UTC (GMT).
RWCString weekDayName(const RWLocale& loc = RWLocale::global(), const RWZone& = RWZone::local()) const;
Returns the name of the day of the week for this date, according to the optional locale argument. The function defaults to using the RWLocale global locale.
std::ostream& writeDate(std::ostream& os);
Outputs the date on the std::ostream os, according to the locale imbued on the stream.
std::ostream& writeTime(std::ostream& os);
Outputs the time on the std::ostream os, according to the locale imbued on the stream.
unsigned year(const RWZone& = RWZone::local()) const;
Returns the year of self. Default for optional time zone argument is local.
unsigned yearGMT() const;
Returns the year of self relative to UTC (GMT).
static RWDateTime beginDST(unsigned year, const RWZone& = RWZone::local());
Returns the start of daylight saving time (DST) for the given year, in the given time zone. Returns an "invalid" time if DST is not observed in that year and zone.
static unsigned dayOfWeek(const char* day, const RWLocale& loc = RWLocale::global());
Returns the number of the day of the week corresponding to the given dayName, where Monday = 1, ..., Sunday = 7. Names are interpreted according to the optional locale argument. The function defaults to using the RWLocale global locale.
static unsigned daysInMonthYear(unsigned month, unsigned year);
Returns the number of days in a given month and year. Returns 0 if month is not between 1 and 12 inclusive.
static unsigned daysInYear(unsigned year);
Returns the number of days in a given year.
static bool dayWithinMonth(unsigned month, unsigned day, unsigned year) ;
Returns true if a day (1-31) is within a given month in a given year.
static RWDateTime endDST(unsigned year, const RWZone& = RWZone::local());
Returns the end of daylight saving time for the given year, in the given time zone. Returns an "invalid time" if DST is not observed in that year and zone.
static unsigned hash(const RWDateTime& dt);
Returns the hash value of dt as returned by dt.hash().
static unsigned indexOfMonth(const char* month, const RWLocale& loc = RWLocale::global());
Returns a number between 1 and 12 corresponding to the given month name. Returns 0 for no match. Months are interpreted by the optional locale argument. The function defaults to using the RWLocale global locale.
static bool leapYear(unsigned year);
Returns true if a given year is a leap year.
static RWCString nameOfMonth(unsigned monthNum, const RWLocale& loc = RWLocale::global());
Returns the name of month, where January = 1, ..., December = 12. Months are interpreted by the optional locale argument. The function defaults to using the RWLocale global locale.
static RWDateTime now();
Returns current date and time.
static RWDateTime userSentinel(int n);
Returns user-defined sentinel number n. Throws RWBoundsErr if the argument is outside the range 0 to 127.
static RWCString weekDayName(unsigned dayNum, const RWLocale& loc = RWLocale::global());
Returns the name of the day of the week dayNum where Monday = 1, ..., Sunday = 7. Days are interpreted by the optional locale argument. The function defaults to using the RWLocale global locale.
rwint64 operator-(const RWDateTime &dt1, const RWDateTime &dt2);
Returns the number of milliseconds between dt1 and dt2. Throws RWInternalErr if either dt1 or dt2 is a sentinel.
bool operator<(const RWDateTime& d1, const RWDateTime& d2);
Returns true if d1 is before d2.
bool operator<=(const RWDateTime& d1, const RWDateTime& d2);
Returns true if d1 is before or the same as d2.
bool operator>(const RWDateTime& d1, const RWDateTime& d2);
Returns true if d1 is after d2.
bool operator>=(const RWDateTime& d1, const RWDateTime& d2);
Return true if d1 is after or the same as d2.
bool operator==(const RWDateTime& d1, const RWDateTime& d2);
Returns true if d1 is the same as d2.
bool operator!=(const RWDateTime& d1, const RWDateTime& d2);
Returns true if d1 is not the same as d2.
RWDateTime operator+(const RWDateTime& d, rwint64 s); RWDateTime operator+(rwint64 s, const RWDateTime& d);
Returns the date s milliseconds in the future from the date d.
RWDateTime operator-(const RWDateTime& d, rwint64 s);
Returns the date s milliseconds in the past from d.
std::ostream& operator<<(std::ostream& s, const RWDateTime& dt);
Outputs the date and time stored in dt on std::ostream s, according to the locale imbued on the stream.
std::istream& operator>>(std::istream& s, RWDateTime& dt);
Reads dt from std::istream s. The function reads one full line, and the string it contains is converted according to the locale imbued on the stream. The function RWDateTime::isValid() must be used to test whether the results are a valid date.
RWvostream& operator<<(RWvostream&, const RWDateTime& dt); RWFile& operator<<(RWFile&,const RWDateTime& dt);
Saves dt to a virtual stream or RWFile, respectively.
RWvistream& operator>>(RWvistream&, RWDateTime& dt); RWFile& operator>>(RWFile&, RWDateTime& dt);
Restores dt from a virtual stream or RWFile, respectively, replacing the previous contents of dt.
RWvistream& operator>>(RWvistream&, RWDateTime*& dt); RWFile& operator>>(RWFile&, RWDateTime*& dt);
Restores an RWDateTime from a virtual stream or RWFile, respectively, by allocating an RWDateTime on the heap and restoring its state.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, 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.