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

The following examples show how to use android.icu.util.Calendar#SEPTEMBER . 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: DangiTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Make sure no Gregorian dates map to Chinese 1-based day of
 * month zero.  This was a problem with some of the astronomical
 * new moon determinations.
 */
@Test
public void TestZeroDOM() {
    Calendar cal = Calendar.getInstance(new ULocale("ko_KR@calendar=dangi"));
    GregorianCalendar greg = new GregorianCalendar(1989, Calendar.SEPTEMBER, 1);
    logln("Start: " + greg.getTime());
    for (int i=0; i<1000; ++i) {
        cal.setTimeInMillis(greg.getTimeInMillis());
        if (cal.get(Calendar.DAY_OF_MONTH) == 0) {
            errln("Fail: " + greg.getTime() + " -> " +
                  cal.get(Calendar.YEAR) + "/" +
                  cal.get(Calendar.MONTH) +
                  (cal.get(Calendar.IS_LEAP_MONTH)==1?"(leap)":"") +
                  "/" + cal.get(Calendar.DAY_OF_MONTH));
        }
        greg.add(Calendar.DAY_OF_YEAR, 1);
    }
    logln("End: " + greg.getTime());
}
 
Example 6
Source File: ChineseTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Make sure no Gregorian dates map to Chinese 1-based day of
 * month zero.  This was a problem with some of the astronomical
 * new moon determinations.
 */
@Test
public void TestZeroDOM() {
    ChineseCalendar cal = new ChineseCalendar();
    GregorianCalendar greg = new GregorianCalendar(1989, Calendar.SEPTEMBER, 1);
    logln("Start: " + greg.getTime());
    for (int i=0; i<1000; ++i) {
        cal.setTimeInMillis(greg.getTimeInMillis());
        if (cal.get(Calendar.DAY_OF_MONTH) == 0) {
            errln("Fail: " + greg.getTime() + " -> " +
                  cal.get(Calendar.EXTENDED_YEAR) + "/" +
                  cal.get(Calendar.MONTH) +
                  (cal.get(Calendar.IS_LEAP_MONTH)==1?"(leap)":"") +
                  "/" + cal.get(Calendar.DAY_OF_MONTH));
        }
        greg.add(Calendar.DAY_OF_YEAR, 1);
    }
    logln("End: " + greg.getTime());
}
 
Example 7
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 8
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 9
Source File: TimeZoneTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Bug 4107276
 */
@Test
public void TestDSTSavings() {
    // It might be better to find a way to integrate this test into the main TimeZone
    // tests above, but I don't have time to figure out how to do this (or if it's
    // even really a good idea).  Let's consider that a future.  --rtg 1/27/98
    SimpleTimeZone tz = new SimpleTimeZone(-5 * millisPerHour, "dstSavingsTest",
                                           Calendar.MARCH, 1, 0, 0, Calendar.SEPTEMBER, 1, 0, 0,
                                           (int)(0.5 * millisPerHour));

    if (tz.getRawOffset() != -5 * millisPerHour)
        errln("Got back a raw offset of " + (tz.getRawOffset() / millisPerHour) +
              " hours instead of -5 hours.");
    if (!tz.useDaylightTime())
        errln("Test time zone should use DST but claims it doesn't.");
    if (tz.getDSTSavings() != 0.5 * millisPerHour)
        errln("Set DST offset to 0.5 hour, but got back " + (tz.getDSTSavings() /
                                                             millisPerHour) + " hours instead.");

    int offset = tz.getOffset(GregorianCalendar.AD, 1998, Calendar.JANUARY, 1,
                              Calendar.THURSDAY, 10 * millisPerHour);
    if (offset != -5 * millisPerHour)
        errln("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got "
              + (offset / millisPerHour) + " hours.");

    offset = tz.getOffset(GregorianCalendar.AD, 1998, Calendar.JUNE, 1, Calendar.MONDAY,
                          10 * millisPerHour);
    if (offset != -4.5 * millisPerHour)
        errln("The offset for 10 AM, 6/1/98 should have been -4.5 hours, but we got "
              + (offset / millisPerHour) + " hours.");

    tz.setDSTSavings(millisPerHour);
    offset = tz.getOffset(GregorianCalendar.AD, 1998, Calendar.JANUARY, 1,
                          Calendar.THURSDAY, 10 * millisPerHour);
    if (offset != -5 * millisPerHour)
        errln("The offset for 10 AM, 1/1/98 should have been -5 hours, but we got "
              + (offset / millisPerHour) + " hours.");

    offset = tz.getOffset(GregorianCalendar.AD, 1998, Calendar.JUNE, 1, Calendar.MONDAY,
                          10 * millisPerHour);
    if (offset != -4 * millisPerHour)
        errln("The offset for 10 AM, 6/1/98 (with a 1-hour DST offset) should have been -4 hours, but we got "
              + (offset / millisPerHour) + " hours.");
}
 
Example 10
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 11
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);
      }
      */
}