text stringlengths 0 2.2M |
|---|
(void)veryVeryVeryVerbose;
|
cout << "TEST " << __FILE__ << " CASE " << test << endl;
|
// CONCERN: 'BSLS_REVIEW' failures should lead to test failures.
|
bsls::ReviewFailureHandlerGuard reviewGuard(&bsls::Review::failByAbort);
|
switch (test) { case 0: // Zero is always the leading case.
|
case 12: {
|
// --------------------------------------------------------------------
|
// USAGE EXAMPLE
|
// Extracted from component header file.
|
//
|
// Concerns:
|
//: 1 The usage example provided in the component header file compiles,
|
//: links, and runs as shown.
|
//
|
// Plan:
|
//: 1 Incorporate usage example from header into test driver, remove
|
//: leading comment characters, and replace 'assert' with 'ASSERT'.
|
//: (C-1)
|
//
|
// Testing:
|
// USAGE EXAMPLE
|
// --------------------------------------------------------------------
|
if (verbose) cout << endl
|
<< "USAGE EXAMPLE" << endl
|
<< "=============" << endl;
|
///Usage
|
///-----
|
// This section illustrates intended use of this component.
|
//
|
///Example 1: Basic 'bdlt::Iso8601Util' Usage
|
/// - - - - - - - - - - - - - - - - - - - - -
|
// This example demonstrates basic use of one 'generate' function and two
|
// 'parse' functions.
|
//
|
// First, we construct a few objects that are prerequisites for this and the
|
// following example:
|
//..
|
const bdlt::Date date(2005, 1, 31); // 2005/01/31
|
const bdlt::Time time(8, 59, 59, 123); // 08:59:59.123
|
const int tzOffset = 240; // +04:00 (four hours west of UTC)
|
//..
|
// Then, we construct a 'bdlt::DatetimeTz' object for which a corresponding ISO
|
// 8601-compliant string will be generated shortly:
|
//..
|
const bdlt::DatetimeTz sourceDatetimeTz(bdlt::Datetime(date, time),
|
tzOffset);
|
//..
|
// For comparison with the ISO 8601 string generated below, note that streaming
|
// the value of 'sourceDatetimeTz' to 'stdout':
|
//..
|
if (veryVerbose)
|
bsl::cout << sourceDatetimeTz << bsl::endl;
|
//..
|
// produces:
|
//..
|
// 31JAN2005_08:59:59.123000+0400
|
//..
|
// Next, we use a 'generate' function to produce an ISO 8601-compliant string
|
// for 'sourceDatetimeTz', writing the output to a 'bsl::ostringstream', and
|
// assert that both the return value and the string that is produced are as
|
// expected:
|
//..
|
bsl::ostringstream oss;
|
const bsl::ostream& ret =
|
bdlt::Iso8601Util::generate(oss, sourceDatetimeTz);
|
ASSERT(&oss == &ret);
|
const bsl::string iso8601 = oss.str();
|
ASSERT(iso8601 == "2005-01-31T08:59:59.123+04:00");
|
//..
|
// For comparison, see the output that was produced by the streaming operator
|
// above.
|
//
|
// Now, we parse the string that was just produced, loading the result of the
|
// parse into a second 'bdlt::DatetimeTz' object, and assert that the parse was
|
// successful and that the target object has the same value as that of the
|
// original (i.e., 'sourceDatetimeTz'):
|
//..
|
bdlt::DatetimeTz targetDatetimeTz;
|
int rc = bdlt::Iso8601Util::parse(&targetDatetimeTz,
|
iso8601.c_str(),
|
static_cast<int>(iso8601.length()));
|
ASSERT( 0 == rc);
|
ASSERT(sourceDatetimeTz == targetDatetimeTz);
|
//..
|
// Finally, we parse the 'iso8601' string a second time, this time loading the
|
// result into a 'bdlt::Datetime' object (instead of a 'bdlt::DatetimeTz'):
|
//..
|
bdlt::Datetime targetDatetime;
|
rc = bdlt::Iso8601Util::parse(&targetDatetime,
|
iso8601.c_str(),
|
static_cast<int>(iso8601.length()));
|
ASSERT( 0 == rc);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.