beautypg.com

HP Integrity NonStop J-Series User Manual

Page 67

background image

RWDate d(frenchDate, french); // OK // 2

cout << frenchDate << ((d.isValid()) ? " IS " : " IS NOT ")
<< "a valid date (french locale)." << endl << endl;
RWDate bad = RWDate(frenchDate); // 3
cout << frenchDate;
cout << ((bad.isValid() && bad == d) ? " IS " : " IS NOT ")
<< "a valid date (default locale)." << endl << endl;
bad = RWDate(americanDate, french); // 4
cout << americanDate;
cout << ((bad.isValid() && bad == d) ? " IS " : " IS NOT ")
<< "a valid date (french locale)." << endl << endl;
cout << d << endl; // 5
cout << d.asString() << endl; // 6
cout << d.asString('x', french) << endl; // 7
return 0;
}

Here's a line-by-line description of the previous code:

A snapshot is taken of locale fr. This assumes your system supports the locale. Another common
name for this locale is fr_FR.

1.

A date is constructed using the constructor:

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

Note that the second argument month is meaningful only within the context of a locale. In this
case, we are using the locale constructed at line 1. The result is the date known in English as
June 10, 2002.

2.

Here we attempt to construct the same date using the default locale. This locale recognizes C
formatting conventions only. Hence, the date 10 Juin 2002 should be meaningless. Just in case,
though, compare with a known valid date.

3.

For the same reason, constructing a date using United States names with a French locale should
fail. Just in case, though, compare with a known valid date.

4.

The date constructed at line 2 is printed using the default locale, i.e., United States formatting
conventions. The results are:

06/10/25

5.

The date is converted to a string, then printed. Again, the default locale is used. The results are
the same:

06/10/25

6.

The date is converted to a string, this time using the locale constructed at line 1. The results are
now

[5]

:

7.

This manual is related to the following products: