public Date calculateNextTrigger(Calendar baseCalendar) {
        // All occurrences are done
        if (isLastOccurrence()) return null;

        Calendar nextCalendar = (Calendar) baseCalendar.clone();

        // trigger: { every: 'day', count: 5 }
        if (triggerEveryString != null) {
            try {
                addInterval(nextCalendar, triggerEveryString, 1);
            } catch (IllegalArgumentException exception) {
                Log.e(TAG, "Error calculating next trigger, trigger unit is wrong: " + exception.getMessage());
                return null;
            }

            // trigger every: { minute: 10, hour: 9, day: 27, month: 10 }
        } else if (triggerEveryJSONObject != null) {
            // Set calendar to trigger.every values like minute: 20, hour: 9, etc.
            // Returns the next higher Calendar field for calculating the next trigger
            // If 0 is returned the options are empty or wrong
            int nextTriggerCalendarFieldToIncrease = setEveryValues(nextCalendar);

            // Nothing should be increased, options are empty or wrong
            if (nextTriggerCalendarFieldToIncrease == 0) return null;

            // If the next trigger is in the past or equal, increase the calendar
            // The trigger could be set by trigger.every to the past.
            // For e.g., if the current time is 9:30 and every: {minute: 10} is set, the trigger
            // would be set to 9:10. To get a next trigger, the hour have to be increased by 1 to 10:10.
            if (nextCalendar.compareTo(baseCalendar) <= 0) {
                nextCalendar.add(nextTriggerCalendarFieldToIncrease, 1);
                // Correct trigger after incrementing it
                // Example: If weekday was set to monday and a year was added,
                // the weekday could be changed to another day, set to monday again
                setEveryValues(nextCalendar);
            }
        }

        // Check if the trigger is within the before option
        if (!isWithinTriggerbefore(nextCalendar)) return null;

        return nextCalendar.getTime();
    }
Calculates the next trigger.
@param baseCalendar The base calendar from where to calculate the next trigger.
src/android/trigger/TriggerHandlerEvery.java