IndianCalendar::IndianCalendar(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.
}
/* * Return the length (in days) of the given month. * * @param eyear The year in Saka Era * @param month The month(0-based) in Indian calendar
*/
int32_t IndianCalendar::handleGetMonthLength(int32_t eyear, int32_t month, UErrorCode& /* status */) const { if (month < 0 || month > 11) {
eyear += ClockMath::floorDivide(month, 12, &month);
}
/* * Return the number of days in the given Indian year * * @param eyear The year in Saka Era.
*/
int32_t IndianCalendar::handleGetYearLength(int32_t eyear) const { return isGregorianLeap(eyear + INDIAN_ERA_START) ? 366 : 365;
} /* * Returns the Julian Day corresponding to gregorian date * * @param year The Gregorian year * @param month The month in Gregorian Year, 0 based. * @param date The date in Gregorian day in month
*/ staticdouble gregorianToJD(int32_t year, int32_t month, int32_t date) { return Grego::fieldsToDay(year, month, date) + kEpochStartAsJulianDay - 0.5;
}
/* * Returns the Gregorian Date corresponding to a given Julian Day * Month is 0 based. * @param jd The Julian Day
*/ static int32_t* jdToGregorian(double jd, int32_t gregorianDate[3], UErrorCode& status) {
int32_t gdow;
Grego::dayToFields(jd - kEpochStartAsJulianDay,
gregorianDate[0], gregorianDate[1], gregorianDate[2], gdow, status); return gregorianDate;
}
//------------------------------------------------------------------------- // Functions for converting from field values to milliseconds.... //------------------------------------------------------------------------- staticdouble IndianToJD(int32_t year, int32_t month, int32_t date) {
int32_t leapMonth, gyear, m; double start, jd;
gyear = year + INDIAN_ERA_START;
if(isGregorianLeap(gyear)) {
leapMonth = 31;
start = gregorianToJD(gyear, 2 /* The third month in 0 based month */, 21);
} else {
leapMonth = 30;
start = gregorianToJD(gyear, 2 /* The third month in 0 based month */, 22);
}
if (month >= 8) {
m = month - 7;
jd += m * 30;
}
jd += date - 1;
}
return jd;
}
/* * Return JD of start of given month/year of Indian Calendar * @param eyear The year in Indian Calendar measured from Saka Era (78 AD). * @param month The month in Indian calendar
*/
int64_t IndianCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UBool /* useMonth */, UErrorCode& status) const { if (U_FAILURE(status)) { return 0;
}
//month is 0 based; converting it to 1-based
int32_t imonth;
// If the month is out of range, adjust it into range, and adjust the extended year accordingly if (month < 0 || month > 11) { if (uprv_add32_overflow(eyear, ClockMath::floorDivide(month, 12, &month), &eyear)) {
status = U_ILLEGAL_ARGUMENT_ERROR; return 0;
}
}
//------------------------------------------------------------------------- // Functions for converting from milliseconds to field values //-------------------------------------------------------------------------
if (newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR) == UCAL_EXTENDED_YEAR) {
year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1
} else {
year = internalGet(UCAL_YEAR, 1); // Default to year 1
}
return year;
}
/* * Override Calendar to compute several fields specific to the Indian * calendar system. These are: * * <ul><li>ERA * <li>YEAR * <li>MONTH * <li>DAY_OF_MONTH * <li>EXTENDED_YEAR</ul> * * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this * method is called. The getGregorianXxx() methods return Gregorian * calendar equivalents for the given Julian day.
*/ void IndianCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status) { double jdAtStartOfGregYear;
int32_t leapMonth, IndianYear, yday, IndianMonth, IndianDayOfMonth, mday;
int32_t gregorianYear; // Stores gregorian date corresponding to Julian day;
int32_t gd[3];
gregorianYear = jdToGregorian(julianDay, gd, status)[0]; // Gregorian date for Julian day if (U_FAILURE(status)) return;
IndianYear = gregorianYear - INDIAN_ERA_START; // Year in Saka era
jdAtStartOfGregYear = gregorianToJD(gregorianYear, 0, 1); // JD at start of Gregorian year
yday = static_cast<int32_t>(julianDay - jdAtStartOfGregYear); // Day number in Gregorian year (starting from 0)
if (yday < INDIAN_YEAR_START) { // Day is at the end of the preceding Saka year
IndianYear -= 1;
leapMonth = isGregorianLeap(gregorianYear - 1) ? 31 : 30; // Days in leapMonth this year, previous Gregorian year
yday += leapMonth + (31 * 5) + (30 * 3) + 10;
} else {
leapMonth = isGregorianLeap(gregorianYear) ? 31 : 30; // Days in leapMonth this year
yday -= INDIAN_YEAR_START;
}
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.