staticconst int32_t kGregorianEpoch = 1970; // used as the default value of EXTENDED_YEAR staticconstchar* TENTATIVE_ERA_VAR_NAME = "ICU_ENABLE_TENTATIVE_ERA";
// Export the following for use by test code.
UBool JapaneseCalendar::enableTentativeEra() { // Although start date of next Japanese era is planned ahead, a name of // new era might not be available. This implementation allows tester to // check a new era without era names by settings below (in priority order). // By default, such tentative era is disabled.
// 1. Environment variable ICU_ENABLE_TENTATIVE_ERA=true or false
UBool includeTentativeEra = false;
#if U_PLATFORM_HAS_WINUWP_API == 1 // UWP doesn't allow access to getenv(), but we can call GetEnvironmentVariableW to do the same thing.
char16_t varName[26] = {};
u_charsToUChars(TENTATIVE_ERA_VAR_NAME, varName, static_cast<int32_t>(uprv_strlen(TENTATIVE_ERA_VAR_NAME)));
WCHAR varValue[5] = {};
DWORD ret = GetEnvironmentVariableW(reinterpret_cast<WCHAR*>(varName), varValue, UPRV_LENGTHOF(varValue)); if ((ret == 4) && (_wcsicmp(varValue, L"true") == 0)) {
includeTentativeEra = true;
} #else char *envVarVal = getenv(TENTATIVE_ERA_VAR_NAME); if (envVarVal != nullptr && uprv_stricmp(envVarVal, "true") == 0) {
includeTentativeEra = true;
} #endif return includeTentativeEra;
}
// Initialize global Japanese era data staticvoid U_CALLCONV initializeEras(UErrorCode &status) {
gJapaneseEraRules = EraRules::createInstance("japanese", JapaneseCalendar::enableTentativeEra(), status); if (U_FAILURE(status)) { return;
}
gCurrentEra = gJapaneseEraRules->getCurrentEraIndex();
}
/* Some platforms don't like to export constants, like old Palm OS and some z/OS configurations. */
uint32_t JapaneseCalendar::getCurrentEra() { return gCurrentEra;
}
JapaneseCalendar::JapaneseCalendar(const Locale& aLocale, UErrorCode& success)
: GregorianCalendar(aLocale, success)
{
init(success);
setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
}
int32_t JapaneseCalendar::getDefaultMonthInYear(int32_t eyear, UErrorCode& status)
{ if (U_FAILURE(status)) { return 0;
}
int32_t era = internalGetEra(); // TODO do we assume we can trust 'era'? What if it is denormalized?
int32_t month = 0;
// Find out if we are at the edge of an era
int32_t eraStart[3] = { 0,0,0 };
gJapaneseEraRules->getStartDate(era, eraStart, status); if (U_FAILURE(status)) { return 0;
} if(eyear == eraStart[0]) { // Yes, we're in the first year of this era. return eraStart[1] // month
-1; // return 0-based month
}
return month;
}
int32_t JapaneseCalendar::getDefaultDayInMonth(int32_t eyear, int32_t month, UErrorCode& status)
{ if (U_FAILURE(status)) { return 0;
}
int32_t era = internalGetEra();
int32_t day = 1;
int32_t JapaneseCalendar::handleGetExtendedYear(UErrorCode& status)
{ if (U_FAILURE(status)) { return 0;
} // EXTENDED_YEAR in JapaneseCalendar is a Gregorian year // The default value of EXTENDED_YEAR is 1970 (Showa 45)
// extended year is a gregorian year, where 1 = 1AD, 0 = 1BC, -1 = 2BC, etc
int32_t year = internalGet(UCAL_YEAR, 1); // pin to minimum of year 1 (first year) // add gregorian starting year, subtract one because year starts at 1 if (uprv_add32_overflow(year, eraStartYear - 1, &year)) {
status = U_ILLEGAL_ARGUMENT_ERROR; return 0;
} return year;
}
void JapaneseCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status)
{ //Calendar::timeToFields(theTime, quick, status);
GregorianCalendar::handleComputeFields(julianDay, status);
int32_t year = internalGet(UCAL_EXTENDED_YEAR); // Gregorian year
int32_t eraIdx = gJapaneseEraRules->getEraIndex(year, internalGetMonth(status) + 1, internalGet(UCAL_DAY_OF_MONTH), status);
int32_t startYear = gJapaneseEraRules->getStartYear(eraIdx, status) - 1; if (U_FAILURE(status)) { return;
} if (uprv_add32_overflow(year, -startYear, &year)) {
status = U_ILLEGAL_ARGUMENT_ERROR; return;
}
internalSet(UCAL_ERA, eraIdx);
internalSet(UCAL_YEAR, year);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.