text
stringlengths
0
2.2M
#ifdef BSLS_PLATFORM_OS_WINDOWS
const char *TIME_ZONE_DIRECTORY = "test\\Asia";
const char *TIME_ZONE_FILE = "test\\Asia\\Bangkok";
#else
const char *TIME_ZONE_DIRECTORY = "test/Asia";
const char *TIME_ZONE_FILE = "test/Asia/Bangkok";
#endif
int rc =
bdls::FilesystemUtil::createDirectories(TIME_ZONE_DIRECTORY, true);
ASSERT(0 == rc);
//..
// Finally we create a file for Bangkok and write the binary time zone data to
// that file.
//..
bsl::ofstream outputFile(TIME_ZONE_FILE, bsl::ofstream::binary);
ASSERT(outputFile.is_open());
outputFile.write(reinterpret_cast<const char *>(ASIA_BANGKOK_DATA),
sizeof(ASIA_BANGKOK_DATA));
outputFile.close();
//..
//
///Example 1: Using a 'baltzo::DataFileLoader' to Load a Zoneinfo File
/// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// In this example we demonstrate how to use a 'baltzo::DataFileLoader' to load
// a time zone data file into a 'baltzo::Zoneinfo' object. First we create
// a 'baltzo::DataFileLoader' object, and configure it with the relative path
// "test" which we created in the prologue example.
//..
baltzo::DataFileLoader loader;
loader.configureRootPath("test");
//..
// Note that 'isRootPathPlausible' will return 'false' for the relative path
// "test" since it does not contain data for the time zone "GMT" so it is
// (correctly) assumed that "test" does not contain a (reasonably complete)
// set of time zone data:
//..
ASSERT(!loader.isRootPathPlausible());
//..
// Next we use the 'dataFilePath' method to verify that 'loader' will
// correctly locate the test data file we've created:
//..
const char *BANGKOK_ID = "Asia/Bangkok";
bsl::string bangkokDataPath;
rc = loader.loadTimeZoneFilePath(&bangkokDataPath, BANGKOK_ID);
ASSERT(0 == rc);
ASSERT(TIME_ZONE_FILE == bangkokDataPath);
//..
// Then we create a 'baltzo::Zoneinfo' and load it using 'loader':
//..
baltzo::Zoneinfo timeZone;
rc = loader.loadTimeZone(&timeZone, BANGKOK_ID);
ASSERT(0 == rc);
//..
// Finally we verify several properties of the timezone: (1) That its
// identifier is "Asia/Bangkok", and (2) it contains two transitions referring
// to three local time descriptors, "LMT" (Local Mean Time), "BMT" (Bangkok
// Mean Time), and "ICT" (Indochina Time):
//..
ASSERT(BANGKOK_ID == timeZone.identifier());
baltzo::Zoneinfo::TransitionConstIterator iterator =
timeZone.beginTransitions();
ASSERT("LMT" == iterator->descriptor().description());
++iterator;
ASSERT("BMT" == iterator->descriptor().description());
++iterator;
ASSERT("ICT" == iterator->descriptor().description());
++iterator;
ASSERT(timeZone.endTransitions() == iterator);
//..
if (verbose) {
timeZone.print(bsl::cout, 1, 3);
}
bdls::FilesystemUtil::remove("test", true);
// TIME_ZONE_DIRECTORY/.. i.e. "test"
} break;
case 6: {
// --------------------------------------------------------------------
// TESTING 'loadTimeZone'
//
// Concerns:
//: 1 'loadTimeZone' correctly loads time-zone information when a valid
//: time zone identifier is specified.
//:
//: 2 'loadTimeZone' returns 'k_UNSUPPORTED_ID' if the specified time
//: zone identifier is invalid.
//:
//: 3 'loadTimeZone' returns a non-zero value different from
//: 'k_UNSUPPORTED_ID' on error reading the specified time-zone file.
//
// Plan:
//: 1 Test that 'loadTimeZone' returns time-zone information when give
//: a valid time zone identifier.
//:
//: 2 Test that 'loadTimeZone' returns 'k_UNSUPPORTED_ID' when
//: 'rootPath' is a plausible directory, but the time zone identifier
//: is invalid.
//: