PersianCalendar::PersianCalendar(const Locale& aLocale, UErrorCode& success)
: Calendar(TimeZone::forLocaleOrDefault(aLocale), aLocale, success)
{
setTimeInMillis(getNow(), success); // Call this again now that the vtable is set up properly.
}
/** * Determine whether a year is a leap year in the Persian calendar
*/
UBool PersianCalendar::isLeapYear(int32_t year)
{
int64_t y = static_cast<int64_t>(year) * 25LL + 11LL; return (y % 33L < 8);
}
/** * Return the day # on which the given year starts. Days are counted * from the Persian epoch, origin 0.
*/
int32_t PersianCalendar::yearStart(int32_t year, UErrorCode& status) { return handleComputeMonthStart(year,0,false, status);
}
/** * Return the day # on which the given month starts. Days are counted * from the Persian epoch, origin 0. * * @param year The Persian year * @param year The Persian month, 0-based
*/
int32_t PersianCalendar::monthStart(int32_t year, int32_t month, UErrorCode& status) const { return handleComputeMonthStart(year,month,true, status);
}
/** * Return the length (in days) of the given month. * * @param year The Persian year * @param year The Persian month, 0-based
*/
int32_t PersianCalendar::handleGetMonthLength(int32_t extendedYear, int32_t month, UErrorCode& /*status*/) const { // If the month is out of range, adjust it into range, and // modify the extended year value accordingly. if (month < 0 || month > 11) {
extendedYear += ClockMath::floorDivide(month, 12, &month);
}
/** * Return the number of days in the given Persian year
*/
int32_t PersianCalendar::handleGetYearLength(int32_t extendedYear) const { return isLeapYear(extendedYear) ? 366 : 365;
}
//------------------------------------------------------------------------- // Functions for converting from field values to milliseconds.... //-------------------------------------------------------------------------
// Return JD of start of given month/year
int64_t PersianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool /*useMonth*/, UErrorCode& status) const { if (U_FAILURE(status)) { return 0;
} // If the month is out of range, adjust it into range, and // modify the extended year value accordingly. if (month < 0 || month > 11) { if (uprv_add32_overflow(eyear, ClockMath::floorDivide(month, 12, &month), &eyear)) {
status = U_ILLEGAL_ARGUMENT_ERROR; return 0;
}
}
if (month != 0) {
julianDay += kPersianNumDays[month];
}
return julianDay;
}
//------------------------------------------------------------------------- // Functions for converting from milliseconds to field values //-------------------------------------------------------------------------
int32_t PersianCalendar::handleGetExtendedYear(UErrorCode& status) { if (U_FAILURE(status)) { return 0;
} if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) { return internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
} return internalGet(UCAL_YEAR, 1); // Default to year 1
}
/** * Override Calendar to compute several fields specific to the Persian * calendar system. These are: * * <ul><li>ERA * <li>YEAR * <li>MONTH * <li>DAY_OF_MONTH * <li>DAY_OF_YEAR * <li>EXTENDED_YEAR</ul> * * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this * method is called.
*/ void PersianCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status) {
int64_t daysSinceEpoch = julianDay;
daysSinceEpoch -= PERSIAN_EPOCH;
int64_t year = ClockMath::floorDivideInt64(
33LL * daysSinceEpoch + 3LL, 12053LL) + 1LL; if (year > INT32_MAX || year < INT32_MIN) {
status = U_ILLEGAL_ARGUMENT_ERROR; return;
}
¤ 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.0.12Bemerkung:
(vorverarbeitet)
¤
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.