RWCString
Class
RWCString can be found in the Essential Tools Module. It is an industry standard for string manipulation, providing string processing features that are just as efficient as those in C, but far less prone to errors. Its features include memory management, collation, substrings, pattern matching, regular expressions, I/O, tokenizing, and support for multibyte strings.
Class
RWCString has member functions to read, compare, store, restore, concatenate, prefix, and append
RWCStrings and
char*'s. Operators allow access to individual characters, with or without bounds checking.
For a full discussion of the features of this class, please see the
Essential Tools Module User's Guide and the
SourcePro API Reference Guide.
RWDateTime
Class
RWDateTime, also contained in the Essential Tools Module, is the primary class used for dates and times in the DB Interface Module. This class serves as a compact representation for calendar calculations. It shields you from many of the details of programming with time elements, like leap years, and performs conversions to and from conventional calendar formats.
SourcePro DB compatibility is provided to
RWDateTime instances that are initialized to either
RWDateTime::null or a valid date. For a full discussion of the many features of this class, please see the
Essential Tools Module User's Guide and the
SourcePro API Reference Guide.
When
RWDateTime is used to either write or extract data to or from a database, by default it uses the local time zone represented by
RWZone::local(). Methods on
RWDBDatabase and
RWDBConnection allow you to specify a different time zone.
const RWZone* RWDBDatabase::timeZone(const RWZone* zone)
const RWZone& RWDBDatabase::timeZone() const
The first method sets the time zone on the
RWDBDatabase instance, and all
RWDBConnection instances produced by it after the time zone is set. The
RWDBDatabase instance retains a reference to the time zone, hence it is the application's responsibility to ensure that the time zone has a lifetime greater than the
RWDBDatabase instance or any object produced from it. The second method allows you to determine the current setting for this
RWDBDatabase.
const RWZone* RWDBConnection::timeZone(const RWZone* zone)
const RWZone& RWDBConnection::timeZone() const
The first method sets the time zone for the specific
RWDBConnection instance. The
RWDBConnection instance retains a reference to the time zone, hence it is the application's responsibility to ensure that the time zone has a lifetime greater than the
RWDBConnection instance or any object using it. The second method allows you to determine the current setting for this
RWDBConnection.
NOTE >> If the database client you are using provides a time zone setting on its connections, the above methods do not set or get those time zone settings. If you wish to get or set the time zone setting on the database client connection, you can do so by executing the database-specific SQL for getting or setting the time zone using RWDBConnection::executeSql().
Example
The following example shows how
RWDateTime performs date calculations. This code prints out the date January 6, 1990, then calculates and prints the date of the previous Sunday, using the global locale:
#include <rw/db/db.h>
#include <rw/rstream.h>
int
main() {
RWDateTime dd(1990U, 1, 6);
cout << dd.asString() << ", a " << dd.weekDayName() << endl;
RWDateTime prev = dd.previous("Sunday");
cout << "The previous Sunday is: " << prev.asString() << endl;
return 0;
}
Program output:
01/06/90 00:00:00.000, a Saturday
The previous Sunday is: 12/31/89 00:00:00.000
Constructors
An
RWDateTime may be constructed in many ways. For example, you can:
RWDateTime dt(RWDateTime::setCurrentTime);
• Construct an
RWDateTime for a given year, month, and day:
RWDateTime d1(1924U, 1, 24); // Jan.24, 1924
• Construct an
RWDateTime from an
RWDate, supplying hours, minutes, seconds, and milliseconds:
RWDate d(10, 3, 90); // Mar. 10, 1990
RWDateTime dt(d, 1, 30, 30, 100) // Mar. 10, 1990 1:30:30.100
In the first example, we use the enumerated constructor to construct
RWDateTime with current value. If you are constructing an array and must fill in today’s date, you must assign the dates explicitly (see the Essential Tools documentation for more details).
There are many other constructors, including those that use
RWDate or
RWTime in various ways. There are accessors for each component of an
RWDateTime (years, months, days, hours, and so on).
RWDateTime provides powerful localization features which may be accessed and changed via the
RWDateTime interface. Member operators and functions allow a complete range of arithmetic manipulations on date and time values.
Complete information on the capabilities of
RWDateTime can be found in the
Essential Tools Module User's Guide and the
SourcePro API Reference Guide.
RWTimeTuple and RWTimeTupleOffset
Essential Tools Module classes
RWTimeTuple and
RWTimeTupleOffset also represent dates and times and can be used as an alternative to
RWDateTime in some circumstances. These classes store a tuple of each calendar component of a date and time. If you need picosecond precision or don’t need to perform calculations and comparisons of dates, these classes may offer better performance. For more information, see “Date and Time Classes” in the
Essential Tools Module User's Guide.