예제 #1
0
 /*
  * Resets the calendar time (hour, minute second and millisecond) either to
  * zero or maximum value.
  */
 private void resetTime(boolean max) {
   if (max) {
     calendar.set(
         GregorianCalendar.HOUR_OF_DAY, calendar.getMaximum(GregorianCalendar.HOUR_OF_DAY));
     calendar.set(GregorianCalendar.MINUTE, calendar.getMaximum(GregorianCalendar.MINUTE));
     calendar.set(GregorianCalendar.SECOND, calendar.getMaximum(GregorianCalendar.SECOND));
     calendar.set(
         GregorianCalendar.MILLISECOND, calendar.getMaximum(GregorianCalendar.MILLISECOND));
   } else {
     calendar.set(GregorianCalendar.HOUR_OF_DAY, 0);
     calendar.set(GregorianCalendar.MINUTE, 0);
     calendar.set(GregorianCalendar.SECOND, 0);
     calendar.set(GregorianCalendar.MILLISECOND, 0);
   }
 }
예제 #2
0
  public static short proximoDiaMesAtual(short sDia) {
    short sProximoDia = 1;
    GregorianCalendar gcTmp = new GregorianCalendar();

    if (sDia < gcTmp.getMaximum(5)) {
      sProximoDia = sDia++;
    }

    return sProximoDia;
  }
예제 #3
0
  public void test(TestHarness harness) {
    GregorianCalendar cal;
    cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US);

    // Month with 6 weeks
    cal.set(2006, Calendar.JULY, 30);
    cal.setLenient(false);

    harness.check(cal.getMaximum(Calendar.WEEK_OF_MONTH), 6);

    cal.clear(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.WEEK_OF_MONTH, 1);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    harness.check(cal.get(Calendar.DAY_OF_MONTH), 1);

    cal.clear(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.WEEK_OF_MONTH, 6);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    harness.check(cal.get(Calendar.DAY_OF_MONTH), 31);

    // Month with 4 weeks
    cal.set(1998, Calendar.FEBRUARY, 14);
    cal.clear(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.WEEK_OF_MONTH, 1);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    harness.check(cal.get(Calendar.DAY_OF_MONTH), 1);

    cal.clear(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.WEEK_OF_MONTH, 4);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);
    harness.check(cal.get(Calendar.DAY_OF_MONTH), 28);
    harness.check(cal.get(Calendar.MONTH), Calendar.FEBRUARY);

    // Month with 5 weeks
    cal.set(1993, Calendar.FEBRUARY, 14);
    cal.clear(Calendar.DAY_OF_MONTH);
    cal.set(Calendar.WEEK_OF_MONTH, 5);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    harness.check(cal.get(Calendar.DAY_OF_MONTH), 28);
  }