Java Code Examples for java.util.GregorianCalendar#getMinimum()

The following examples show how to use java.util.GregorianCalendar#getMinimum() . 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: CalendarTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void dowTest(boolean lenient) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(1997, AUGUST, 12); // Wednesday
    cal.getTime(); // Force update
    cal.setLenient(lenient);
    cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996
    int dow = cal.get(DAY_OF_WEEK);
    int min = cal.getMinimum(DAY_OF_WEEK);
    int max = cal.getMaximum(DAY_OF_WEEK);
    if (dow < min || dow > max) {
        errln("FAIL: Day of week " + dow + " out of range");
    }
    if (dow != SUNDAY) {
        errln("FAIL2: Day of week should be SUNDAY; is " + dow + ": " + cal.getTime());
    }
    if (min != SUNDAY || max != SATURDAY) {
        errln("FAIL: Min/max bad");
    }
}
 
Example 2
Source File: CalendarRegression.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void dowTest(boolean lenient) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.set(1997, AUGUST, 12); // Wednesday
    // cal.getTime(); // Force update
    cal.setLenient(lenient);
    cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996
    int dow = cal.get(DAY_OF_WEEK);
    int min = cal.getMinimum(DAY_OF_WEEK);
    int max = cal.getMaximum(DAY_OF_WEEK);
    logln(cal.getTime().toString());
    if (min != SUNDAY || max != SATURDAY) {
        errln("FAIL: Min/max bad");
    }
    if (dow < min || dow > max) {
        errln("FAIL: Day of week " + dow + " out of range");
    }
    if (dow != SUNDAY) {
        errln("FAIL: Day of week should be SUNDAY Got " + dow);
    }
}
 
Example 3
Source File: GregorianCalendarTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * java.util.GregorianCalendar#getMinimum(int)
 */
public void test_getMinimumI() {
    // Test for method int java.util.GregorianCalendar.getMinimum(int)
    GregorianCalendar gc = new GregorianCalendar();
    assertEquals("Wrong minimum value for DAY_OF_MONTH", 1, gc
            .getMinimum(Calendar.DAY_OF_MONTH));
    assertTrue("Wrong minimum value for MONTH", gc
            .getMinimum(Calendar.MONTH) == Calendar.JANUARY);
    assertEquals("Wrong minimum value for HOUR_OF_DAY", 0, gc
            .getMinimum(Calendar.HOUR_OF_DAY));
    assertEquals("Wrong minimum value for HOUR",
            0, gc.getMinimum(Calendar.HOUR));

    BitSet result = new BitSet();
    int[] min = { 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, -46800000,
            0 };
    for (int i = 0; i < min.length; i++) {
        if (gc.getMinimum(i) != min[i])
            result.set(i);
    }
    assertTrue("Wrong min for " + result, result.length() == 0);
}
 
Example 4
Source File: CalendarRegression.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 5006864: Define the minimum value of DAY_OF_WEEK_IN_MONTH as 1
 */
public void Test5006864() {
    GregorianCalendar cal = new GregorianCalendar();
    int min = cal.getMinimum(DAY_OF_WEEK_IN_MONTH);
    if (min != 1) {
        errln("GregorianCalendar.getMinimum(DAY_OF_WEEK_IN_MONTH) returned "
                + min + ", expected 1.");
    }
    min = cal.getGreatestMinimum(DAY_OF_WEEK_IN_MONTH);
    if (min != 1) {
        errln("GregorianCalendar.getGreatestMinimum(DAY_OF_WEEK_IN_MONTH) returned "
                + min + ", expected 1.");
    }
}
 
Example 5
Source File: DateUtils.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * 得到本周的第一天
 * 
 * @return
 */
public static int toCurrentFirstWeekDay() {
	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(new Date());
	int day = cal.getMinimum(GregorianCalendar.DAY_OF_WEEK);
	return day;
}
 
Example 6
Source File: DateUtils.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
/**
 * 得到当月的第一天
 * 
 * @return
 */
public static int toCurrentFirstMonthDay() {
	GregorianCalendar cal = new GregorianCalendar();
	cal.setTime(new Date());
	int day = cal.getMinimum(GregorianCalendar.DAY_OF_MONTH);
	return day;
}