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

The following examples show how to use android.icu.util.Calendar#APRIL . 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: CompatibilityTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestRog() {
    GregorianCalendar gc = new GregorianCalendar();

    int year = 1997, month = Calendar.APRIL, date = 1;
    gc.set(year, month, date); // April 1, 1997

    gc.set(Calendar.HOUR_OF_DAY, 23);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);

    for (int i = 0; i < 9; i++, gc.add(Calendar.DATE, 1)) {
        if (gc.get(Calendar.YEAR) != year ||
            gc.get(Calendar.MONTH) != month ||
            gc.get(Calendar.DATE) != (date + i))
            errln("FAIL: Date " + gc.getTime() + " wrong");
    }
}
 
Example 6
Source File: TimeZoneRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * TimeZone broken at midnight.  The TimeZone code fails to handle
 * transitions at midnight correctly.
 */
@Test
public void Test4162593() {
    SimpleDateFormat fmt = new SimpleDateFormat("z", Locale.US);
    final int ONE_HOUR = 60*60*1000;
    final float H = (float) ONE_HOUR;
    TimeZone initialZone = TimeZone.getDefault();
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy HH:mm z");

    SimpleTimeZone asuncion = new SimpleTimeZone(-4*ONE_HOUR, "America/Asuncion" /*PY%sT*/,
        Calendar.OCTOBER, 1, 0 /*DOM*/, 0*ONE_HOUR,
        Calendar.MARCH, 1, 0 /*DOM*/, 0*ONE_HOUR, 1*ONE_HOUR);

    /* Zone
     * Starting time
     * Transition expected between start+1H and start+2H
     */
    Object[] DATA = {
        new SimpleTimeZone(2*ONE_HOUR, "Asia/Damascus" /*EE%sT*/,
            Calendar.APRIL, 1, 0 /*DOM*/, 0*ONE_HOUR,
            Calendar.OCTOBER, 1, 0 /*DOM*/, 0*ONE_HOUR, 1*ONE_HOUR),
        new int[] {1998, Calendar.SEPTEMBER, 30, 22, 0},
        Boolean.TRUE,

        asuncion,
        new int[] {2000, Calendar.FEBRUARY, 28, 22, 0},
        Boolean.FALSE,

        asuncion,
        new int[] {2000, Calendar.FEBRUARY, 29, 22, 0},
        Boolean.TRUE,
    };

    String[] zone = new String[4];

    for (int j=0; j<DATA.length; j+=3) {
        TimeZone tz = (TimeZone)DATA[j];
        TimeZone.setDefault(tz);
        fmt.setTimeZone(tz);
        sdf.setTimeZone(tz);

        // Must construct the Date object AFTER setting the default zone
        int[] p = (int[])DATA[j+1];
        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(p[0], p[1], p[2], p[3], p[4]);
        long start = cal.getTime().getTime();
        boolean transitionExpected = ((Boolean)DATA[j+2]).booleanValue();

        logln(tz.getID() + ":");
        for (int i=0; i<4; ++i) {
            Date d = new Date(start + i*ONE_HOUR);
            zone[i] = fmt.format(d);
            logln("" + i + ": " + sdf.format(d) + " => " + zone[i] +
                  " (" + d.getTime()/H + ")");
        }
        cal.set(p[0], p[1], p[2], 0, 0);
        for (int i=0; i<4; ++i) {
            int h = 22+i;
            int dom = p[2]+(h>=24?1:0);
            h %= 24;
            int ms = h*ONE_HOUR;
            cal.clear();
            cal.set(p[0], p[1], dom, 0, 0);
            int off = tz.getOffset(GregorianCalendar.AD,
                                   cal.get(Calendar.YEAR),
                                   cal.get(Calendar.MONTH),
                                   cal.get(Calendar.DATE),
                                   cal.get(Calendar.DAY_OF_WEEK),
                                   ms);
            cal.add(Calendar.HOUR, h);
            int dstOffset = cal.get(Calendar.DST_OFFSET);
            logln("h=" + h + "; dom=" + dom +
                  "; ZONE_OFFSET=" + cal.get(Calendar.ZONE_OFFSET)/H +
                  "; DST_OFFSET=" + dstOffset/H +
                  "; getOffset()=" + off/H +
                  " (" + cal.getTime().getTime()/H + ")");
        }
        if (zone[0].equals(zone[1]) &&
            (zone[1].equals(zone[2]) != transitionExpected) &&
            zone[2].equals(zone[3])) {
            logln("Ok: transition " + transitionExpected);
        } else {
            errln("FAIL: expected " +
                  (transitionExpected?"transition":"no transition"));
        }
    }

// restore the initial time zone so that this test case
// doesn't affect the others.
TimeZone.setDefault(initialZone);
}
 
Example 7
Source File: TimeZoneBoundaryTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Test new rule formats.
 */
@Test
public void TestNewRules()
{
    //logln(Locale.getDefault().getDisplayName());
    //logln(TimeZone.getDefault().getID());
    //logln(new Date(0));

    if (true)
    {
        // Doesn't matter what the default TimeZone is here, since we
        // are creating our own TimeZone objects.

        SimpleTimeZone tz;
        java.util.Calendar tempcal = java.util.Calendar.getInstance();
        tempcal.clear();

        logln("-----------------------------------------------------------------");
        logln("Aug 2ndTues .. Mar 15");
        tz = new SimpleTimeZone(-8*ONE_HOUR, "Test_1",
                                Calendar.AUGUST, 2, Calendar.TUESDAY, 2*ONE_HOUR,
                                Calendar.MARCH, 15, 0, 2*ONE_HOUR);
        //logln(tz.toString());
        logln("========================================");
        tempcal.set(1997, 0, 1);
        _testUsingBinarySearch(tz, tempcal.getTime(), 858416400000L);
        logln("========================================");
        tempcal.set(1997, 6, 1);
        _testUsingBinarySearch(tz, tempcal.getTime(), 871380000000L);

        logln("-----------------------------------------------------------------");
        logln("Apr Wed>=14 .. Sep Sun<=20");
        tz = new SimpleTimeZone(-8*ONE_HOUR, "Test_2",
                                Calendar.APRIL, 14, -Calendar.WEDNESDAY, 2*ONE_HOUR,
                                Calendar.SEPTEMBER, -20, -Calendar.SUNDAY, 2*ONE_HOUR);
        //logln(tz.toString());
        logln("========================================");
        tempcal.set(1997, 0, 1);
        _testUsingBinarySearch(tz, tempcal.getTime(), 861184800000L);
        logln("========================================");
        tempcal.set(1997, 6, 1);
        _testUsingBinarySearch(tz, tempcal.getTime(), 874227600000L);
    }

    /*
      if (true)
      {
      logln("========================================");
      logln("Stepping using millis");
      _testUsingMillis(new Date(97,0,1), false);
      }

      if (true)
      {
      logln("========================================");
      logln("Stepping using fields");
      _testUsingFields(1997, false);
      }

      if (false)
      {
      cal.clear();
      cal.set(1997, 3, 5, 10, 0);
      //    cal.inDaylightTime();
      logln("Date = " + cal.getTime());
      logln("Millis = " + cal.getTime().getTime()/3600000);
      }
      */
}