Java Code Examples for android.icu.util.Calendar#MONTH

The following examples show how to use android.icu.util.Calendar#MONTH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateIntervalFormat.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated This API is ICU internal only.
 * @hide original deprecated declaration
 * @hide draft / provisional / internal are hidden on Android
 */
@Deprecated
public String getPatterns(Calendar fromCalendar,
        Calendar toCalendar, 
        Output<String> part2) {
    // First, find the largest different calendar field.
    int field;
    if ( fromCalendar.get(Calendar.ERA) != toCalendar.get(Calendar.ERA) ) {
        field = Calendar.ERA;
    } else if ( fromCalendar.get(Calendar.YEAR) != 
                toCalendar.get(Calendar.YEAR) ) {
        field = Calendar.YEAR;
    } else if ( fromCalendar.get(Calendar.MONTH) !=
                toCalendar.get(Calendar.MONTH) ) {
        field = Calendar.MONTH;
    } else if ( fromCalendar.get(Calendar.DATE) !=
                toCalendar.get(Calendar.DATE) ) {
        field = Calendar.DATE;
    } else if ( fromCalendar.get(Calendar.AM_PM) !=
                toCalendar.get(Calendar.AM_PM) ) {
        field = Calendar.AM_PM;
    } else if ( fromCalendar.get(Calendar.HOUR) !=
                toCalendar.get(Calendar.HOUR) ) {
        field = Calendar.HOUR;
    } else if ( fromCalendar.get(Calendar.MINUTE) !=
                toCalendar.get(Calendar.MINUTE) ) {
        field = Calendar.MINUTE;
    } else if ( fromCalendar.get(Calendar.SECOND) !=
                toCalendar.get(Calendar.SECOND) ) {
        field = Calendar.SECOND;
    } else {
        return null;
    }
    PatternInfo intervalPattern = fIntervalPatterns.get(
            DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]);
    part2.value = intervalPattern.getSecondPart();
    return intervalPattern.getFirstPart();
}
 
Example 2
Source File: CalendarFieldsSet.java    From j2objc with Apache License 2.0 5 votes vote down vote up
protected void handleParseValue(FieldsSet inheritFrom, int field, String substr) {
    if(field == Calendar.MONTH) {
        parseValueEnum(DebugUtilitiesData.UCalendarMonths, inheritFrom, field, substr);
        // will fallback to default.
    } else {
        parseValueDefault(inheritFrom, field, substr);
    }
}
 
Example 3
Source File: DangiTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Make sure IS_LEAP_MONTH participates in field resolution.
 */
@Test
public void TestResolution() {
    Calendar cal = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
    DateFormat fmt = DateFormat.getDateInstance(cal, DateFormat.DEFAULT);

    // May 22 4334 = y4334 m4 d30 doy119
    // May 23 4334 = y4334 m4* d1 doy120

    final int THE_YEAR = 4334;
    final int END = -1;

    int[] DATA = {
        // Format:
        // (field, value)+, END, exp.month, exp.isLeapMonth, exp.DOM
        // Note: exp.month is ONE-BASED

        // If we set DAY_OF_YEAR only, that should be used
        Calendar.DAY_OF_YEAR, 1,
        END,
        1,0,1, // Expect 1-1
        
        // If we set MONTH only, that should be used
        Calendar.IS_LEAP_MONTH, 1,
        Calendar.DAY_OF_MONTH, 1,
        Calendar.MONTH, 3,
        END,
        4,1,1, // Expect 4*-1
        
        // If we set the DOY last, that should take precedence
        Calendar.MONTH, 1, // Should ignore
        Calendar.IS_LEAP_MONTH, 1, // Should ignore
        Calendar.DAY_OF_MONTH, 1, // Should ignore
        Calendar.DAY_OF_YEAR, 121,
        END,
        4,1,2, // Expect 4*-2
        
        // If we set IS_LEAP_MONTH last, that should take precedence
        Calendar.MONTH, 3,
        Calendar.DAY_OF_MONTH, 1,
        Calendar.DAY_OF_YEAR, 5, // Should ignore
        Calendar.IS_LEAP_MONTH, 1,
        END,
        4,1,1, // Expect 4*-1
    };

    StringBuilder buf = new StringBuilder();
    for (int i=0; i<DATA.length; ) {
        cal.clear();
        cal.set(Calendar.EXTENDED_YEAR, THE_YEAR);
        buf.setLength(0);
        buf.append("EXTENDED_YEAR=" + THE_YEAR);
        while (DATA[i] != END) {
            cal.set(DATA[i++], DATA[i++]);
            buf.append(" " + fieldName(DATA[i-2]) + "=" + DATA[i-1]);
        }
        ++i; // Skip over END mark
        int expMonth = DATA[i++]-1;
        int expIsLeapMonth = DATA[i++];
        int expDOM = DATA[i++];
        int month = cal.get(Calendar.MONTH);
        int isLeapMonth = cal.get(Calendar.IS_LEAP_MONTH);
        int dom = cal.get(Calendar.DAY_OF_MONTH);
        if (expMonth == month && expIsLeapMonth == isLeapMonth &&
            dom == expDOM) {
            logln("OK: " + buf + " => " + fmt.format(cal.getTime()));
        } else {
            String s = fmt.format(cal.getTime());
            cal.clear();
            cal.set(Calendar.EXTENDED_YEAR, THE_YEAR);
            cal.set(Calendar.MONTH, expMonth);
            cal.set(Calendar.IS_LEAP_MONTH, expIsLeapMonth);
            cal.set(Calendar.DAY_OF_MONTH, expDOM);
            errln("Fail: " + buf + " => " + s +
                  "=" + (month+1) + "," + isLeapMonth + "," + dom +
                  ", expected " + fmt.format(cal.getTime()) +
                  "=" + (expMonth+1) + "," + expIsLeapMonth + "," + expDOM);
        }
    }
}
 
Example 4
Source File: ChineseTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Make sure IS_LEAP_MONTH participates in field resolution.
 */
@Test
public void TestResolution() {
    ChineseCalendar cal = new ChineseCalendar();
    DateFormat fmt = DateFormat.getDateInstance(cal, DateFormat.DEFAULT);

    // May 22 2001 = y4638 m4 d30 doy119
    // May 23 2001 = y4638 m4* d1 doy120

    final int THE_YEAR = 4638;
    final int END = -1;

    int[] DATA = {
        // Format:
        // (field, value)+, END, exp.month, exp.isLeapMonth, exp.DOM
        // Note: exp.month is ONE-BASED

        // If we set DAY_OF_YEAR only, that should be used
        Calendar.DAY_OF_YEAR, 1,
        END,
        1,0,1, // Expect 1-1
        
        // If we set MONTH only, that should be used
        Calendar.IS_LEAP_MONTH, 1,
        Calendar.DAY_OF_MONTH, 1,
        Calendar.MONTH, 3,
        END,
        4,1,1, // Expect 4*-1
        
        // If we set the DOY last, that should take precedence
        Calendar.MONTH, 1, // Should ignore
        Calendar.IS_LEAP_MONTH, 1, // Should ignore
        Calendar.DAY_OF_MONTH, 1, // Should ignore
        Calendar.DAY_OF_YEAR, 121,
        END,
        4,1,2, // Expect 4*-2
        
        // I've disabled this test because it doesn't work this way,
        // not even with a GregorianCalendar!  MONTH alone isn't enough
        // to supersede DAY_OF_YEAR.  Some other month-related field is
        // also required. - Liu 11/28/00
        //! // If we set MONTH last, that should take precedence
        //! ChineseCalendar.IS_LEAP_MONTH, 1,
        //! Calendar.DAY_OF_MONTH, 1,
        //! Calendar.DAY_OF_YEAR, 5, // Should ignore
        //! Calendar.MONTH, 3,
        //! END,
        //! 4,1,1, // Expect 4*-1
        
        // If we set IS_LEAP_MONTH last, that should take precedence
        Calendar.MONTH, 3,
        Calendar.DAY_OF_MONTH, 1,
        Calendar.DAY_OF_YEAR, 5, // Should ignore
        Calendar.IS_LEAP_MONTH, 1,
        END,
        4,1,1, // Expect 4*-1
    };

    StringBuffer buf = new StringBuffer();
    for (int i=0; i<DATA.length; ) {
        cal.clear();
        cal.set(Calendar.EXTENDED_YEAR, THE_YEAR);
        buf.setLength(0);
        buf.append("EXTENDED_YEAR=" + THE_YEAR);
        while (DATA[i] != END) {
            cal.set(DATA[i++], DATA[i++]);
            buf.append(" " + fieldName(DATA[i-2]) + "=" + DATA[i-1]);
        }
        ++i; // Skip over END mark
        int expMonth = DATA[i++]-1;
        int expIsLeapMonth = DATA[i++];
        int expDOM = DATA[i++];
        int month = cal.get(Calendar.MONTH);
        int isLeapMonth = cal.get(Calendar.IS_LEAP_MONTH);
        int dom = cal.get(Calendar.DAY_OF_MONTH);
        if (expMonth == month && expIsLeapMonth == isLeapMonth &&
            dom == expDOM) {
            logln("OK: " + buf + " => " + fmt.format(cal.getTime()));
        } else {
            String s = fmt.format(cal.getTime());
            cal.clear();
            cal.set(Calendar.EXTENDED_YEAR, THE_YEAR);
            cal.set(Calendar.MONTH, expMonth);
            cal.set(Calendar.IS_LEAP_MONTH, expIsLeapMonth);
            cal.set(Calendar.DAY_OF_MONTH, expDOM);
            errln("Fail: " + buf + " => " + s +
                  "=" + (month+1) + "," + isLeapMonth + "," + dom +
                  ", expected " + fmt.format(cal.getTime()) +
                  "=" + (expMonth+1) + "," + expIsLeapMonth + "," + expDOM);
        }
    }
}
 
Example 5
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Set behavior of DST_OFFSET field. ICU4J Jitterbug 9.
 */
@Test
public void TestJ9() {
    int HOURS = 60*60*1000;
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("PST"),
                                         Locale.US);

    final int END_FIELDS = 0x1234;

    int[] DATA = {
        // With no explicit ZONE/DST expect 12:00 am
        Calendar.MONTH, Calendar.JUNE,
        END_FIELDS,
        0, 0, // expected hour, min

        // Normal ZONE/DST for June 1 Pacific is 8:00/1:00
        Calendar.MONTH, Calendar.JUNE,
        Calendar.ZONE_OFFSET, -8*HOURS,
        Calendar.DST_OFFSET, HOURS,
        END_FIELDS,
        0, 0, // expected hour, min

        // With ZONE/DST of 8:00/0:30 expect time of 12:30 am
        Calendar.MONTH, Calendar.JUNE,
        Calendar.ZONE_OFFSET, -8*HOURS,
        Calendar.DST_OFFSET, HOURS/2,
        END_FIELDS,
        0, 30, // expected hour, min

        // With ZONE/DST of 8:00/UNSET expect time of 1:00 am
        Calendar.MONTH, Calendar.JUNE,
        Calendar.ZONE_OFFSET, -8*HOURS,
        END_FIELDS,
        1, 0, // expected hour, min

        // With ZONE/DST of UNSET/0:30 expect 4:30 pm (day before)
        Calendar.MONTH, Calendar.JUNE,
        Calendar.DST_OFFSET, HOURS/2,
        END_FIELDS,
        16, 30, // expected hour, min
    };

    for (int i=0; i<DATA.length; ) {
        int start = i;
        cal.clear();

        // Set fields
        while (DATA[i] != END_FIELDS) {
            cal.set(DATA[i++], DATA[i++]);
        }
        ++i; // skip over END_FIELDS

        // Get hour/minute
        int h = cal.get(Calendar.HOUR_OF_DAY);
        int m = cal.get(Calendar.MINUTE);

        // Check
        if (h != DATA[i] || m != DATA[i+1]) {
            errln("Fail: expected " + DATA[i] + ":" + DATA[i+1] +
                  ", got " + h + ":" + m + " after:");
            while (DATA[start] != END_FIELDS) {
                logln("set(" + FIELD_NAME[DATA[start++]] +
                      ", " + DATA[start++] + ");");
            }
        }

        i += 2; // skip over expected hour, min
    }
}