private int compareToRule(int month, int monthLen, int prevMonthLen,
                                  int dayOfMonth,
                                  int dayOfWeek, int millis, int millisDelta,
                                  int ruleMode, int ruleMonth, int ruleDayOfWeek,
                                  int ruleDay, int ruleMillis)
    {
        // Make adjustments for startTimeMode and endTimeMode

        millis += millisDelta;

        while (millis >= Grego.MILLIS_PER_DAY) {
            millis -= Grego.MILLIS_PER_DAY;
            ++dayOfMonth;
            dayOfWeek = 1 + (dayOfWeek % 7); // dayOfWeek is one-based
            if (dayOfMonth > monthLen) {
                dayOfMonth = 1;
                /* When incrementing the month, it is desirable to overflow
                 * from DECEMBER to DECEMBER+1, since we use the result to
                 * compare against a real month. Wraparound of the value
                 * leads to bug 4173604. */
                ++month;
            }
        }
        /*
         * For some reasons, Sun Java 6 on Solaris/Linux has a problem with
         * the while loop below (at least Java 6 up to build 1.6.0_02-b08).
         * It looks the JRE messes up the variable 'millis' while executing
         * the code in the while block.  The problem is not reproduced with
         * JVM option -Xint, that is, it is likely a bug of the HotSpot
         * adaptive compiler.  Moving 'millis += Grego.MILLIS_PER_DAY'
         * to the end of this while block seems to resolve the problem.
         * See ticket#5887 about the problem in detail.
         */
        while (millis < 0) {
            //millis += Grego.MILLIS_PER_DAY;
            --dayOfMonth;
            dayOfWeek = 1 + ((dayOfWeek+5) % 7); // dayOfWeek is one-based
            if (dayOfMonth < 1) {
                dayOfMonth = prevMonthLen;
                --month;
            }
            millis += Grego.MILLIS_PER_DAY;
        }

        if (month < ruleMonth) return -1;
        else if (month > ruleMonth) return 1;

        int ruleDayOfMonth = 0;

        // Adjust the ruleDay to the monthLen, for non-leap year February 29 rule days.
        if (ruleDay > monthLen) {
            ruleDay = monthLen;
        }

        switch (ruleMode)
        {
        case DOM_MODE:
            ruleDayOfMonth = ruleDay;
            break;
        case DOW_IN_MONTH_MODE:
            // In this case ruleDay is the day-of-week-in-month
            if (ruleDay > 0)
                ruleDayOfMonth = 1 + (ruleDay - 1) * 7 +
                    (7 + ruleDayOfWeek - (dayOfWeek - dayOfMonth + 1)) % 7;
            else // Assume ruleDay < 0 here
            {
                ruleDayOfMonth = monthLen + (ruleDay + 1) * 7 -
                    (7 + (dayOfWeek + monthLen - dayOfMonth) - ruleDayOfWeek) % 7;
            }
            break;
        case DOW_GE_DOM_MODE:
            ruleDayOfMonth = ruleDay +
                (49 + ruleDayOfWeek - ruleDay - dayOfWeek + dayOfMonth) % 7;
            break;
        case DOW_LE_DOM_MODE:
            ruleDayOfMonth = ruleDay -
                (49 - ruleDayOfWeek + ruleDay + dayOfWeek - dayOfMonth) % 7;
            // Note at this point ruleDayOfMonth may be <1, although it will
            // be >=1 for well-formed rules.
            break;
        }

        if (dayOfMonth < ruleDayOfMonth) return -1;
        else if (dayOfMonth > ruleDayOfMonth) return 1;

        if (millis < ruleMillis){
                return -1;
        }else if (millis > ruleMillis){
                return 1;
        }else{
                return 0;
        }
    }
private int compareToRule ( int month , int monthLen , int prevMonthLen , int dayOfMonth , int dayOfWeek , int millis , int millisDelta , int ruleMode , int ruleMonth , int ruleDayOfWeek , int ruleDay , int ruleMillis ) { millis += millisDelta ; while ( millis >= Grego . MILLIS_PER_DAY ) { millis -= Grego . MILLIS_PER_DAY ; ++ dayOfMonth ; dayOfWeek = 1 + ( dayOfWeek % 7 ) ; if ( dayOfMonth > monthLen ) { dayOfMonth = 1 ; ++ month ; } } while ( millis < 0 ) { -- dayOfMonth ; dayOfWeek = 1 + ( ( dayOfWeek + 5 ) % 7 ) ; if ( dayOfMonth < 1 ) { dayOfMonth = prevMonthLen ; -- month ; } millis += Grego . MILLIS_PER_DAY ; } if ( month < ruleMonth ) return - 1 ; else if ( month > ruleMonth ) return 1 ; int ruleDayOfMonth = 0 ; if ( ruleDay > monthLen ) { ruleDay = monthLen ; } switch ( ruleMode ) { case DOM_MODE : ruleDayOfMonth = ruleDay ; break ; case DOW_IN_MONTH_MODE : if ( ruleDay > 0 ) ruleDayOfMonth = 1 + ( ruleDay - 1 ) * 7 + ( 7 + ruleDayOfWeek - ( dayOfWeek - dayOfMonth + 1 ) ) % 7 ; else { ruleDayOfMonth = monthLen + ( ruleDay + 1 ) * 7 - ( 7 + ( dayOfWeek + monthLen - dayOfMonth ) - ruleDayOfWeek ) % 7 ; } break ; case DOW_GE_DOM_MODE : ruleDayOfMonth = ruleDay + ( 49 + ruleDayOfWeek - ruleDay - dayOfWeek + dayOfMonth ) % 7 ; break ; case DOW_LE_DOM_MODE : ruleDayOfMonth = ruleDay - ( 49 - ruleDayOfWeek + ruleDay + dayOfWeek - dayOfMonth ) % 7 ; break ; } if ( dayOfMonth < ruleDayOfMonth ) return - 1 ; else if ( dayOfMonth > ruleDayOfMonth ) return 1 ; if ( millis < ruleMillis ) { return - 1 ; } else if ( millis > ruleMillis ) { return 1 ; } else { return 0 ; } }
Compare a given date in the year to a rule. Return 1, 0, or -1, depending
on whether the date is after, equal to, or before the rule date. The
millis are compared directly against the ruleMillis, so any
standard-daylight adjustments must be handled by the caller.

@return  1 if the date is after the rule date, -1 if the date is before
the rule date, or 0 if the date is equal to the rule date.