下面列出了java.util.GregorianCalendar#getMinimum ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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");
}
}
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);
}
}
/**
* 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);
}
/**
* 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.");
}
}
/**
* 得到本周的第一天
*
* @return
*/
public static int toCurrentFirstWeekDay() {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
int day = cal.getMinimum(GregorianCalendar.DAY_OF_WEEK);
return day;
}
/**
* 得到当月的第一天
*
* @return
*/
public static int toCurrentFirstMonthDay() {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
int day = cal.getMinimum(GregorianCalendar.DAY_OF_MONTH);
return day;
}