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

The following examples show how to use android.icu.util.Calendar#DECEMBER . 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: OlsonTimeZone.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) {
    if (month < Calendar.JANUARY || month > Calendar.DECEMBER) {
        throw new IllegalArgumentException("Month is not in the legal range: " +month);
    } else {
        return getOffset(era, year, month, day, dayOfWeek, milliseconds, Grego.monthLength(year, month));
    }
}
 
Example 6
Source File: OlsonTimeZone.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * TimeZone API.
 */
public int getOffset(int era, int year, int month,int dom, int dow, int millis, int monthLength){

    if ((era != GregorianCalendar.AD && era != GregorianCalendar.BC)
        || month < Calendar.JANUARY
        || month > Calendar.DECEMBER
        || dom < 1
        || dom > monthLength
        || dow < Calendar.SUNDAY
        || dow > Calendar.SATURDAY
        || millis < 0
        || millis >= Grego.MILLIS_PER_DAY
        || monthLength < 28
        || monthLength > 31) {
        throw new IllegalArgumentException();
    }

    if (era == GregorianCalendar.BC) {
        year = -year;
    }

    if (finalZone != null && year >= finalStartYear) {
        return finalZone.getOffset(era, year, month, dom, dow, millis);
    }

    // Compute local epoch millis from input fields
    long time = Grego.fieldsToDay(year, month, dom) * Grego.MILLIS_PER_DAY + millis;

    int[] offsets = new int[2];
    getHistoricalOffset(time, true, LOCAL_DST, LOCAL_STD, offsets);
    return offsets[0] + offsets[1];
}
 
Example 7
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Week of year is wrong at the start and end of the year.
 */
@Test
public void Test4197699() {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setFirstDayOfWeek(Calendar.MONDAY);
    cal.setMinimalDaysInFirstWeek(4);
    DateFormat fmt = new SimpleDateFormat("E dd MMM yyyy  'DOY='D 'WOY='w");
    fmt.setCalendar(cal);

    int[] DATA = {
        2000,  Calendar.JANUARY,   1,   52,
        2001,  Calendar.DECEMBER,  31,  1,
    };

    for (int i=0; i<DATA.length; ) {
        cal.set(DATA[i++], DATA[i++], DATA[i++]);
        int expWOY = DATA[i++];
        int actWOY = cal.get(Calendar.WEEK_OF_YEAR);
        if (expWOY == actWOY) {
            logln("Ok: " + fmt.format(cal.getTime()));
        } else {
            errln("FAIL: " + fmt.format(cal.getTime())
                  + ", expected WOY=" + expWOY);
            cal.add(Calendar.DATE, -8);
            for (int j=0; j<14; ++j) {
                cal.add(Calendar.DATE, 1);
                logln(fmt.format(cal.getTime()));
            }
        }
    }
}
 
Example 8
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static boolean isValidMonth(int month) {
    return month >= Calendar.JANUARY && month <= Calendar.DECEMBER;
}
 
Example 9
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
private static boolean isValidMonth(int month) {
    return month >= Calendar.JANUARY && month <= Calendar.DECEMBER;
}
 
Example 10
Source File: TimeZoneRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * SimpleTimeZone.getOffset accepts illegal arguments.
 */
@Test
public void Test4154650() {
    final int GOOD=1, BAD=0;
    final int GOOD_ERA=GregorianCalendar.AD, GOOD_YEAR=1998, GOOD_MONTH=Calendar.AUGUST;
    final int GOOD_DAY=2, GOOD_DOW=Calendar.SUNDAY, GOOD_TIME=16*3600000;
    int[] DATA = {
        GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME,

        GOOD, GregorianCalendar.BC, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME,
        GOOD, GregorianCalendar.AD, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME,
        BAD,  GregorianCalendar.BC-1, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME,
        BAD,  GregorianCalendar.AD+1, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, GOOD_TIME,

        GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, GOOD_DAY, GOOD_DOW, GOOD_TIME,
        GOOD, GOOD_ERA, GOOD_YEAR, Calendar.DECEMBER, GOOD_DAY, GOOD_DOW, GOOD_TIME,
        BAD,  GOOD_ERA, GOOD_YEAR, Calendar.JANUARY-1, GOOD_DAY, GOOD_DOW, GOOD_TIME,
        BAD,  GOOD_ERA, GOOD_YEAR, Calendar.DECEMBER+1, GOOD_DAY, GOOD_DOW, GOOD_TIME,

        GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 1, GOOD_DOW, GOOD_TIME,
        GOOD, GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 31, GOOD_DOW, GOOD_TIME,
        BAD,  GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 0, GOOD_DOW, GOOD_TIME,
        BAD,  GOOD_ERA, GOOD_YEAR, Calendar.JANUARY, 32, GOOD_DOW, GOOD_TIME,

        GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SUNDAY, GOOD_TIME,
        GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SATURDAY, GOOD_TIME,
        BAD,  GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SUNDAY-1, GOOD_TIME,
        BAD,  GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, Calendar.SATURDAY+1, GOOD_TIME,

        GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 0,
        GOOD, GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 24*3600000-1,
        BAD,  GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, -1,
        BAD,  GOOD_ERA, GOOD_YEAR, GOOD_MONTH, GOOD_DAY, GOOD_DOW, 24*3600000,
    };

    TimeZone tz = TimeZone.getDefault();
    for (int i=0; i<DATA.length; i+=7) {
        boolean good = DATA[i] == GOOD;
        IllegalArgumentException e = null;
        try {
            /*int offset =*/ tz.getOffset(DATA[i+1], DATA[i+2], DATA[i+3],
                                      DATA[i+4], DATA[i+5], DATA[i+6]);
            //offset = 0;
       } catch (IllegalArgumentException ex) {
            e = ex;
        }
        if (good != (e == null)) {
            errln("Fail: getOffset(" +
                  DATA[i+1] + ", " + DATA[i+2] + ", " + DATA[i+3] + ", " +
                  DATA[i+4] + ", " + DATA[i+5] + ", " + DATA[i+6] +
                  (good ? (") threw " + e) : ") accepts invalid args"));
        }
    }
}