Logo Search packages:      
Sourcecode: icu version File versions

void Calendar::setWeekCountData ( const Locale desiredLocale,
const char *  type,
UErrorCode success 
) [private]

Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction time.

Parameters:
desiredLocale The given locale.
type The calendar type identifier, e.g: gregorian, buddhist, etc.
success Indicates the status of setting the week count data from the resource for the given locale. Returns U_ZERO_ERROR if constructed successfully.

Definition at line 3105 of file calendar.cpp.

References fFirstDayOfWeek, CalendarData::getByKey(), U_FAILURE, U_INVALID_FORMAT_ERROR, U_SUCCESS, U_USING_FALLBACK_WARNING, UCAL_SUNDAY, ULOC_ACTUAL_LOCALE, and ULOC_VALID_LOCALE.

Referenced by Calendar(), and createInstance().

{
    // Read the week count data from the resource bundle.  This should
    // have the form:
    //
    //   DateTimeElements:intvector {
    //      1,    // first day of week
    //      1     // min days in week
    //   }
    //   Both have a range of 1..7


    if (U_FAILURE(status)) return;

    fFirstDayOfWeek = UCAL_SUNDAY;
    fMinimalDaysInFirstWeek = 1;

    CalendarData calData(desiredLocale, type, status);
    // If the resource data doesn't seem to be present at all, then use last-resort
    // hard-coded data.
    UResourceBundle *dateTimeElements = calData.getByKey(gDateTimeElements, status);

    if (U_FAILURE(status))
    {
#if defined (U_DEBUG_CALDATA)
        fprintf(stderr, " Failure loading dateTimeElements = %s\n", u_errorName(status));
#endif
        status = U_USING_FALLBACK_WARNING;
        return;
    }

    U_LOCALE_BASED(locBased, *this);
    locBased.setLocaleIDs(ures_getLocaleByType(dateTimeElements, ULOC_VALID_LOCALE, &status),
        ures_getLocaleByType(dateTimeElements, ULOC_ACTUAL_LOCALE, &status));
    if (U_SUCCESS(status)) {
#if defined (U_DEBUG_CAL)
        fprintf(stderr, " Valid=%s, Actual=%s\n", validLocale, actualLocale);
#endif
        int32_t arrLen;
        const int32_t *dateTimeElementsArr = ures_getIntVector(dateTimeElements, &arrLen, &status);

        if(U_SUCCESS(status) && arrLen == 2
            && 1 <= dateTimeElementsArr[0] && dateTimeElementsArr[0] <= 7
            && 1 <= dateTimeElementsArr[1] && dateTimeElementsArr[1] <= 7)
        {
            fFirstDayOfWeek = (UCalendarDaysOfWeek)dateTimeElementsArr[0];
            fMinimalDaysInFirstWeek = (uint8_t)dateTimeElementsArr[1];
        }
        else {
            status = U_INVALID_FORMAT_ERROR;
        }
    }

    // do NOT close dateTimeElements
}


Generated by  Doxygen 1.6.0   Back to index