Пример #1
0
 /**
  * Setting the date from the given object (only year, month, day). Hours, minutes, seconds etc.
  * will be preserved.
  *
  * @param src The calendar from which to copy the values.
  * @see #ensurePrecision()
  */
 public DateHolder setDay(final Calendar src) {
   calendar.set(Calendar.YEAR, src.get(Calendar.YEAR));
   calendar.set(Calendar.MONTH, src.get(Calendar.MONTH));
   calendar.set(Calendar.DAY_OF_MONTH, src.get(Calendar.DAY_OF_MONTH));
   computeTime();
   return this;
 }
Пример #2
0
 /**
  * Sets the date by giving all datefields and compute all fields.
  *
  * @param year
  * @param month
  * @param day
  * @param hour
  * @param minute
  * @param second
  * @param millisecond
  * @see #computeTime()
  * @see #ensurePrecision()
  */
 public DateHolder setDate(
     final int year,
     final int month,
     final int date,
     final int hourOfDay,
     final int minute,
     final int second,
     final int millisecond) {
   calendar.set(year, month, date, hourOfDay, minute, second);
   calendar.set(Calendar.MILLISECOND, millisecond);
   computeTime();
   ensurePrecision();
   return this;
 }
Пример #3
0
  private void calculate() {
    DateHolder dateHolder = new DateHolder(cal, DatePrecision.DAY);
    year = dateHolder.getYear();
    month = dateHolder.getMonth();
    dateHolder.setBeginOfMonth();
    begin = dateHolder.getDate(); // Storing begin of month.
    dateHolder.setEndOfMonth();
    end = dateHolder.getDate(); // Storing end of month.
    dateHolder.setDate(begin); // reset to begin of month
    dateHolder.computeTime();
    dateHolder.setBeginOfWeek(); // get first week (with days of previous month)

    weeks = new ArrayList<WeekHolder>();
    do {
      WeekHolder week = new WeekHolder(dateHolder.getCalendar(), month);
      weeks.add(week);
      dateHolder.add(Calendar.WEEK_OF_YEAR, 1);
    } while (dateHolder.getMonth() == month);
  }