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

int32_t IslamicCalendar::trueMonthStart ( int32_t  month  )  const [private]

Find the day number on which a particular month of the true/lunar Islamic calendar starts.

Parameters:
month The month in question, origin 0 from the Hijri epoch
Returns:
The day number on which the given month starts.

Definition at line 227 of file islamcal.cpp.

References ClockMath::floorDivide(), moonAge(), CalendarAstronomer::SYNODIC_MONTH, U_FAILURE, and U_ZERO_ERROR.

Referenced by handleComputeFields(), handleGetMonthLength(), handleGetYearLength(), monthStart(), and yearStart().

{
    UErrorCode status = U_ZERO_ERROR;
    int32_t start = CalendarCache::get(&gMonthCache, month, status);

    if (start==0) {
        // Make a guess at when the month started, using the average length
        UDate origin = HIJRA_MILLIS 
            + uprv_floor(month * CalendarAstronomer::SYNODIC_MONTH) * kOneDay;

        // moonAge will fail due to memory allocation error
        double age = moonAge(origin, status);
        if (U_FAILURE(status)) {
            goto trueMonthStartEnd;
        }

        if (age >= 0) {
            // The month has already started
            do {
                origin -= kOneDay;
                age = moonAge(origin, status);
                if (U_FAILURE(status)) {
                    goto trueMonthStartEnd;
                }
            } while (age >= 0);
        }
        else {
            // Preceding month has not ended yet.
            do {
                origin += kOneDay;
                age = moonAge(origin, status);
                if (U_FAILURE(status)) {
                    goto trueMonthStartEnd;
                }
            } while (age < 0);
        }
        start = (int32_t)ClockMath::floorDivide((origin - HIJRA_MILLIS), (double)kOneDay) + 1;
        CalendarCache::put(&gMonthCache, month, start, status);
    }
trueMonthStartEnd :
    if(U_FAILURE(status)) {
        start = 0;
    }
    return start;
}


Generated by  Doxygen 1.6.0   Back to index