An ** RWDateTime** may be constructed in several ways. Unlike

For example, to construct an ** RWDateTime** with today's date and current time, use the following:

RWDateTime dt(RWDateTime::setCurrentTime); // today, current time

An ** RWDateTime** can also be constructed from a given date and/or a given time. Or you can use an

RWDateTime dt("June 2, 1952", RWDateTime::setDate, RWLocale::global()); // sets date to 6/2/52, 00:00:00

Similarly, to construct an ** RWDateTime** for a given time:

RWDateTime dt("10:00 pm", RWDateTime::setTime, RWLocale::global()); // sets date and time to today, 22:00:00

Finally, to construct an ** RWDateTime** for a given date and time, you can use the following techniques. Note that when you initialize both the day and time, the date precedes the time and the two values are separated by a semicolon.

RWDateTime dt("June 4, 1968; 10:51 am", RWDateTime::setBoth, RWLocale::global()); // 6/4/68, 10:51:00

or

RWDateTime dt(4,6,1968,10,51,0); // 6/4/68, 10:51:00

Class ** RWDateTime** has member functions to compare, store, add, and subtract

For example, here is a code fragment that outputs the hour in local and UTC (GMT) zones, and then the complete local time and date.

RWDateTime dt(RWDateTime::setCurrentTime); cout << dt.dayOfMonth() << endl; // Current day of month cout << dt.hour() << endl; // Local hour cout << dt.hourGMT() << endl; // UTC (GMT) hour dt.writeDate(cout); // Local date dt.writeTime(cout); // Local time cout << dt << endl; // Local time and date

** RWDateTime** has the ability to hold sentinel values that are not necessarily dates, but are convenient to use as comparison values within applications. For example, a "future" sentinel provides a value that represents a date larger than the largest

Table 8 summarizes the responses of ** RWDateTime** operations when applied to various sentinels. The sections that follow Table 8 provide more information about the sentinels.

Operator/Function
| Valid | Null | Invalid | Past/Future | User Sentinel |

Extract Part | Ok | RWTHROW | RWTHROW | RWTHROW | RWTHROW |

Arithmetic | Ok | Propagate to Invalid | Propagate | Propagate Past/Future | Propagate to Invalid |

Relational | Ok | Return False | RWTHROW | Ok | Return False |

asString()/Output | Ok | "NULL" | "#INVALID#" | "#INVALID#" | "#<num>#" |

Read String | Ok | N/A | Ok | N/A | N/A |

Create | Ok | Ok | Ok | Ok | Ok |

The Essential Tools Module includes an ** RWDateTime** with an "invalid" state that can be compared to other

No other operations work, other than persisting the invalid object and using it in comparisons for equality. Arithmetic manipulation of an invalid ** RWDateTime** always results in an invalid

The following examples show several ways to construct an ** RWDateTime** with an invalid state:

// construct dt1 with invalid state: RWDateTime dt1; // construct dt2 with invalid state: RWDateTime dt2(RWDateTime::invalid); // construct dt3 with invalid state: RWDateTime dt3(RWDateTime::invalidSentinel); // construct dt4 with invalid state: RWDateTime dt4(RWDate(29,02,1997));

Sometimes it is convenient to have an ** RWDateTime** that is valid yet holds no specific value. The Essential Tools Module includes the "null" state sentinel for this purpose. You can construct a null

Arithmetic manipulation of a null ** RWDateTime** will result in an invalid

The following examples show how to construct an ** RWDateTime** with a null state, and demonstrate what happens when it is used in an arithmetic operation:

// construct dt1 with null state: RWDateTime dt1(RWDateTime::null); // construct dt2 with null state RWDateTime dt2(RWDateTime::nullSentinel); // attempted arithmetic manipulation: assert(dt2.isValid()); dt2.incrementMillisecond(23); // dt2 set to invalid state assert(dt2.isValid()); // invalid

When sorting and searching for ** RWDateTime** objects it is useful to have sentinels that represent "smaller than the smallest"

** RWDateTime** includes two global static constants to determine the minimum and maximum valid

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 will not change their values, nor cause any error. Attempts to use any part extraction functions (

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

** RWDateTime** also provides for the use of 128 user-defined sentinels numbered 0 through 127. Each of these sentinels behave like the null sentinel for part extraction functions, arithmetic manipulation, and relational operations. The

Here is an example of constructing and using user-defined sentinels:

RWDateTime sent0 = RWDateTime::userSentinel(0); RWDateTime sent1 = RWDateTime::userSentinel(1); std::cout << sent1.asString() << std::endl; // outputs #<1>#

©2004 Copyright Quovadx, Inc. All Rights Reserved.

Rogue Wave and SourcePro are registered trademarks 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.