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

The following examples show how to use android.icu.util.Calendar#NOVEMBER . 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: CalendarRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void Test4095407() {
    GregorianCalendar a = new GregorianCalendar(1997,Calendar.NOVEMBER, 13);
    int dow = a.get(Calendar.DAY_OF_WEEK);
    if (dow != Calendar.THURSDAY)
        errln("Fail: Want THURSDAY Got " + dow);
}
 
Example 6
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Calendar.getActualMaximum(YEAR) works wrong.
 */
@Test
public void Test4167060() {
    int field = Calendar.YEAR;
    DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy G",
                                             Locale.US);

    GregorianCalendar calendars[] = {
        new GregorianCalendar(100, Calendar.NOVEMBER, 1),
        new GregorianCalendar(-99 /* 100BC */, Calendar.JANUARY, 1),
        new GregorianCalendar(1996, Calendar.FEBRUARY, 29),
    };

    String[] id = { "Hybrid", "Gregorian", "Julian" };

    for (int k=0; k<3; ++k) {
        logln("--- " + id[k] + " ---");

        for (int j=0; j<calendars.length; ++j) {
            GregorianCalendar calendar = calendars[j];
            if (k == 1) {
                calendar.setGregorianChange(new Date(Long.MIN_VALUE));
            } else if (k == 2) {
                calendar.setGregorianChange(new Date(Long.MAX_VALUE));
            }

            format.setCalendar((Calendar)calendar.clone());

            Date dateBefore = calendar.getTime();

            int maxYear = calendar.getActualMaximum(field);
            logln("maxYear: " + maxYear + " for " + format.format(calendar.getTime()));
            logln("date before: " + format.format(dateBefore));

            int years[] = {2000, maxYear-1, maxYear, maxYear+1};

            for (int i = 0; i < years.length; i++) {
                boolean valid = years[i] <= maxYear;
                calendar.set(field, years[i]);
                Date dateAfter = calendar.getTime();
                int newYear = calendar.get(field);
                calendar.setTime(dateBefore); // restore calendar for next
                                              // use

                logln(" Year " + years[i] + (valid? " ok " : " bad") +
                      " => " + format.format(dateAfter));
                if (valid && newYear != years[i]) {
                    errln("  FAIL: " + newYear + " should be valid; date, month and time shouldn't change");
                } else if (!valid && newYear == years[i]) {
                    // We no longer require strict year maxima. That is, the
                    // calendar
                    // algorithm may work for values > the stated maximum.
                    //errln(" FAIL: " + newYear + " should be invalid");
                    logln("  Note: " + newYear + " > maximum, but still valid");
                }
            }
        }
    }
}
 
Example 7
Source File: TimeZoneTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test
public void TestFebruary() {
    // Time zone with daylight savings time from the first Sunday in November
    // to the last Sunday in February.
    // Similar to the new rule for Brazil (Sao Paulo) in tzdata2006n.
    //
    // Note: In tzdata2007h, the rule had changed, so no actual zones uses
    // lastSun in Feb anymore.
    SimpleTimeZone tz1 = new SimpleTimeZone(
                       -3 * MILLIS_PER_HOUR,                    // raw offset: 3h before (west of) GMT
                       "nov-feb",
                       Calendar.NOVEMBER, 1, Calendar.SUNDAY,   // start: November, first, Sunday
                       0,                                       //        midnight wall time
                       Calendar.FEBRUARY, -1, Calendar.SUNDAY,  // end:   February, last, Sunday
                       0);                                      //        midnight wall time

    // Now hardcode the same rules as for Brazil in tzdata 2006n, so that
    // we cover the intended code even when in the future zoneinfo hardcodes
    // these transition dates.
    SimpleTimeZone tz2= new SimpleTimeZone(
                       -3 * MILLIS_PER_HOUR,                    // raw offset: 3h before (west of) GMT
                       "nov-feb2",
                       Calendar.NOVEMBER, 1, -Calendar.SUNDAY,  // start: November, 1 or after, Sunday
                       0,                                       //        midnight wall time
                       Calendar.FEBRUARY, -29, -Calendar.SUNDAY,// end:   February, 29 or before, Sunday
                       0);                                      //        midnight wall time

    // Gregorian calendar with the UTC time zone for getting sample test date/times.
    GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("Etc/GMT"));
    // "Unable to create the UTC calendar: %s"

    int[] data = {
        // UTC time (6 fields) followed by
        // expected time zone offset in hours after GMT (negative=before GMT).
        // int year, month, day, hour, minute, second, offsetHours
        2006, Calendar.NOVEMBER,  5, 02, 59, 59, -3,
        2006, Calendar.NOVEMBER,  5, 03, 00, 00, -2,
        2007, Calendar.FEBRUARY, 25, 01, 59, 59, -2,
        2007, Calendar.FEBRUARY, 25, 02, 00, 00, -3,

        2007, Calendar.NOVEMBER,  4, 02, 59, 59, -3,
        2007, Calendar.NOVEMBER,  4, 03, 00, 00, -2,
        2008, Calendar.FEBRUARY, 24, 01, 59, 59, -2,
        2008, Calendar.FEBRUARY, 24, 02, 00, 00, -3,

        2008, Calendar.NOVEMBER,  2, 02, 59, 59, -3,
        2008, Calendar.NOVEMBER,  2, 03, 00, 00, -2,
        2009, Calendar.FEBRUARY, 22, 01, 59, 59, -2,
        2009, Calendar.FEBRUARY, 22, 02, 00, 00, -3,

        2009, Calendar.NOVEMBER,  1, 02, 59, 59, -3,
        2009, Calendar.NOVEMBER,  1, 03, 00, 00, -2,
        2010, Calendar.FEBRUARY, 28, 01, 59, 59, -2,
        2010, Calendar.FEBRUARY, 28, 02, 00, 00, -3
    };

    TimeZone timezones[] = { tz1, tz2 };

    TimeZone tz;
    Date dt;
    int t, i, raw, dst;
    int[] offsets = new int[2]; // raw = offsets[0], dst = offsets[1]
    for (t = 0; t < timezones.length; ++t) {
        tz = timezones[t];
        for (i = 0; i < data.length; i+=7) {
            gc.set(data[i], data[i+1], data[i+2],
                   data[i+3], data[i+4], data[i+5]);
            dt = gc.getTime();
            tz.getOffset(dt.getTime(), false, offsets);
            raw = offsets[0];
            dst = offsets[1];
            if ((raw + dst) != data[i+6] * MILLIS_PER_HOUR) {
                errln("test case " + t + "." + (i/7) + ": " +
                      "tz.getOffset(" + data[i] + "-" + (data[i+1] + 1) + "-" + data[i+2] + " " +
                      data[i+3] + ":" + data[i+4] + ":" + data[i+5] +
                      ") returns " + raw + "+" + dst + " != " + data[i+6] * MILLIS_PER_HOUR);
            }
        }
    }
}
 
Example 8
Source File: TimeZoneTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test
public void TestObservesDaylightTime() {
    boolean observesDaylight;
    long current = System.currentTimeMillis();

    // J2ObjC change: time zones going through adjustments are problematic when comparing
    // the ICU tz data vs. the operating system tz data.
    Set<String> unstableTzids = new HashSet<>();
    // https://github.com/eggert/tz/blob/379f7ba9b81eee97f0209a322540b4a522122b5d/africa#L847
    unstableTzids.add("Africa/Casablanca");
    unstableTzids.add("Africa/El_Aaiun");

    String[] tzids = TimeZone.getAvailableIDs();
    for (String tzid : tzids) {
        // OlsonTimeZone
        TimeZone tz = TimeZone.getTimeZone(tzid, TimeZone.TIMEZONE_ICU);
        observesDaylight = tz.observesDaylightTime();
        if (observesDaylight != isDaylightTimeAvailable(tz, current)) {
            errln("Fail: [OlsonTimeZone] observesDaylightTime() returned " + observesDaylight + " for " + tzid);
        }

        // RuleBasedTimeZone
        RuleBasedTimeZone rbtz = createRBTZ((BasicTimeZone)tz, current);
        boolean observesDaylightRBTZ = rbtz.observesDaylightTime();
        if (observesDaylightRBTZ != isDaylightTimeAvailable(rbtz, current)) {
            errln("Fail: [RuleBasedTimeZone] observesDaylightTime() returned " + observesDaylightRBTZ + " for " + rbtz.getID());
        } else if (observesDaylight != observesDaylightRBTZ) {
            errln("Fail: RuleBasedTimeZone " + rbtz.getID() + " returns " + observesDaylightRBTZ + ", but different from match OlsonTimeZone");
        }

        // JavaTimeZone
        tz = TimeZone.getTimeZone(tzid, TimeZone.TIMEZONE_JDK);
        observesDaylight = tz.observesDaylightTime();
        if (!unstableTzids.contains(tzid)
            && observesDaylight != isDaylightTimeAvailable(tz, current)) {
            errln("Fail: [JavaTimeZone] observesDaylightTime() returned " + observesDaylight + " for " + tzid);
        }

        // VTimeZone
        tz = VTimeZone.getTimeZone(tzid);
        observesDaylight = tz.observesDaylightTime();
        if (observesDaylight != isDaylightTimeAvailable(tz, current)) {
            errln("Fail: [VTimeZone] observesDaylightTime() returned " + observesDaylight + " for " + tzid);
        }
    }

    // SimpleTimeZone
    SimpleTimeZone[] stzs = {
        new SimpleTimeZone(0, "STZ0"),
        new SimpleTimeZone(-5*60*60*1000, "STZ-5D", Calendar.MARCH, 2, Calendar.SUNDAY, 2*60*60*1000,
                Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2*60*60*1000),
    };
    for (SimpleTimeZone stz : stzs) {
        observesDaylight = stz.observesDaylightTime();
        if (observesDaylight != isDaylightTimeAvailable(stz, current)) {
            errln("Fail: [SimpleTimeZone] observesDaylightTime() returned " + observesDaylight + " for " + stz.getID());
        }
    }
}