Logo Search packages:      
Sourcecode: icu version File versions  Download package

int32_t Calendar::getActualMaximum ( UCalendarDateFields  field,
UErrorCode status 
) const [virtual, inherited]

Return the maximum value that this field could have, given the current date. For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar, for some years the actual maximum for MONTH is 12, and for others 13.

The version of this function on Calendar uses an iterative algorithm to determine the actual maximum value for the field. There is almost always a more efficient way to accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar overrides this function with a more efficient implementation.

Parameters:
field the field to determine the maximum of
status Fill-in parameter which receives the status of this operation.
Returns:
the maximum of the given field for the current date of this Calendar ICU 2.6.

Reimplemented in JapaneseCalendar, and GregorianCalendar.

Definition at line 2919 of file calendar.cpp.

References Calendar::clone(), FALSE, Calendar::get(), Calendar::getActualHelper(), Calendar::getLeastMaximum(), Calendar::getMaximum(), Calendar::handleGetMonthLength(), Calendar::handleGetYearLength(), Calendar::prepareGetActual(), U_FAILURE, U_MEMORY_ALLOCATION_ERROR, UCAL_AM_PM, UCAL_DATE, UCAL_DAY_OF_WEEK, UCAL_DAY_OF_YEAR, UCAL_DOW_LOCAL, UCAL_DST_OFFSET, UCAL_EXTENDED_YEAR, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_JULIAN_DAY, UCAL_MILLISECOND, UCAL_MILLISECONDS_IN_DAY, UCAL_MINUTE, UCAL_MONTH, UCAL_SECOND, and UCAL_ZONE_OFFSET.

{
    int32_t result;
    switch (field) {
    case UCAL_DATE:
        {
            if(U_FAILURE(status)) return 0;
            Calendar *cal = clone();
            if(!cal) { status = U_MEMORY_ALLOCATION_ERROR; return 0; }
            cal->prepareGetActual(field,FALSE,status);
            result = handleGetMonthLength(cal->get(UCAL_EXTENDED_YEAR, status), cal->get(UCAL_MONTH, status));
            delete cal;
        }
        break;

    case UCAL_DAY_OF_YEAR:
        {
            if(U_FAILURE(status)) return 0;
            Calendar *cal = clone();
            if(!cal) { status = U_MEMORY_ALLOCATION_ERROR; return 0; }
            cal->prepareGetActual(field,FALSE,status);
            result = handleGetYearLength(cal->get(UCAL_EXTENDED_YEAR, status));
            delete cal;
        }
        break;

    case UCAL_DAY_OF_WEEK:
    case UCAL_AM_PM:
    case UCAL_HOUR:
    case UCAL_HOUR_OF_DAY:
    case UCAL_MINUTE:
    case UCAL_SECOND:
    case UCAL_MILLISECOND:
    case UCAL_ZONE_OFFSET:
    case UCAL_DST_OFFSET:
    case UCAL_DOW_LOCAL:
    case UCAL_JULIAN_DAY:
    case UCAL_MILLISECONDS_IN_DAY:
        // These fields all have fixed minima/maxima
        result = getMaximum(field);
        break;

    default:
        // For all other fields, do it the hard way....
        result = getActualHelper(field, getLeastMaximum(field), getMaximum(field),status);
        break;
    }
    return result;
}


Generated by  Doxygen 1.6.0   Back to index