本文整理汇总了C++中TimeZone::getID方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeZone::getID方法的具体用法?C++ TimeZone::getID怎么用?C++ TimeZone::getID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeZone
的用法示例。
在下文中一共展示了TimeZone::getID方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TZEnumeration
TZEnumeration(int32_t rawOffset) : map(NULL), len(0), pos(0) {
if (!getOlsonMeta()) {
return;
}
// Allocate more space than we'll need. The end of the array will
// be blank.
map = (int32_t*)uprv_malloc(OLSON_ZONE_COUNT * sizeof(int32_t));
if (map == 0) {
return;
}
uprv_memset(map, 0, sizeof(int32_t) * OLSON_ZONE_COUNT);
UnicodeString s;
for (int32_t i=0; i<OLSON_ZONE_COUNT; ++i) {
if (getID(i)) {
// This is VERY inefficient.
TimeZone* z = TimeZone::createTimeZone(unistr);
// Make sure we get back the ID we wanted (if the ID is
// invalid we get back GMT).
if (z != 0 && z->getID(s) == unistr &&
z->getRawOffset() == rawOffset) {
map[len++] = i;
}
delete z;
}
}
}
示例2: TestDateFormatRoundTrip
void DateFormatRoundTripTest::TestDateFormatRoundTrip()
{
UErrorCode status = U_ZERO_ERROR;
getFieldCal = Calendar::createInstance(status);
failure(status, "Calendar::createInstance");
if(!assertSuccess("trying to construct", status))return;
int32_t locCount = 0;
const Locale *avail = DateFormat::getAvailableLocales(locCount);
logln("DateFormat available locales: %d", locCount);
if(quick) {
SPARSENESS = 18;
logln("Quick mode: only testing SPARSENESS = 18");
}
TimeZone *tz = TimeZone::createDefault();
UnicodeString temp;
logln("Default TimeZone: " + tz->getID(temp));
delete tz;
#ifdef TEST_ONE_LOC // define this to just test ONE locale.
Locale loc(TEST_ONE_LOC);
test(loc);
#if INFINITE
for(;;) {
test(loc);
}
#endif
#else
# if INFINITE
// Special infinite loop test mode for finding hard to reproduce errors
Locale loc = Locale::getDefault();
logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName(temp));
for(;;)
test(loc);
# else
test(Locale::getDefault());
#if 1
// installed locales
for (int i=0; i < locCount; ++i) {
test(avail[i]);
}
#endif
#if 1
// special locales
int32_t jCount = CalendarTest::testLocaleCount();
for (int32_t j=0; j < jCount; ++j) {
test(Locale(CalendarTest::testLocaleID(j)));
}
#endif
# endif
#endif
delete getFieldCal;
}
示例3: loc
/**
* Test to see if DateFormat understands zone equivalency groups. It
* might seem that this should be a DateFormat test, but it's really a
* TimeZone test -- the changes to DateFormat are minor.
*
* We use two known, stable zones that shouldn't change much over time
* -- America/Vancouver and America/Los_Angeles. However, they MAY
* change at some point -- if that happens, replace them with any two
* zones in an equivalency group where one zone has localized name
* data, and the other doesn't, in some locale.
*/
void TimeZoneRegressionTest::TestJ449() {
UErrorCode status = U_ZERO_ERROR;
UnicodeString str;
// Modify the following three as necessary. The two IDs must
// specify two zones in the same equivalency group. One must have
// locale data in 'loc'; the other must not.
const char* idWithLocaleData = "America/Los_Angeles";
const char* idWithoutLocaleData = "US/Pacific";
const Locale loc("en", "", "");
TimeZone *zoneWith = TimeZone::createTimeZone(idWithLocaleData);
TimeZone *zoneWithout = TimeZone::createTimeZone(idWithoutLocaleData);
// Make sure we got valid zones
if (zoneWith->getID(str) != UnicodeString(idWithLocaleData) ||
zoneWithout->getID(str) != UnicodeString(idWithoutLocaleData)) {
dataerrln(UnicodeString("Fail: Unable to create zones - wanted ") + idWithLocaleData + ", got " + zoneWith->getID(str) + ", and wanted " + idWithoutLocaleData + " but got " + zoneWithout->getID(str));
} else {
GregorianCalendar calWith(*zoneWith, status);
GregorianCalendar calWithout(*zoneWithout, status);
SimpleDateFormat fmt("MMM d yyyy hh:mm a zzz", loc, status);
if (U_FAILURE(status)) {
errln("Fail: Unable to create GregorianCalendar/SimpleDateFormat");
} else {
UDate date = 0;
UnicodeString strWith, strWithout;
fmt.setCalendar(calWith);
fmt.format(date, strWith);
fmt.setCalendar(calWithout);
fmt.format(date, strWithout);
if (strWith == strWithout) {
logln((UnicodeString)"Ok: " + idWithLocaleData + " -> " +
strWith + "; " + idWithoutLocaleData + " -> " +
strWithout);
} else {
errln((UnicodeString)"FAIL: " + idWithLocaleData + " -> " +
strWith + "; " + idWithoutLocaleData + " -> " +
strWithout);
}
}
}
delete zoneWith;
delete zoneWithout;
}
示例4: getCanonicalCLDRID
const UChar* U_EXPORT2
ZoneMeta::getCanonicalCLDRID(const TimeZone& tz) {
if (dynamic_cast<const OlsonTimeZone *>(&tz) != NULL) {
// short cut for OlsonTimeZone
const OlsonTimeZone *otz = (const OlsonTimeZone*)&tz;
return otz->getCanonicalID();
}
UErrorCode status = U_ZERO_ERROR;
UnicodeString tzID;
return getCanonicalCLDRID(tz.getID(tzID), status);
}
示例5: createZone
/**
* If the ID supplied to TimeZone is not a valid system ID,
* TimeZone::createTimeZone() will return a GMT zone object. In order
* to detect this error, we check the ID of the returned zone against
* the ID we requested. If they don't match, we fail with an error.
*/
TimeZone* createZone(const UnicodeString& id) {
UnicodeString str;
TimeZone* zone = TimeZone::createTimeZone(id);
if (zone->getID(str) != id) {
delete zone;
printf("Error: TimeZone::createTimeZone(");
uprintf(id);
printf(") returned zone with ID ");
uprintf(str);
printf("\n");
exit(1);
}
return zone;
}
示例6:
U_CAPI int32_t U_EXPORT2
ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec) {
int32_t len = 0;
if (ec!=NULL && U_SUCCESS(*ec)) {
TimeZone* zone = TimeZone::createDefault();
if (zone == NULL) {
*ec = U_MEMORY_ALLOCATION_ERROR;
} else {
UnicodeString id;
zone->getID(id);
delete zone;
len = id.extract(result, resultCapacity, *ec);
}
}
return len;
}
示例7: TIMEZONE_Get_default
void TIMEZONE_Get_default(sLONG_PTR *pResult, PackagePtr pParams)
{
C_TEXT returnValue;
TimeZone *defaultZone = TimeZone::createDefault();
if(defaultZone){
UnicodeString zoneId;
defaultZone->getID(zoneId);
DT::setUnicodeString(returnValue, zoneId);
delete defaultZone;
}
returnValue.setReturn(pResult);
}
示例8: timezone_convert_datetimezone
/* {{{ timezone_process_timezone_argument
* TimeZone argument processor. outside_error may be NULL (for static functions/constructors) */
U_CFUNC TimeZone *timezone_process_timezone_argument(zval *zv_timezone,
intl_error *outside_error,
const char *func)
{
zval local_zv_tz;
char *message = NULL;
TimeZone *timeZone;
if (zv_timezone == NULL || Z_TYPE_P(zv_timezone) == IS_NULL) {
timelib_tzinfo *tzinfo = get_timezone_info();
ZVAL_STRING(&local_zv_tz, tzinfo->name);
zv_timezone = &local_zv_tz;
} else {
ZVAL_NULL(&local_zv_tz);
}
if (Z_TYPE_P(zv_timezone) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(zv_timezone), TimeZone_ce_ptr)) {
TimeZone_object *to = Z_INTL_TIMEZONE_P(zv_timezone);
if (to->utimezone == NULL) {
spprintf(&message, 0, "%s: passed IntlTimeZone is not "
"properly constructed", func);
if (message) {
intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1);
efree(message);
}
zval_dtor(&local_zv_tz);
return NULL;
}
timeZone = to->utimezone->clone();
if (timeZone == NULL) {
spprintf(&message, 0, "%s: could not clone TimeZone", func);
if (message) {
intl_errors_set(outside_error, U_MEMORY_ALLOCATION_ERROR, message, 1);
efree(message);
}
zval_dtor(&local_zv_tz);
return NULL;
}
} else if (Z_TYPE_P(zv_timezone) == IS_OBJECT &&
instanceof_function(Z_OBJCE_P(zv_timezone), php_date_get_timezone_ce())) {
php_timezone_obj *tzobj = Z_PHPTIMEZONE_P(zv_timezone);
zval_dtor(&local_zv_tz);
return timezone_convert_datetimezone(tzobj->type, tzobj, 0,
outside_error, func);
} else {
UnicodeString id,
gottenId;
UErrorCode status = U_ZERO_ERROR; /* outside_error may be NULL */
convert_to_string_ex(zv_timezone);
if (intl_stringFromChar(id, Z_STRVAL_P(zv_timezone), Z_STRLEN_P(zv_timezone),
&status) == FAILURE) {
spprintf(&message, 0, "%s: Time zone identifier given is not a "
"valid UTF-8 string", func);
if (message) {
intl_errors_set(outside_error, status, message, 1);
efree(message);
}
zval_dtor(&local_zv_tz);
return NULL;
}
timeZone = TimeZone::createTimeZone(id);
if (timeZone == NULL) {
spprintf(&message, 0, "%s: could not create time zone", func);
if (message) {
intl_errors_set(outside_error, U_MEMORY_ALLOCATION_ERROR, message, 1);
efree(message);
}
zval_dtor(&local_zv_tz);
return NULL;
}
if (timeZone->getID(gottenId) != id) {
spprintf(&message, 0, "%s: no such time zone: '%s'",
func, Z_STRVAL_P(zv_timezone));
if (message) {
intl_errors_set(outside_error, U_ILLEGAL_ARGUMENT_ERROR, message, 1);
efree(message);
}
zval_dtor(&local_zv_tz);
delete timeZone;
return NULL;
}
}
zval_dtor(&local_zv_tz);
return timeZone;
}
示例9: stri_timezone_info
/** Get localized time zone info
*
* @param tz single string or NULL
* @param locale single string or NULL
* @param display_type single string
* @return list
*
* @version 0.5-1 (Marek Gagolewski, 2014-12-24)
*
* @version 0.5-1 (Marek Gagolewski, 2015-03-01)
* new out: WindowsID, NameDaylight, new in: display_type
*/
SEXP stri_timezone_info(SEXP tz, SEXP locale, SEXP display_type) {
TimeZone* curtz = stri__prepare_arg_timezone(tz, "tz", R_NilValue);
const char* qloc = stri__prepare_arg_locale(locale, "locale", true); /* this is R_alloc'ed */
const char* dtype_str = stri__prepare_arg_string_1_notNA(display_type, "display_type"); /* this is R_alloc'ed */
const char* dtype_opts[] = {
"short", "long", "generic_short", "generic_long", "gmt_short", "gmt_long",
"common", "generic_location",
NULL};
int dtype_cur = stri__match_arg(dtype_str, dtype_opts);
TimeZone::EDisplayType dtype;
switch (dtype_cur) {
case 0: dtype = TimeZone::SHORT; break;
case 1: dtype = TimeZone::LONG; break;
case 2: dtype = TimeZone::SHORT_GENERIC; break;
case 3: dtype = TimeZone::LONG_GENERIC; break;
case 4: dtype = TimeZone::SHORT_GMT; break;
case 5: dtype = TimeZone::LONG_GMT; break;
case 6: dtype = TimeZone::SHORT_COMMONLY_USED; break;
case 7: dtype = TimeZone::GENERIC_LOCATION; break;
default: Rf_error(MSG__INCORRECT_MATCH_OPTION, "display_type"); break;
}
const R_len_t infosize = 6;
SEXP vals;
PROTECT(vals = Rf_allocVector(VECSXP, infosize));
for (int i=0; i<infosize; ++i)
SET_VECTOR_ELT(vals, i, R_NilValue);
R_len_t curidx = -1;
++curidx;
UnicodeString val_ID;
curtz->getID(val_ID);
SET_VECTOR_ELT(vals, curidx, stri__make_character_vector_UnicodeString_ptr(1, &val_ID));
++curidx;
UnicodeString val_name;
curtz->getDisplayName(false, dtype, Locale::createFromName(qloc), val_name);
SET_VECTOR_ELT(vals, curidx, stri__make_character_vector_UnicodeString_ptr(1, &val_name));
++curidx;
if ((bool)curtz->useDaylightTime()) {
UnicodeString val_name2;
curtz->getDisplayName(true, dtype, Locale::createFromName(qloc), val_name2);
SET_VECTOR_ELT(vals, curidx, stri__make_character_vector_UnicodeString_ptr(1, &val_name2));
}
else
SET_VECTOR_ELT(vals, curidx, Rf_ScalarString(NA_STRING));
++curidx;
UnicodeString val_windows;
UErrorCode status = U_ZERO_ERROR;
#if U_ICU_VERSION_MAJOR_NUM>=52
TimeZone::getWindowsID(val_ID, val_windows, status); // Stable since ICU 52
#endif
if (U_SUCCESS(status) && val_windows.length() > 0)
SET_VECTOR_ELT(vals, curidx, stri__make_character_vector_UnicodeString_ptr(1, &val_windows));
else
SET_VECTOR_ELT(vals, curidx, Rf_ScalarString(NA_STRING));
++curidx;
SET_VECTOR_ELT(vals, curidx, Rf_ScalarReal(curtz->getRawOffset()/1000.0/3600.0));
++curidx;
SET_VECTOR_ELT(vals, curidx, Rf_ScalarLogical((bool)curtz->useDaylightTime()));
delete curtz;
stri__set_names(vals, infosize, "ID", "Name", "Name.Daylight", "Name.Windows", "RawOffset", "UsesDaylightTime");
UNPROTECT(1);
return vals;
}
示例10: sizeof
extern int
main(int argc, char *argv[]) {
int32_t low = 1902;
int32_t high = 2038;
UBool bAll = FALSE;
const char *dir = NULL;
const char *linesep = NULL;
U_MAIN_INIT_ARGS(argc, argv);
argc = u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
if (argc < 0) {
cerr << "Illegal command line argument(s)" << endl << endl;
}
if (argc < 0 || options[kOptHelpH].doesOccur || options[kOptHelpQuestionMark].doesOccur) {
cerr
<< "Usage: icuzdump [-options] [zoneid1 zoneid2 ...]" << endl
<< endl
<< "\tDump all offset transitions for the specified zones." << endl
<< endl
<< "Options:" << endl
<< "\t-a : Dump all available zones." << endl
<< "\t-d <dir> : When specified, write transitions in a file under" << endl
<< "\t the directory for each zone." << endl
<< "\t-l <sep> : New line code type used in file outputs. CR or LF (default)"
<< "\t or CRLF." << endl
<< "\t-c [<low_year>,]<high_year>" << endl
<< "\t : When specified, dump transitions starting <low_year>" << endl
<< "\t (inclusive) up to <high_year> (exclusive). The default" << endl
<< "\t values are 1902(low) and 2038(high)." << endl;
return argc < 0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
}
bAll = options[kOptAllZones].doesOccur;
if (options[kOptDestDir].doesOccur) {
dir = options[kOptDestDir].value;
}
if (options[kOptLineSep].doesOccur) {
if (strcmp(options[kOptLineSep].value, "CR") == 0) {
linesep = "\r";
} else if (strcmp(options[kOptLineSep].value, "CRLF") == 0) {
linesep = "\r\n";
} else if (strcmp(options[kOptLineSep].value, "LF") == 0) {
linesep = "\n";
}
}
if (options[kOptCutover].doesOccur) {
char* comma = (char*)strchr(options[kOptCutover].value, ',');
if (comma == NULL) {
high = atoi(options[kOptCutover].value);
} else {
*comma = 0;
low = atoi(options[kOptCutover].value);
high = atoi(comma + 1);
}
}
ICUZDump dumper;
dumper.setLowYear(low);
dumper.setHighYear(high);
if (dir != NULL && linesep != NULL) {
// use the specified line separator only for file output
dumper.setLineSeparator((const char*)linesep);
}
ZoneIterator* zit;
if (bAll) {
zit = new ZoneIterator(TRUE);
} else {
if (argc <= 1) {
zit = new ZoneIterator();
} else {
zit = new ZoneIterator((const char**)&argv[1], argc - 1);
}
}
UnicodeString id;
if (dir != NULL) {
// file output
ostringstream path;
ios::openmode mode = ios::out;
if (linesep != NULL) {
mode |= ios::binary;
}
for (;;) {
TimeZone* tz = zit->next();
if (tz == NULL) {
break;
}
dumper.setTimeZone(tz);
tz->getID(id);
// target file path
path.str("");
path << dir << U_FILE_SEP_CHAR;
id = id.findAndReplace("/", "-");
//.........这里部分代码省略.........
示例11: SimpleTimeZone
/**
* @bug 4162593
* TimeZone broken at midnight. The TimeZone code fails to handle
* transitions at midnight correctly.
*/
void
TimeZoneRegressionTest::Test4162593()
{
UErrorCode status = U_ZERO_ERROR;
SimpleDateFormat *fmt = new SimpleDateFormat("z", Locale::getUS(), status);
if(U_FAILURE(status)) {
dataerrln("Error creating calendar %s", u_errorName(status));
delete fmt;
return;
}
const int32_t ONE_HOUR = 60*60*1000;
SimpleTimeZone *asuncion = new SimpleTimeZone(-4*ONE_HOUR, "America/Asuncion" /*PY%sT*/,
UCAL_OCTOBER, 1, 0 /*DOM*/, 0*ONE_HOUR,
UCAL_MARCH, 1, 0 /*DOM*/, 0*ONE_HOUR, 1*ONE_HOUR, status);
/* Zone
* Starting time
* Transition expected between start+1H and start+2H
*/
TimeZone *DATA_TZ [] = {
0, 0, 0 };
int32_t DATA_INT [] [5] = {
// These years must be AFTER the Gregorian cutover
{1998, UCAL_SEPTEMBER, 30, 22, 0},
{2000, UCAL_FEBRUARY, 28, 22, 0},
{2000, UCAL_FEBRUARY, 29, 22, 0},
};
UBool DATA_BOOL [] = {
TRUE,
FALSE,
TRUE,
};
UnicodeString zone [4];// = new String[4];
DATA_TZ[0] =
new SimpleTimeZone(2*ONE_HOUR, "Asia/Damascus" /*EE%sT*/,
UCAL_APRIL, 1, 0 /*DOM*/, 0*ONE_HOUR,
UCAL_OCTOBER, 1, 0 /*DOM*/, 0*ONE_HOUR, 1*ONE_HOUR, status);
DATA_TZ[1] = asuncion; DATA_TZ[2] = asuncion;
for(int32_t j = 0; j < 3; j++) {
TimeZone *tz = (TimeZone*)DATA_TZ[j];
TimeZone::setDefault(*tz);
fmt->setTimeZone(*tz);
// Must construct the Date object AFTER setting the default zone
int32_t *p = (int32_t*)DATA_INT[j];
UDate d = CalendarRegressionTest::makeDate(p[0], p[1], p[2], p[3], p[4]);
UBool transitionExpected = DATA_BOOL[j];
UnicodeString temp;
logln(tz->getID(temp) + ":");
for (int32_t i = 0; i < 4; ++i) {
FieldPosition pos(0);
zone[i].remove();
zone[i] = fmt->format(d+ i*ONE_HOUR, zone[i], pos);
logln(UnicodeString("") + i + ": " + d + " / " + zone[i]);
//d += (double) ONE_HOUR;
}
if(zone[0] == zone[1] &&
(zone[1] == zone[2]) != transitionExpected &&
zone[2] == zone[3]) {
logln(UnicodeString("Ok: transition ") + transitionExpected);
}
else {
errln("Fail: boundary transition incorrect");
}
}
delete fmt;
delete asuncion;
delete DATA_TZ[0];
}