The Past and Future Sentinels
When sorting and searching for
RWDateTime objects it is useful to have sentinels that represent “smaller than the smallest”
RWDateTime and “larger than the largest”
RWDateTime. The “past” and “future” sentinels are special kinds of invalid sentinels.
RWDateTime includes two global static constants to determine the minimum and maximum valid RWDateTime objects: RWDateTime::minDateTime and RWDateTime::maxDateTime. You can pass these constants to the RWDateTime(rwint64) constructor to create instances of the minimum and maximum RWDateTime as needed, or you can use them to compare directly with the millisecond count returned by RWDateTime::milliSeconds().
The past and future sentinels can be used in any relational operation, and every valid
RWDateTime falls strictly between the past and future sentinels. Arithmetic manipulation of past or future sentinels does not change their values, nor cause any error. Attempts to use any part extraction functions (
day(), month(), extract(), etc.) result in an
RWInternalErr being thrown. The
asString() family of functions always return the string
"#INVALID#" for past and future sentinels.
Here are some examples of constructing and using past and future sentinels:
// construct a past sentinel
RWDateTime past(RWDateTime::pastSentinel);
// construct a future sentinel
RWDateTime future(RWDateTime::futureSentinel);
// construct an RWDateTime holding the largest valid time
RWDateTime maxDT(RWDateTime::maxDateTime);
// construct an RWDateTime holding the smallest valid time
RWDateTime minDT(RWDateTime::minDateTime);
bool a = past < minDT; // a == true
bool b = future > maxDT; // b == true
bool c = minDT.isValid(); // c == true
bool d = maxDT.isValid(); // d == true
bool e = !past.isValid(); // e == true
bool f = !future.isValid(); // f == true