void CalendarRegressionTest::test4040996()
{
    int32_t count = 0;
    StringEnumeration* ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
    if (ids == NULL) {
        dataerrln("Unable to create TimeZone enumeration.");
        return;
    }
    UErrorCode status = U_ZERO_ERROR;
    count = ids->count(status);
    (void)count;    // Suppress set but not used warning.
    SimpleTimeZone *pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *ids->snext(status));
    pdt->setStartRule(UCAL_APRIL, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000, status);
    pdt->setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2 * 60 * 60 * 1000, status);
    Calendar *calendar = new GregorianCalendar(pdt, status);
    if (U_FAILURE(status)) {
        dataerrln("Fail new GregorianCalendar: %s", u_errorName(status));
        return;
    }
    calendar->set(UCAL_MONTH,3);
    calendar->set(UCAL_DATE,18);
    calendar->set(UCAL_SECOND, 30);

    logln(UnicodeString("MONTH: ") + calendar->get(UCAL_MONTH, status));
    logln(UnicodeString("DAY_OF_MONTH: ") +
                       calendar->get(UCAL_DATE, status));
    logln(UnicodeString("MINUTE: ") + calendar->get(UCAL_MINUTE, status));
    logln(UnicodeString("SECOND: ") + calendar->get(UCAL_SECOND, status));

    calendar->add(UCAL_SECOND,6, status);
    //This will print out todays date for MONTH and DAY_OF_MONTH
    //instead of the date it was set to.
    //This happens when adding MILLISECOND or MINUTE also
    logln(UnicodeString("MONTH: ") + calendar->get(UCAL_MONTH, status));
    logln(UnicodeString("DAY_OF_MONTH: ") +
                       calendar->get(UCAL_DATE, status));
    logln(UnicodeString("MINUTE: ") + calendar->get(UCAL_MINUTE, status));
    logln(UnicodeString("SECOND: ") + calendar->get(UCAL_SECOND, status));
    if (calendar->get(UCAL_MONTH, status) != 3 ||
        calendar->get(UCAL_DATE, status) != 18 ||
        calendar->get(UCAL_SECOND, status) != 36)
        errln(UnicodeString("Fail: Calendar::add misbehaves"));

    delete calendar;
    delete ids;
    // delete ids;   // TODO:  BAD API
}
void CalendarRegressionTest::test4040996()
{
    int32_t count = 0;
    StringEnumeration* ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000);
    if (ids == NULL) {
        dataerrln("Unable to create TimeZone enumeration.");
        return;
    }
    UErrorCode status = U_ZERO_ERROR;
    count = ids->count(status);
    (void)count;     
    SimpleTimeZone *pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *ids->snext(status));
    pdt->setStartRule(UCAL_APRIL, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000, status);
    pdt->setEndRule(UCAL_OCTOBER, -1, UCAL_SUNDAY, 2 * 60 * 60 * 1000, status);
    Calendar *calendar = new GregorianCalendar(pdt, status);
    if (U_FAILURE(status)) {
        dataerrln("Fail new GregorianCalendar: %s", u_errorName(status));
        return;
    }
    calendar->set(UCAL_MONTH,3);
    calendar->set(UCAL_DATE,18);
    calendar->set(UCAL_SECOND, 30);

    logln(UnicodeString("MONTH: ") + calendar->get(UCAL_MONTH, status));
    logln(UnicodeString("DAY_OF_MONTH: ") +
                       calendar->get(UCAL_DATE, status));
    logln(UnicodeString("MINUTE: ") + calendar->get(UCAL_MINUTE, status));
    logln(UnicodeString("SECOND: ") + calendar->get(UCAL_SECOND, status));

    calendar->add(UCAL_SECOND,6, status);
     
     
     
    logln(UnicodeString("MONTH: ") + calendar->get(UCAL_MONTH, status));
    logln(UnicodeString("DAY_OF_MONTH: ") +
                       calendar->get(UCAL_DATE, status));
    logln(UnicodeString("MINUTE: ") + calendar->get(UCAL_MINUTE, status));
    logln(UnicodeString("SECOND: ") + calendar->get(UCAL_SECOND, status));
    if (calendar->get(UCAL_MONTH, status) != 3 ||
        calendar->get(UCAL_DATE, status) != 18 ||
        calendar->get(UCAL_SECOND, status) != 36)
        errln(UnicodeString("Fail: Calendar::add misbehaves"));

    delete calendar;
    delete ids;
     
}