SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches

Represents a date stored as a Julian day number. More...

#include <rw/rwdate.h>

Inheritance diagram for RWDate:
RWCollectableDate

Public Member Functions

 RWDate ()
 
 RWDate (const RWCString &str, const RWLocale &loc=RWLocale::global())
 
 RWDate (const RWDate &d)
 
 RWDate (const RWTime &t, const RWZone &zone=RWZone::local())
 
 RWDate (const RWTimeTuple &tt)
 
 RWDate (const RWTimeTupleOffset &tt)
 
 RWDate (const struct tm *tmbuf)
 
 RWDate (std::istream &s, const RWLocale &loc=RWLocale::global())
 
 RWDate (unsigned day, const char *month, unsigned year, const RWLocale &loc=RWLocale::global())
 
 RWDate (unsigned day, unsigned month, unsigned year)
 
 RWDate (unsigned day, unsigned year)
 
 RWDate (unsigned jd)
 
 RWDate (unsigned long jd)
 
RWCString asString (char format='x', const RWLocale &loc=RWLocale::global()) const
 
RWCString asString (const char *format, const RWLocale &loc=RWLocale::global()) const
 
bool between (const RWDate &a, const RWDate &b) const
 
RWspace binaryStoreSize () const
 
int compareTo (const RWDate *d) const
 
unsigned day () const
 
unsigned dayOfMonth () const
 
void extract (struct tm *tmbuf) const
 
unsigned firstDayOfMonth () const
 
unsigned firstDayOfMonth (unsigned month) const
 
unsigned hash () const
 
bool isValid () const
 
unsigned julian () const
 
void julian (unsigned j)
 
bool leap () const
 
RWDate max (const RWDate &dt) const
 
RWDate min (const RWDate &dt) const
 
unsigned month () const
 
RWCString monthName (const RWLocale &loc=RWLocale::global()) const
 
RWDate next (const char *dayName, const RWLocale &loc=RWLocale::global()) const
 
RWDate next (unsigned dayNum) const
 
RWDateoperator++ ()
 
RWDate operator++ (int)
 
RWDateoperator+= (unsigned s)
 
RWDateoperator-- ()
 
RWDate operator-- (int)
 
RWDateoperator-= (unsigned s)
 
RWDateoperator= (const RWDate &d)
 
RWDate previous (const char *dayName, const RWLocale &loc=RWLocale::global()) const
 
RWDate previous (unsigned dayNum) const
 
unsigned weekDay () const
 
RWCString weekDayName (const RWLocale &loc=RWLocale::global()) const
 
unsigned year () const
 

Static Public Member Functions

static unsigned dayOfWeek (const char *dayName, const RWLocale &loc=RWLocale::global())
 
static unsigned daysInMonthYear (unsigned month, unsigned year)
 
static unsigned daysInYear (unsigned year)
 
static bool dayWithinMonth (unsigned month, unsigned day, unsigned year)
 
static unsigned hash (const RWDate &d)
 
static unsigned indexOfMonth (const char *monthName, const RWLocale &loc=RWLocale::global())
 
static unsigned jday (unsigned month, unsigned day, unsigned year)
 
static bool leapYear (unsigned year)
 
static RWCString nameOfMonth (unsigned monNum, const RWLocale &loc=RWLocale::global())
 
static RWDate now ()
 
static RWCString weekDayName (unsigned day, const RWLocale &loc=RWLocale::global())
 

Friends

bool operator!= (const RWDate &d1, const RWDate &d2)
 
RWDate operator+ (const RWDate &dt, unsigned dd)
 
RWDate operator+ (unsigned dd, const RWDate &dt)
 
unsigned operator- (const RWDate &d1, const RWDate &d2)
 
RWDate operator- (const RWDate &dt, unsigned dd)
 
bool operator< (const RWDate &d1, const RWDate &d2)
 
std::ostream & operator<< (std::ostream &s, const RWDate &d)
 
bool operator<= (const RWDate &d1, const RWDate &d2)
 
bool operator== (const RWDate &d1, const RWDate &d2)
 
bool operator> (const RWDate &d1, const RWDate &d2)
 
bool operator>= (const RWDate &d1, const RWDate &d2)
 
std::istream & operator>> (std::istream &s, RWDate &t)
 
class RWTime
 

Related Symbols

(Note that these are not member symbols.)

RWFileoperator<< (RWFile &file, const RWDate &date)
 
RWvostreamoperator<< (RWvostream &str, const RWDate &date)
 
RWFileoperator>> (RWFile &file, RWDate &date)
 
RWvistreamoperator>> (RWvistream &str, RWDate &date)
 

Detailed Description

Class RWDate represents a date, stored as a Julian day number. The member function isValid() can be used to determine whether an RWDate is a valid date. For example, isValid() would return false for the date 29 February 1991 because 1991 is not a leap year. See the chapter on date and time classes in the Essential Tools Module User's Guide.

Note
RWDate instances can be converted to and from the C Standard Library type struct tm defined in <time.h>.

We recommend creating programs that use four-digit year specifiers. For more information, see the section on RWDate in the Essential Tools Module User's Guide.

Note that because the default constructor for this class creates an instance holding the current date, constructing a large array of RWDate may be slow.

RWDate v[5000]; // Figures out the current date 5000 times
Represents a date stored as a Julian day number.
Definition rwdate.h:112

When using the Essential Tools Module template collections, consider the following:

// Figures out the current date just once:
RWDate()
Definition rwdate.h:117
Maintains a collection of values implemented as a vector.
Definition tvordvec.h:108

Thanks to the smart allocation scheme of the standard collections, the above declaration results in only one call to the default constructor, followed by 5000 invocations of the copy constructor. In the case of RWDate, the copy constructor amounts to an assignment of one int to another, resulting in faster creation than the simple array.

Synopsis
#include <rw/rwdate.h>
RWDate a; // Construct today's date
Persistence
Simple
Example
#include <rw/rwdate.h>
int main() {
// ENIAC start date
RWDate d(14, "February", 1945);
// Today
RWDate today;
std::cout << d.asString("%A, %B %d 19%y")
<< " was the day the ENIAC computer was\nfirst turned on. "
<< today - d << " days have gone by since then. "
<< std::endl;
return 0;
}
RWCString asString(char format='x', const RWLocale &loc=RWLocale::global()) const

Constructor & Destructor Documentation

◆ RWDate() [1/13]

RWDate::RWDate ( )
inline

Default constructor. Constructs an RWDate with the present date.

◆ RWDate() [2/13]

RWDate::RWDate ( unsigned jd)
inline

Constructs a date from the Julian Day number jd. Note that it is possible to construct a valid RWDate that represents a day previous to the beginning of the Gregorian calendar for some locality. Rogue Wave doesn't know the specifics for your locality, so will not enforce an arbitrary cutoff for "validity."

◆ RWDate() [3/13]

RWDate::RWDate ( unsigned long jd)
explicit
Deprecated
As of SourcePro 2017, use RWDate(unsigned) instead.

Constructs a date from the Julian Day number jd. Note that it is possible to construct a valid RWDate that represents a day previous to the beginning of the Gregorian calendar for some locality. Rogue Wave doesn't know the specifics for your locality, so will not enforce an arbitrary cutoff for "validity."

◆ RWDate() [4/13]

RWDate::RWDate ( unsigned day,
unsigned year )

Constructs an RWDate with a given day of the year and a given year. The member function isValid() can be used to test whether the results are a valid date.

◆ RWDate() [5/13]

RWDate::RWDate ( unsigned day,
const char * month,
unsigned year,
const RWLocale & loc = RWLocale::global() )

Constructs an RWDate with the given day of the month, month, and year. The locale argument is used to convert the month name. Days should be 1-31, months may be specified as (for example): "January", "JAN", or "Jan", and the year may be specified as (for example) 1990, or 90. The member function isValid() can be used to test whether the results are a valid date.

◆ RWDate() [6/13]

RWDate::RWDate ( unsigned day,
unsigned month,
unsigned year )

Constructs an RWDate with the given day of the month, month of the year, and year. Days should be 1-31, months should be 1-12, and the year may be specified as (for example) 1990, or 90. The member function isValid() can be used to test whether the results are a valid date.

◆ RWDate() [7/13]

RWDate::RWDate ( std::istream & s,
const RWLocale & loc = RWLocale::global() )
inline

Constructs a date whereby the locale argument reads and converts a full line to a date. Because RWLocale cannot rigorously check date input, the member function isValid() must be used to test whether the results are a valid date.

◆ RWDate() [8/13]

RWDate::RWDate ( const RWCString & str,
const RWLocale & loc = RWLocale::global() )

Converts the string str to a date. Because RWLocale cannot rigorously check date input, the member function isValid() must be used to test whether the results are a valid date.

◆ RWDate() [9/13]

RWDate::RWDate ( const RWTime & t,
const RWZone & zone = RWZone::local() )

Constructs an RWDate from an RWTime. The time zone used defaults to local. The member function isValid() must be used to test whether the results are a valid date.

◆ RWDate() [10/13]

RWDate::RWDate ( const struct tm * tmbuf)

Constructs an RWDate from the contents of the struct tm argument members tm_year, tm_mon, and tm_mday. Note that the numbering of months and years used in struct tm differs from that used for RWDate operations. struct tm is declared in the C Standard Library include file <time.h>.

◆ RWDate() [11/13]

RWDate::RWDate ( const RWTimeTuple & tt)
explicit

Constructs an RWDateTime using the RWTimeTuple tt. Only the year, month and day of month values are referenced. All other members of tt are ignored.

If the tt represents a date prior to -4713-11-25, an invalid RWDate instance is constructed.

In 32-bit builds, if the tt represents a date after 11754509-07-22, and invalid RWDate instance is constructed.

◆ RWDate() [12/13]

RWDate::RWDate ( const RWTimeTupleOffset & tt)
explicit

Constructs an RWDateTime using the RWTimeTupleOffset tt. Only the year, month and day of month values are referenced. All other members of tt are ignored.

If the tt represents a date prior to -4713-11-25, an invalid RWDate instance is constructed.

In 32-bit builds, if the tt represents a date after 11754509-07-22, and invalid RWDate instance is constructed.

◆ RWDate() [13/13]

RWDate::RWDate ( const RWDate & d)
inline

Copy constructor.

Member Function Documentation

◆ asString() [1/2]

RWCString RWDate::asString ( char format = 'x',
const RWLocale & loc = RWLocale::global() ) const

Returns the date as a string, formatted by the optional RWLocale argument. Formats are as defined in the C++ Standard Library function std::strftime(), explained in the description for RWLocale.

◆ asString() [2/2]

RWCString RWDate::asString ( const char * format,
const RWLocale & loc = RWLocale::global() ) const

Returns the date as a string, formatted by the optional RWLocale argument. Formats are as defined in the C++ Standard Library function std::strftime(), explained in the description for RWLocale.

◆ between()

bool RWDate::between ( const RWDate & a,
const RWDate & b ) const
inline

Returns true if this RWDate is between a and b, inclusive.

◆ binaryStoreSize()

RWspace RWDate::binaryStoreSize ( ) const
inline

Returns the number of bytes necessary to store the object using the global function

friend std::ostream & operator<<(std::ostream &s, const RWDate &d)
Represents an abstraction of a filesystem regular file.
Definition rwfile.h:68

◆ compareTo()

int RWDate::compareTo ( const RWDate * d) const

Compares self to the RWDate pointed to by d and returns:

0 if self == *d;

1 if self > *d;

-1 if self < *d.

◆ day()

unsigned RWDate::day ( ) const

Returns the day of the year (1-366) for this date.

◆ dayOfMonth()

unsigned RWDate::dayOfMonth ( ) const

Returns the day of the month (1-31) for this date.

◆ dayOfWeek()

unsigned RWDate::dayOfWeek ( const char * dayName,
const RWLocale & loc = RWLocale::global() )
inlinestatic

Returns the number of the day of the week corresponding to the given dayName ( Monday = 1, ..., Sunday = 7). Names are interpreted by the optional RWLocale argument. Returns 0 if no match is found.

◆ daysInMonthYear()

static unsigned RWDate::daysInMonthYear ( unsigned month,
unsigned year )
static

Returns the number of days in a given month and year. Returns 0 if month is not between 1 and 12, inclusive.

◆ daysInYear()

static unsigned RWDate::daysInYear ( unsigned year)
static

Returns the number of days in a given year.

◆ dayWithinMonth()

static bool RWDate::dayWithinMonth ( unsigned month,
unsigned day,
unsigned year )
static

Returns true if a day (1-31) is within a given month in a given year, otherwise false.

◆ extract()

void RWDate::extract ( struct tm * tmbuf) const

Returns with the struct tm argument filled out completely, with the time members set to 0 and tm_isdst set to -1. Note that the encoding for months and days of the week used in struct tm differs from that used elsewhere in RWDate. If the date is invalid, all fields are set to -1.

◆ firstDayOfMonth() [1/2]

unsigned RWDate::firstDayOfMonth ( ) const
inline

Returns the day of the year (1-366) corresponding to the first day of the month and year for this RWDate.

◆ firstDayOfMonth() [2/2]

unsigned RWDate::firstDayOfMonth ( unsigned month) const

Returns the day of the year (1-366) corresponding to the first day of the month month (1-12) of the year for this RWDate.

◆ hash() [1/2]

unsigned RWDate::hash ( ) const

Returns a suitable hashing value.

◆ hash() [2/2]

static unsigned RWDate::hash ( const RWDate & d)
static

Returns the hash value of d as returned by d.hash().

◆ indexOfMonth()

unsigned RWDate::indexOfMonth ( const char * monthName,
const RWLocale & loc = RWLocale::global() )
inlinestatic

Returns the number of the month (1-12) corresponding to the given monthName. Returns 0 for no match.

◆ isValid()

bool RWDate::isValid ( ) const
inline

Returns true if this is a valid date, false otherwise.

◆ jday()

static unsigned RWDate::jday ( unsigned month,
unsigned day,
unsigned year )
static

Returns the Julian day corresponding to the given month (1-12), day (1-31) and year. Returns zero (0) if the date is invalid.

◆ julian() [1/2]

unsigned RWDate::julian ( ) const
inline

Returns the value of the Julian day number.

◆ julian() [2/2]

void RWDate::julian ( unsigned j)
inline

Changes the value of the Julian day number to j.

◆ leap()

bool RWDate::leap ( ) const
inline

Returns true if the year of this RWDate is a leap year, otherwise false.

◆ leapYear()

static bool RWDate::leapYear ( unsigned year)
static

Returns true if a given year is a leap year, otherwise false.

◆ max()

RWDate RWDate::max ( const RWDate & dt) const
inline

Returns the later date of self or dt.

◆ min()

RWDate RWDate::min ( const RWDate & dt) const
inline

Returns the earlier date of self or dt.

◆ month()

unsigned RWDate::month ( ) const

Returns the month (1-12) for this date.

◆ monthName()

RWCString RWDate::monthName ( const RWLocale & loc = RWLocale::global()) const
inline

Returns the name of the month for this date, according to the optional RWLocale argument.

◆ nameOfMonth()

static RWCString RWDate::nameOfMonth ( unsigned monNum,
const RWLocale & loc = RWLocale::global() )
static

Returns the name of month monNum ( January = 1, ..., December = 12), formatted for the given locale.

◆ next() [1/2]

RWDate RWDate::next ( const char * dayName,
const RWLocale & loc = RWLocale::global() ) const

Returns the date of the next dayName (for example, the date of the previous Monday) The weekday name is interpreted according to the optional RWLocale argument.

◆ next() [2/2]

RWDate RWDate::next ( unsigned dayNum) const

Returns the date of the next numbered day of the week, where Monday = 1, ..., Sunday = 7. The variable dayNum must be between 1 and 7, inclusive.

◆ now()

static RWDate RWDate::now ( )
static

Returns today's date.

◆ operator++() [1/2]

RWDate & RWDate::operator++ ( )
inline

Prefix increment operator. Adds one day to self, returning the result.

◆ operator++() [2/2]

RWDate RWDate::operator++ ( int )
inline

Postfix increment operator. Adds one day to self, returning the initial value.

◆ operator+=()

RWDate & RWDate::operator+= ( unsigned s)
inline

Adds s days to self, returning self.

◆ operator--() [1/2]

RWDate & RWDate::operator-- ( )
inline

Prefix decrement operator. Subtracts one day from self, returning the result.

◆ operator--() [2/2]

RWDate RWDate::operator-- ( int )
inline

Postfix decrement operator. Subtracts one day from self, returning the initial value.

◆ operator-=()

RWDate & RWDate::operator-= ( unsigned s)
inline

Subtracts s days from self, returning self.

◆ operator=()

RWDate & RWDate::operator= ( const RWDate & d)
inline

Assignment operator.

◆ previous() [1/2]

RWDate RWDate::previous ( const char * dayName,
const RWLocale & loc = RWLocale::global() ) const

Returns the date of the previous dayName (for example, the date of the previous Monday) The weekday name is interpreted according to the optional RWLocale argument.

◆ previous() [2/2]

RWDate RWDate::previous ( unsigned dayNum) const

Returns the date of the previous numbered day of the week, where Monday = 1, ..., Sunday = 7. The variable dayNum must be between 1 and 7, inclusive.

◆ weekDay()

unsigned RWDate::weekDay ( ) const

Returns the number of the day of the week for this date, where Monday = 1, ..., Sunday = 7.

◆ weekDayName() [1/2]

RWCString RWDate::weekDayName ( const RWLocale & loc = RWLocale::global()) const
inline

Returns the name of the day of the week for this date, according to the optional RWLocale argument. The function defaults to using the RWLocale global locale.

◆ weekDayName() [2/2]

static RWCString RWDate::weekDayName ( unsigned day,
const RWLocale & loc = RWLocale::global() )
static

Returns the name of the day of the week day ( Monday = 1, ..., Sunday = 7), formatted for the given locale. The function defaults to the RWLocale global locale.

◆ year()

unsigned RWDate::year ( ) const

Returns the year of this date.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const RWDate & d1,
const RWDate & d2 )
friend

Returns true if the date d1 is not the same as d2, otherwise false.

◆ operator+ [1/2]

RWDate operator+ ( const RWDate & dt,
unsigned dd )
friend

Returns the date dd days in the future from the date dt.

◆ operator+ [2/2]

RWDate operator+ ( unsigned dd,
const RWDate & dt )
friend

Returns the date dd days in the future from the date dt.

◆ operator- [1/2]

unsigned operator- ( const RWDate & d1,
const RWDate & d2 )
friend

If d1 > d2, returns the number of days between d1 and d2. Otherwise, the result is implementation-defined.

◆ operator- [2/2]

RWDate operator- ( const RWDate & dt,
unsigned dd )
friend

Returns the date dd days in the past from dt.

◆ operator<

bool operator< ( const RWDate & d1,
const RWDate & d2 )
friend

Returns true if the date d1 is before d2, otherwise false.

◆ operator<<() [1/3]

RWFile & operator<< ( RWFile & file,
const RWDate & date )
related

Saves the date into date from the RWFile file.

◆ operator<<() [2/3]

RWvostream & operator<< ( RWvostream & str,
const RWDate & date )
related

Saves the date into date from the virtual stream str.

◆ operator<< [3/3]

std::ostream & operator<< ( std::ostream & s,
const RWDate & d )
friend

Outputs the date d on ostream s, according to the locale imbued in the stream (see class RWLocale), or by RWLocale::global() if none.

◆ operator<=

bool operator<= ( const RWDate & d1,
const RWDate & d2 )
friend

Returns true if the date d1 is before or the same as d2, otherwise false.

◆ operator==

bool operator== ( const RWDate & d1,
const RWDate & d2 )
friend

Returns true if the date d1 is the same as d2, otherwise false.

◆ operator>

bool operator> ( const RWDate & d1,
const RWDate & d2 )
friend

Returns true if the date d1 is after d2, otherwise false.

◆ operator>=

bool operator>= ( const RWDate & d1,
const RWDate & d2 )
friend

Returns true if the date d1 is after or the same as d2, otherwise false.

◆ operator>>() [1/3]

RWFile & operator>> ( RWFile & file,
RWDate & date )
related

Restores the date into date from the RWFile file, replacing the previous contents of date.

◆ operator>>() [2/3]

RWvistream & operator>> ( RWvistream & str,
RWDate & date )
related

Restores the date into date from the virtual stream str, replacing the previous contents of date.

◆ operator>> [3/3]

std::istream & operator>> ( std::istream & s,
RWDate & t )
friend

Reads t from std::istream s. One full line is read, and the string contained is converted according to the locale imbued in the stream (see class RWLocale), or by RWLocale::global() if none. The function RWDate::isValid() must be used to test whether the results are a valid date.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.