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

The following examples show how to use android.icu.util.Calendar#SATURDAY . 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: CalendarRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Get the associated date starting from a specified date NOTE: the
 * unnecessary "getTime()'s" below are a work-around for a bug in jdk 1.1.3
 * (and probably earlier versions also)
 * <p>
 * 
 * @param d
 *            The date to start from
 */
public static Date getAssociatedDate(Date d) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(d);
    //cal.add(field, amount); //<-- PROBLEM SEEN WITH field = DATE,MONTH
    // cal.getTime(); // <--- REMOVE THIS TO SEE BUG
    while (true) {
        int wd = cal.get(Calendar.DAY_OF_WEEK);
        if (wd == Calendar.SATURDAY || wd == Calendar.SUNDAY) {
            cal.add(Calendar.DATE, 1);
            // cal.getTime();
        }
        else
            break;
    }
    return cal.getTime();
}
 
Example 2
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
void dowTest(boolean lenient) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(1997, Calendar.AUGUST, 12); // Wednesday
    // cal.getTime(); // Force update
    cal.setLenient(lenient);
    cal.set(1996, Calendar.DECEMBER, 1); // Set the date to be December 1,
                                         // 1996
    int dow = cal.get(Calendar.DAY_OF_WEEK);
    int min = cal.getMinimum(Calendar.DAY_OF_WEEK);
    int max = cal.getMaximum(Calendar.DAY_OF_WEEK);
    logln(cal.getTime().toString());
    if (min != Calendar.SUNDAY || max != Calendar.SATURDAY)
        errln("FAIL: Min/max bad");
    if (dow < min || dow > max) 
        errln("FAIL: Day of week " + dow + " out of range");
    if (dow != Calendar.SUNDAY) 
        errln("FAIL: Day of week should be SUNDAY Got " + dow);
}
 
Example 3
Source File: CalendarViewLegacyDelegate.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the strings to be used by the header.
 */
private void setUpHeader() {
    mDayNamesShort = new String[mDaysPerWeek];
    mDayNamesLong = new String[mDaysPerWeek];
    for (int i = mFirstDayOfWeek, count = mFirstDayOfWeek + mDaysPerWeek; i < count; i++) {
        int calendarDay = (i > Calendar.SATURDAY) ? i - Calendar.SATURDAY : i;
        mDayNamesShort[i - mFirstDayOfWeek] = DateUtils.getDayOfWeekString(calendarDay,
                DateUtils.LENGTH_SHORTEST);
        mDayNamesLong[i - mFirstDayOfWeek] = DateUtils.getDayOfWeekString(calendarDay,
                DateUtils.LENGTH_LONG);
    }

    TextView label = (TextView) mDayNamesHeader.getChildAt(0);
    if (mShowWeekNumber) {
        label.setVisibility(View.VISIBLE);
    } else {
        label.setVisibility(View.GONE);
    }
    for (int i = 1, count = mDayNamesHeader.getChildCount(); i < count; i++) {
        label = (TextView) mDayNamesHeader.getChildAt(i);
        if (mWeekDayTextAppearanceResId > -1) {
            label.setTextAppearance(mWeekDayTextAppearanceResId);
        }
        if (i < mDaysPerWeek + 1) {
            label.setText(mDayNamesShort[i - 1]);
            label.setContentDescription(mDayNamesLong[i - 1]);
            label.setVisibility(View.VISIBLE);
        } else {
            label.setVisibility(View.GONE);
        }
    }
    mDayNamesHeader.invalidate();
}
 
Example 4
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 5
Source File: CompatibilityTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
void dowTest(boolean lenient) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(1997, Calendar.AUGUST, 12); // Wednesday
    cal.getTime(); // Force update
    cal.setLenient(lenient);
    cal.set(1996, Calendar.DECEMBER, 1); // Set the date to be December 1, 1996
    int dow = cal.get(Calendar.DAY_OF_WEEK);
    int min = cal.getMinimum(Calendar.DAY_OF_WEEK);
    int max = cal.getMaximum(Calendar.DAY_OF_WEEK);
    if (dow < min || dow > max) errln("FAIL: Day of week " + dow + " out of range");
    if (dow != Calendar.SUNDAY) {
        errln("FAIL2: Day of week should be SUNDAY; is " + dow + ": " + cal.getTime());
    }
    if (min != Calendar.SUNDAY || max != Calendar.SATURDAY) errln("FAIL: Min/max bad");
}
 
Example 6
Source File: IBMCalendarTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestWeekData() {
    // Each line contains two locales using the same set of week rule data.
    final String LOCALE_PAIRS[] = {
        "en",       "en_US",
        "de",       "de_DE",
        "de_DE",    "en_DE",
        "en_GB",    "und_GB",
        "ar_EG",    "en_EG",
        "ar_SA",    "fr_SA",
    };

    for (int i = 0; i < LOCALE_PAIRS.length; i += 2) {
        Calendar cal1 = Calendar.getInstance(new ULocale(LOCALE_PAIRS[i]));
        Calendar cal2 = Calendar.getInstance(new ULocale(LOCALE_PAIRS[i + 1]));

        // First day of week
        int dow1 = cal1.getFirstDayOfWeek();
        int dow2 = cal2.getFirstDayOfWeek();
        if (dow1 != dow2) {
            errln("getFirstDayOfWeek: " + LOCALE_PAIRS[i] + "->" + dow1 + ", " + LOCALE_PAIRS[i + 1] + "->" + dow2);
        }

        // Minimum days in first week
        int minDays1 = cal1.getMinimalDaysInFirstWeek();
        int minDays2 = cal2.getMinimalDaysInFirstWeek();
        if (minDays1 != minDays2) {
            errln("getMinimalDaysInFirstWeek: " + LOCALE_PAIRS[i] + "->" + minDays1 + ", " + LOCALE_PAIRS[i + 1] + "->" + minDays2);
        }

        // Weekdays and Weekends
        for (int d = Calendar.SUNDAY; d <= Calendar.SATURDAY; d++) {
            int wdt1 = cal1.getDayOfWeekType(d);
            int wdt2 = cal2.getDayOfWeekType(d);
            if (wdt1 != wdt2) {
                errln("getDayOfWeekType(" + d + "): " + LOCALE_PAIRS[i] + "->" + wdt1 + ", " + LOCALE_PAIRS[i + 1] + "->" + wdt2);
            }
        }
    }
}
 
Example 7
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void Test4070502() {
    java.util.Calendar tempcal = java.util.Calendar.getInstance();
    tempcal.clear();
    tempcal.set(1998, 0, 30);
    Date d = getAssociatedDate(tempcal.getTime());
    Calendar cal = new GregorianCalendar();
    cal.setTime(d);
    if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY ||
        cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
        errln("Fail: Want weekday Got " + d);
}
 
Example 8
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * GregorianCalendar.getActualMaximum() does not account for first day of
 * week.
 */
@Test
public void Test4166109() {
    /*
     * Test month:
     * 
     * March 1998 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
     * 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
     */
    boolean passed = true;
    int field = Calendar.WEEK_OF_MONTH;

    GregorianCalendar calendar = new GregorianCalendar(Locale.US);
    calendar.set(1998, Calendar.MARCH, 1);
    calendar.setMinimalDaysInFirstWeek(1);
    logln("Date:  " + calendar.getTime());

    int firstInMonth = calendar.get(Calendar.DAY_OF_MONTH);

    for (int firstInWeek = Calendar.SUNDAY; firstInWeek <= Calendar.SATURDAY; firstInWeek++) {
        calendar.setFirstDayOfWeek(firstInWeek);
        int returned = calendar.getActualMaximum(field);
        int expected = (31 + ((firstInMonth - firstInWeek + 7)% 7) + 6) / 7;

        logln("First day of week = " + firstInWeek +
              "  getActualMaximum(WEEK_OF_MONTH) = " + returned +
              "  expected = " + expected +
              ((returned == expected) ? "  ok" : "  FAIL"));

        if (returned != expected) {
            passed = false;
        }
    }
    if (!passed) {
        errln("Test failed");
    }
}
 
Example 9
Source File: SimpleMonthView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static boolean isValidDayOfWeek(int day) {
    return day >= Calendar.SUNDAY && day <= Calendar.SATURDAY;
}
 
Example 10
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
private static boolean isValidDayOfWeek(int day) {
    return day >= Calendar.SUNDAY && day <= Calendar.SATURDAY;
}
 
Example 11
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 12
Source File: DatePicker.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the first day of week.
 *
 * @param firstDayOfWeek The first day of the week conforming to the
 *            {@link CalendarView} APIs.
 * @see Calendar#SUNDAY
 * @see Calendar#MONDAY
 * @see Calendar#TUESDAY
 * @see Calendar#WEDNESDAY
 * @see Calendar#THURSDAY
 * @see Calendar#FRIDAY
 * @see Calendar#SATURDAY
 *
 * @attr ref android.R.styleable#DatePicker_firstDayOfWeek
 */
public void setFirstDayOfWeek(int firstDayOfWeek) {
    if (firstDayOfWeek < Calendar.SUNDAY || firstDayOfWeek > Calendar.SATURDAY) {
        throw new IllegalArgumentException("firstDayOfWeek must be between 1 and 7");
    }
    mDelegate.setFirstDayOfWeek(firstDayOfWeek);
}
 
Example 13
Source File: DatePicker.java    From DateTimePicker with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the first day of week.
 *
 * @param firstDayOfWeek The first day of the week conforming to the
 *                       {@link CalendarView} APIs.
 * @attr ref android.R.styleable#DatePicker_firstDayOfWeek
 * @see Calendar#SUNDAY
 * @see Calendar#MONDAY
 * @see Calendar#TUESDAY
 * @see Calendar#WEDNESDAY
 * @see Calendar#THURSDAY
 * @see Calendar#FRIDAY
 * @see Calendar#SATURDAY
 */
public void setFirstDayOfWeek(int firstDayOfWeek) {
    if (firstDayOfWeek < Calendar.SUNDAY || firstDayOfWeek > Calendar.SATURDAY) {
        throw new IllegalArgumentException("firstDayOfWeek must be between 1 and 7");
    }
    mDelegate.setFirstDayOfWeek(firstDayOfWeek);
}