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

The following examples show how to use android.icu.util.Calendar#JANUARY . 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: 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 2
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 3
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 4
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 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: ChineseTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void Test6510() 
{ 
    Calendar gregorianCalendar; 
    ChineseCalendar chineseCalendar, chineseCalendar2; 
    ChineseDateFormat dateFormat; 
    SimpleDateFormat simpleDateFormat; 
 
    simpleDateFormat = new android.icu.text.SimpleDateFormat("MM/dd/yyyy G 'at' HH:mm:ss vvvv", Locale.US); 
    dateFormat = new android.icu.text.ChineseDateFormat("MM/dd/yyyy(G) HH:mm:ss", Locale.CHINA); 
 
    // lunar to gregorian 
    chineseCalendar = new ChineseCalendar(77, 26, Calendar.JANUARY, 0, 6, 0, 0, 0); 
    // coverage
    assertEquals("equivalent ChineseCalendar() constructors", chineseCalendar,
            new ChineseCalendar(77, 26, Calendar.JANUARY, 0, 6));

    gregorianCalendar = Calendar.getInstance(Locale.US); 
    gregorianCalendar.setTime(chineseCalendar.getTime()); 
 
    // gregorian to lunar 
    chineseCalendar2 = new ChineseCalendar(); 
    chineseCalendar2.setTimeInMillis(gregorianCalendar.getTimeInMillis()); 

    // validate roundtrip 
    if (chineseCalendar.getTimeInMillis() != chineseCalendar2.getTimeInMillis()) 
    { 
        errln("time1: " + chineseCalendar.getTimeInMillis()); 
        errln("time2: " + chineseCalendar2.getTimeInMillis()); 
        errln("Lunar [MM/dd/y(G) HH:mm:ss] " + dateFormat.format(chineseCalendar)); 
        errln("**PROBLEM Grego [MM/dd/y(G) HH:mm:ss] " + simpleDateFormat.format(gregorianCalendar)); 
        errln("Grego [MM/dd/y(G) HH:mm:ss] " + simpleDateFormat.format(gregorianCalendar)); 
        errln("Lunar [MM/dd/y(G) HH:mm:ss] " + dateFormat.format(chineseCalendar2)); 
    } 
}
 
Example 8
Source File: TimeZoneRuleTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestT8943() {
    String id = "Ekaterinburg Time";
    String stdName = "Ekaterinburg Standard Time";
    String dstName = "Ekaterinburg Daylight Time";

    InitialTimeZoneRule initialRule = new InitialTimeZoneRule(stdName, 18000000, 0);
    RuleBasedTimeZone rbtz = new RuleBasedTimeZone(id, initialRule);

    DateTimeRule dtRule = new DateTimeRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 10800000, DateTimeRule.WALL_TIME);
    AnnualTimeZoneRule atzRule = new AnnualTimeZoneRule(stdName, 18000000, 0, dtRule, 2000, 2010);
    rbtz.addTransitionRule(atzRule);

    dtRule = new DateTimeRule(Calendar.MARCH, -1, Calendar.SUNDAY, 7200000, DateTimeRule.WALL_TIME);
    atzRule = new AnnualTimeZoneRule(dstName, 18000000, 3600000, dtRule, 2000, 2010);
    rbtz.addTransitionRule(atzRule);

    dtRule = new DateTimeRule(Calendar.JANUARY, 1, 0, DateTimeRule.WALL_TIME);
    atzRule = new AnnualTimeZoneRule(stdName, 21600000, 0, dtRule, 2011, AnnualTimeZoneRule.MAX_YEAR);
    rbtz.addTransitionRule(atzRule);

    dtRule = new DateTimeRule(Calendar.JANUARY, 1, 1, DateTimeRule.WALL_TIME);
    atzRule = new AnnualTimeZoneRule(dstName, 21600000, 0, dtRule, 2011, AnnualTimeZoneRule.MAX_YEAR);
    rbtz.addTransitionRule(atzRule);

    int[] expected = {21600000, 0};
    int[] offsets = new int[2];
    try {
        rbtz.getOffset(1293822000000L /* 2010-12-31 19:00:00 UTC */, false, offsets);
        if (offsets[0] != expected[0] || offsets[1] != expected[1]) {
            errln("Fail: Wrong offsets: " + offsets[0] + "/" + offsets[1] + " Expected: " + expected[0] + "/" + expected[1]);
        }
    } catch (Exception e) {
        errln("Fail: Exception thrown - " + e.getMessage());
    }
}
 
Example 9
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 10
Source File: TimeZoneRuleTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestT6669() {
    // getNext/PreviousTransition implementation in SimpleTimeZone
    // used to use a bad condition for detecting if DST is enabled or not.

    SimpleTimeZone stz = new SimpleTimeZone(0, "CustomID",
            Calendar.JANUARY, 1, Calendar.SUNDAY, 0,
            Calendar.JULY, 1, Calendar.SUNDAY, 0);

    long t = 1230681600000L; //2008-12-31T00:00:00
    long expectedNext = 1231027200000L; //2009-01-04T00:00:00
    long expectedPrev = 1215298800000L; //2008-07-06T00:00:00

    TimeZoneTransition tzt = stz.getNextTransition(t, false);
    if (tzt == null) {
        errln("FAIL: No transition returned by getNextTransition.");
    } else if (tzt.getTime() != expectedNext){
        errln("FAIL: Wrong transition time returned by getNextTransition - "
                + tzt.getTime() + " Expected: " + expectedNext);
    }

    tzt = stz.getPreviousTransition(t, true);
    if (tzt == null) {
        errln("FAIL: No transition returned by getPreviousTransition.");
    } else if (tzt.getTime() != expectedPrev){
        errln("FAIL: Wrong transition time returned by getPreviousTransition - "
                + tzt.getTime() + " Expected: " + expectedPrev);
    }
}
 
Example 11
Source File: CompatibilityTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
     * Test the behavior of the GregorianCalendar around the changeover.
     */
    @Test
    public void TestGregorianChangeover() {
    
        java.util.TimeZone jdkGMT = java.util.TimeZone.getTimeZone("GMT");
        java.util.Calendar jdkCal = java.util.Calendar.getInstance(jdkGMT);
        jdkCal.clear();
        jdkCal.set(1582, Calendar.OCTOBER, 15);
        
//      if(jdkCal instanceof java.util.GregorianCalendar) {
//          logln("jdk IS grego");
//          java.util.GregorianCalendar jdkgc = (java.util.GregorianCalendar)
//          jdkCal;
//          logln("jdk change at: " + jdkgc.getGregorianChange() + "(" + jdkgc.getGregorianChange().getTime() +")" );
//      } else {
//          logln("jdk NOT grego");
//      }

        long a = jdkCal.getTime().getTime();
        Date c = jdkCal.getTime();
        c.toString();
        long b = c.getTime();
        if(a!=b) {
            logln(" " + a + " != " + b);
            logln("JDK has Gregorian cutover anomaly (1.5?) - skipping this test.");
            return;
        }

        Date co = jdkCal.getTime();
        logln("Change over (Oct 15 1582) = " + co + " (" + co.getTime() + ")");
        final int ONE_DAY = 24*60*60*1000;
        TimeZone gmt = TimeZone.getTimeZone("GMT");
        GregorianCalendar cal = new GregorianCalendar(gmt);
        /*
          Changeover -7 days: 1582/9/28 dow=6
          Changeover -6 days: 1582/9/29 dow=7
          Changeover -5 days: 1582/9/30 dow=1
          Changeover -4 days: 1582/10/1 dow=2
          Changeover -3 days: 1582/10/2 dow=3
          Changeover -2 days: 1582/10/3 dow=4
          Changeover -1 days: 1582/10/4 dow=5
          Changeover +0 days: 1582/10/15 dow=6
          Changeover +1 days: 1582/10/16 dow=7
          Changeover +2 days: 1582/10/17 dow=1
          Changeover +3 days: 1582/10/18 dow=2
          Changeover +4 days: 1582/10/19 dow=3
          Changeover +5 days: 1582/10/20 dow=4
          Changeover +6 days: 1582/10/21 dow=5
          Changeover +7 days: 1582/10/22 dow=6
          */
        int MON[] = {  9,  9,  9,10,10,10,10, 10, 10, 10, 10, 10, 10, 10, 10 };
        int DOM[] = { 28, 29, 30, 1, 2, 3, 4, 15, 16, 17, 18, 19, 20, 21, 22 };
        int DOW[] = {  6,  7,  1, 2, 3, 4, 5,  6,  7,  1,  2,  3,  4,  5,  6 };
        //                                     ^ <-Changeover Fri Oct 15 1582
        int j=0;
        for (int i=-7; i<=7; ++i, ++j) {
            Date d = new Date(co.getTime() + i*ONE_DAY);
            cal.setTime(d);
            int y = cal.get(Calendar.YEAR), mon = cal.get(Calendar.MONTH)+1-Calendar.JANUARY,
                dom = cal.get(Calendar.DATE), dow = cal.get(Calendar.DAY_OF_WEEK);
            logln("Changeover " + (i>=0?"+":"") +
                  i + " days: " + y + "/" + mon + "/" + dom + " dow=" + dow);
            if (y != 1582 || mon != MON[j] || dom != DOM[j] || dow != DOW[j])
                errln(" Fail: Above line is wrong");
        }
    }
 
Example 12
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"));
        }
    }
}
 
Example 13
Source File: TimeZoneRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * SimpleTimeZone accepts illegal DST savings values.  These values
 * must be non-zero.  There is no upper limit at this time.
 */
@Test
public void Test4154525() {
    final int GOOD = 1, BAD = 0;
    int[] DATA = {
        1, GOOD,
        0, BAD,
        -1, BAD,
        60*60*1000, GOOD,
        Integer.MIN_VALUE, BAD,
        // Integer.MAX_VALUE, ?, // no upper limit on DST savings at this time
    };
    for (int i=0; i<DATA.length; i+=2) {
        int savings = DATA[i];
        boolean valid = DATA[i+1] == GOOD;
        String method = null;
        for (int j=0; j<2; ++j) {
            try {
                switch (j) {
                case 0:
                    method = "constructor";
                    SimpleTimeZone z = new SimpleTimeZone(0, "id",
                        Calendar.JANUARY, 1, 0, 0,
                        Calendar.MARCH, 1, 0, 0,
                        savings); // <- what we're interested in
                    break;
                case 1:
                    method = "setDSTSavings()";
                    z = new SimpleTimeZone(0, "GMT");
                    z.setDSTSavings(savings);
                    break;
                }
                if (valid) {
                    logln("Pass: DST savings of " + savings + " accepted by " + method);
                } else {
                    errln("Fail: DST savings of " + savings + " accepted by " + method);
                }
            } catch (IllegalArgumentException e) {
                if (valid) {
                    errln("Fail: DST savings of " + savings + " to " + method + " gave " + e);
                } else {
                    logln("Pass: DST savings of " + savings + " to " + method + " gave " + e);
                }
            }
        }
    }
}
 
Example 14
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 15
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 16
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 17
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;
}