static String defaultTimeZone() { // 6.4.3 DefaultTimeZone () (ECMA-402 2.0) // The DefaultTimeZone abstract operation returns a String value representing the valid (6.4.1) and canonicalized (6.4.2) time zone name for the host environment’s current time zone. UErrorCode status = U_ZERO_ERROR; Vector<UChar, 32> buffer(32); auto bufferLength = ucal_getDefaultTimeZone(buffer.data(), buffer.size(), &status); if (status == U_BUFFER_OVERFLOW_ERROR) { status = U_ZERO_ERROR; buffer.grow(bufferLength); ucal_getDefaultTimeZone(buffer.data(), bufferLength, &status); } if (U_SUCCESS(status)) { status = U_ZERO_ERROR; Vector<UChar, 32> canonicalBuffer(32); auto canonicalLength = ucal_getCanonicalTimeZoneID(buffer.data(), bufferLength, canonicalBuffer.data(), canonicalBuffer.size(), nullptr, &status); if (status == U_BUFFER_OVERFLOW_ERROR) { status = U_ZERO_ERROR; canonicalBuffer.grow(canonicalLength); ucal_getCanonicalTimeZoneID(buffer.data(), bufferLength, canonicalBuffer.data(), canonicalLength, nullptr, &status); } if (U_SUCCESS(status)) return String(canonicalBuffer.data(), canonicalLength); } return ASCIILiteral("UTC"); }
/** * call-seq: * UCalendar.default_tz => ustring * * Returns the default time zone name as UString. * * UCalendar.default_tz # "EET" * */ VALUE icu4r_cal_get_default_tz(VALUE obj) { UErrorCode status = U_ZERO_ERROR; UChar * buf ; long capa = 0; capa = ucal_getDefaultTimeZone (buf, capa, &status); if( U_BUFFER_OVERFLOW_ERROR == status) { buf = ALLOC_N(UChar, capa+1); status = U_ZERO_ERROR; capa = ucal_getDefaultTimeZone (buf, capa, &status); return icu_ustr_new_set(buf, capa, capa+1); } ICU_RAISE(status); return Qnil; }
/** * Call this once to get a consistent timezone. Use ctest_resetTimeZone to set it back to the original value. * @param optionalTimeZone Set this to a requested timezone. * Set to NULL to use the standard test timezone (Pacific Time) */ U_CFUNC void ctest_setTimeZone(const char *optionalTimeZone, UErrorCode *status) { #if !UCONFIG_NO_FORMATTING UChar zoneID[CTEST_MAX_TIMEZONE_SIZE]; if (optionalTimeZone == NULL) { optionalTimeZone = "America/Los_Angeles"; } if (gOriginalTimeZone[0]) { log_data_err("*** Error: time zone saved twice. New value will be %s (Are you missing data?)\n", optionalTimeZone); } ucal_getDefaultTimeZone(gOriginalTimeZone, CTEST_MAX_TIMEZONE_SIZE, status); if (U_FAILURE(*status)) { log_err("*** Error: Failed to save default time zone: %s\n", u_errorName(*status)); *status = U_ZERO_ERROR; } u_uastrncpy(zoneID, optionalTimeZone, CTEST_MAX_TIMEZONE_SIZE-1); zoneID[CTEST_MAX_TIMEZONE_SIZE-1] = 0; ucal_setDefaultTimeZone(zoneID, status); if (U_FAILURE(*status)) { log_err("*** Error: Failed to set default time zone to \"%s\": %s\n", optionalTimeZone, u_errorName(*status)); } #endif }
/* Version information */ static void version() { UErrorCode status = U_ZERO_ERROR; const char *tzVer; int len = 256; UChar tzName[256]; printf("icudate version %s, created by Stephen F. Booth.\n", DATE_VERSION); puts(U_COPYRIGHT_STRING); tzVer = ucal_getTZDataVersion(&status); if(U_FAILURE(status)) { tzVer = u_errorName(status); } printf("\n"); printf("ICU Version: %s\n", U_ICU_VERSION); printf("ICU Data (major+min): %s\n", U_ICUDATA_NAME); printf("Default Locale: %s\n", uloc_getDefault()); printf("Time Zone Data Version: %s\n", tzVer); printf("Default Time Zone: "); status = U_ZERO_ERROR; u_init(&status); len = ucal_getDefaultTimeZone(tzName, len, &status); if(U_FAILURE(status)) { printf(" ** Error getting default zone: %s\n", u_errorName(status)); } uprint(tzName, stdout, &status); printf("\n\n"); }
// Qt wrapper around ucal_getDefaultTimeZone() static QByteArray ucalDefaultTimeZoneId() { int32_t size = 30; QString result(size, Qt::Uninitialized); UErrorCode status = U_ZERO_ERROR; // size = ucal_getDefaultTimeZone(result, resultLength, status) size = ucal_getDefaultTimeZone(reinterpret_cast<UChar *>(result.data()), size, &status); // If overflow, then resize and retry if (status == U_BUFFER_OVERFLOW_ERROR) { result.resize(size); status = U_ZERO_ERROR; size = ucal_getDefaultTimeZone(reinterpret_cast<UChar *>(result.data()), size, &status); } // If successful on first or second go, resize and return if (U_SUCCESS(status)) { result.resize(size); return result.toUtf8(); } return QByteArray(); }
void cmd_version(UBool noLoad) { UVersionInfo icu; char str[200]; printf("<ICUINFO>\n"); printf("International Components for Unicode for C/C++\n"); printf("%s\n", U_COPYRIGHT_STRING); printf("Compiled-Version: %s\n", U_ICU_VERSION); u_getVersion(icu); u_versionToString(icu, str); printf("Runtime-Version: %s\n", str); printf("Compiled-Unicode-Version: %s\n", U_UNICODE_VERSION); u_getUnicodeVersion(icu); u_versionToString(icu, str); printf("Runtime-Unicode-Version: %s\n", U_UNICODE_VERSION); printf("Platform: %s\n", getPlatform()); #if defined(U_BUILD) printf("Build: %s\n", U_BUILD); #if defined(U_HOST) if(strcmp(U_BUILD,U_HOST)) { printf("Host: %s\n", U_HOST); } #endif #endif #if defined(U_CC) printf("C compiler: %s\n", U_CC); #endif #if defined(U_CXX) printf("C++ compiler: %s\n", U_CXX); #endif #if defined(CYGWINMSVC) printf("Cygwin: CYGWINMSVC\n"); #endif printf("ICUDATA: %s\n", U_ICUDATA_NAME); do_init(); printf("Data Directory: %s\n", u_getDataDirectory()); printf("ICU Initialization returned: %s\n", u_errorName(initStatus)); printf( "Default locale: %s\n", uloc_getDefault()); { UErrorCode subStatus = U_ZERO_ERROR; ulocdata_getCLDRVersion(icu, &subStatus); if(U_SUCCESS(subStatus)) { u_versionToString(icu, str); printf("CLDR-Version: %s\n", str); } else { printf("CLDR-Version: %s\n", u_errorName(subStatus)); } } #if !UCONFIG_NO_CONVERSION if(noLoad == FALSE) { printf("Default converter: %s\n", ucnv_getDefaultName()); } #endif #if !UCONFIG_NO_FORMATTING { UChar buf[100]; char buf2[100]; UErrorCode subsubStatus= U_ZERO_ERROR; int32_t len; len = ucal_getDefaultTimeZone(buf, 100, &subsubStatus); if(U_SUCCESS(subsubStatus)&&len>0) { u_UCharsToChars(buf, buf2, len+1); printf("Default TZ: %s\n", buf2); } else { printf("Default TZ: %s\n", u_errorName(subsubStatus)); } } { UErrorCode subStatus = U_ZERO_ERROR; const char *tzVer = ucal_getTZDataVersion(&subStatus); if(U_FAILURE(subStatus)) { tzVer = u_errorName(subStatus); } printf("TZ data version: %s\n", tzVer); } #endif #if U_ENABLE_DYLOAD const char *pluginFile = uplug_getPluginFile(); printf("Plugin file is: %s\n", (pluginFile&&*pluginFile)?pluginFile:"(not set. try setting ICU_PLUGINS to a directory.)"); #else fprintf(stderr, "Dynamic Loading: is disabled. No plugins will be loaded at start-up.\n"); #endif printf("</ICUINFO>\n\n"); }