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

The following examples show how to use android.icu.util.Calendar#JUNE . 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: DatePickerCalendarDelegate.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public static int getDaysInMonth(int month, int year) {
    switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            return 31;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            return 30;
        case Calendar.FEBRUARY:
            return (year % 4 == 0) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 2
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private static int getDaysInMonth(int month, int year) {
    switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            return 31;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            return 30;
        case Calendar.FEBRUARY:
            return (year % 4 == 0) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 3
Source File: DatePickerCalendarDelegate.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
public static int getDaysInMonth(int month, int year) {
    switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            return 31;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            return 30;
        case Calendar.FEBRUARY:
            return (year % 4 == 0) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 4
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
private static int getDaysInMonth(int month, int year) {
    switch (month) {
        case Calendar.JANUARY:
        case Calendar.MARCH:
        case Calendar.MAY:
        case Calendar.JULY:
        case Calendar.AUGUST:
        case Calendar.OCTOBER:
        case Calendar.DECEMBER:
            return 31;
        case Calendar.APRIL:
        case Calendar.JUNE:
        case Calendar.SEPTEMBER:
        case Calendar.NOVEMBER:
            return 30;
        case Calendar.FEBRUARY:
            return (year % 4 == 0) ? 29 : 28;
        default:
            throw new IllegalArgumentException("Invalid Month");
    }
}
 
Example 5
Source File: IBMCalendarTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Verify that JapaneseCalendar shifts years to Japanese Eras but otherwise
 * behaves like GregorianCalendar.
 */
@Test
public void TestJapanese() {
    // First make sure this test works for GregorianCalendar
    int[] control = {
        GregorianCalendar.AD, 1868, 1868, Calendar.SEPTEMBER, 8,
        GregorianCalendar.AD, 1868, 1868, Calendar.SEPTEMBER, 9,
        GregorianCalendar.AD, 1869, 1869, Calendar.JUNE, 4,
        GregorianCalendar.AD, 1912, 1912, Calendar.JULY, 29,
        GregorianCalendar.AD, 1912, 1912, Calendar.JULY, 30,
        GregorianCalendar.AD, 1912, 1912, Calendar.AUGUST, 1,
    };
    quasiGregorianTest(new GregorianCalendar(), control);

    int[] data = {
        JapaneseCalendar.MEIJI, 1, 1868, Calendar.SEPTEMBER, 8,
        JapaneseCalendar.MEIJI, 1, 1868, Calendar.SEPTEMBER, 9,
        JapaneseCalendar.MEIJI, 2, 1869, Calendar.JUNE, 4,
        JapaneseCalendar.MEIJI, 45, 1912, Calendar.JULY, 29,
        JapaneseCalendar.TAISHO, 1, 1912, Calendar.JULY, 30,
        JapaneseCalendar.TAISHO, 1, 1912, Calendar.AUGUST, 1,
    };
    quasiGregorianTest(new JapaneseCalendar(), data);
}
 
Example 6
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Test fieldDifference().
 */
@Test
public void TestJ438() throws Exception {
    int DATA[] = {
        2000, Calendar.JANUARY, 20,   2010, Calendar.JUNE, 15,
        2010, Calendar.JUNE, 15,      2000, Calendar.JANUARY, 20,
        1964, Calendar.SEPTEMBER, 7,  1999, Calendar.JUNE, 4,
        1999, Calendar.JUNE, 4,       1964, Calendar.SEPTEMBER, 7,
    };
    Calendar cal = Calendar.getInstance(Locale.US);
    for (int i=0; i<DATA.length; i+=6) {
        int y1 = DATA[i];
        int m1 = DATA[i+1];
        int d1 = DATA[i+2];
        int y2 = DATA[i+3];
        int m2 = DATA[i+4];
        int d2 = DATA[i+5];

        cal.clear();
        cal.set(y1, m1, d1);
        Date date1 = cal.getTime();
        cal.set(y2, m2, d2);
        Date date2 = cal.getTime();

        cal.setTime(date1);
        int dy = cal.fieldDifference(date2, Calendar.YEAR);
        int dm = cal.fieldDifference(date2, Calendar.MONTH);
        int dd = cal.fieldDifference(date2, Calendar.DATE);

        logln("" + date2 + " - " + date1 + " = " +
              dy + "y " + dm + "m " + dd + "d");

        cal.setTime(date1);
        cal.add(Calendar.YEAR, dy);
        cal.add(Calendar.MONTH, dm);
        cal.add(Calendar.DATE, dd);
        Date date22 = cal.getTime();
        if (!date2.equals(date22)) {
            errln("FAIL: " + date1 + " + " +
                  dy + "y " + dm + "m " + dd + "d = " +
                  date22 + ", exp " + date2);
        } else {
            logln("Ok: " + date1 + " + " +
                  dy + "y " + dm + "m " + dd + "d = " +
                  date22);
        }
    }
}
 
Example 7
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
    }
}