示例#1
1
 public void appendTo(StringBuffer buffer, Calendar calendar) {
   int value = calendar.get(Calendar.HOUR_OF_DAY);
   if (value == 0) {
     value = calendar.getMaximum(Calendar.HOUR_OF_DAY) + 1;
   }
   mRule.appendTo(buffer, value);
 }
示例#2
0
  /**
   * Changes input calendar by resetting time fields to the end of day.
   *
   * @param calendar the calendar to change; can't be null.
   * @return the changed calendar.
   */
  public static Calendar dayEndTime(Calendar calendar) {
    calendar.set(Calendar.HOUR, calendar.getMaximum(Calendar.HOUR));
    calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE));
    calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));
    calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));

    return calendar;
  }
 public static Date addMaximumHour(Date date) {
   if (date == null) return null;
   calendar.setTime(date);
   calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY));
   calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE));
   calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND));
   calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND));
   return calendar.getTime();
 }
 public static Date getUltimoDiaDelMes() {
   Calendar cal = Calendar.getInstance();
   cal.set(
       cal.get(Calendar.YEAR),
       cal.get(Calendar.MONTH),
       cal.getActualMaximum(Calendar.DAY_OF_MONTH),
       cal.getMaximum(Calendar.HOUR_OF_DAY),
       cal.getMaximum(Calendar.MINUTE),
       cal.getMaximum(Calendar.SECOND));
   return cal.getTime();
 }
 public static Object[] getAvailableGroups() {
   if (_groups == null) {
     Calendar cal = Calendar.getInstance();
     cal.set(Calendar.DAY_OF_WEEK_IN_MONTH, 0);
     _groups = new Object[cal.getMaximum(Calendar.DAY_OF_WEEK_IN_MONTH)];
     for (int i = 0; i < _groups.length; i++) {
       _groups[i] = getCalendarField(cal, Calendar.DAY_OF_WEEK_IN_MONTH);
       cal.roll(Calendar.DAY_OF_WEEK_IN_MONTH, 1);
     }
   }
   return _groups;
 }
  /**
   * Determines what Timestamp should be used for active queries on effective dated records.
   * Determination made as follows:
   *
   * <ul>
   *   <li>Use activeAsOfDate value from search values Map if value is not empty
   *   <li>If search value given, try to convert to sql date, if conversion fails, try to convert to
   *       Timestamp
   *   <li>If search value empty, use current Date
   *   <li>If Timestamp value not given, create Timestamp from given Date setting the time as 1
   *       second before midnight
   * </ul>
   *
   * @param searchValues - Map containing search key/value pairs
   * @return Timestamp to be used for active criteria
   */
  public static Timestamp getActiveDateTimestampForCriteria(Map searchValues) {
    Date activeDate = CoreApiServiceLocator.getDateTimeService().getCurrentSqlDate();
    Timestamp activeTimestamp = null;
    if (searchValues.containsKey(KRADPropertyConstants.ACTIVE_AS_OF_DATE)) {
      String activeAsOfDate = (String) searchValues.get(KRADPropertyConstants.ACTIVE_AS_OF_DATE);
      if (StringUtils.isNotBlank(activeAsOfDate)) {
        try {
          activeDate =
              CoreApiServiceLocator.getDateTimeService()
                  .convertToSqlDate(ObjectUtils.clean(activeAsOfDate));
        } catch (ParseException e) {
          // try to parse as timestamp
          try {
            activeTimestamp =
                CoreApiServiceLocator.getDateTimeService()
                    .convertToSqlTimestamp(ObjectUtils.clean(activeAsOfDate));
          } catch (ParseException e1) {
            throw new RuntimeException(
                "Unable to convert date: " + ObjectUtils.clean(activeAsOfDate));
          }
        }
      }
    }

    // if timestamp not given set to 1 second before midnight on the given date
    if (activeTimestamp == null) {
      Calendar cal = Calendar.getInstance();
      cal.setTime(activeDate);
      cal.set(Calendar.HOUR, cal.getMaximum(Calendar.HOUR));
      cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
      cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));

      activeTimestamp = new Timestamp(cal.getTime().getTime());
    }

    return activeTimestamp;
  }
示例#7
0
  private void set(int field, Calendar time) {
    Date temp;
    int value;
    Frequency frequency;
    int actual;

    switch (field) {
      case Calendar.HOUR_OF_DAY:
        value = hour;
        frequency = hourlyFrequency;
        break;

      case Calendar.MINUTE:
        value = minute;
        frequency = minutelyFrequency;
        break;

      case Calendar.SECOND:
        value = second;
        frequency = secondFrequency;
        break;

      default:
        throw new IllegalArgumentException("unknown calendar field " + field);
    }

    switch (frequency) {
      case EVERY:
        if (value != 0) {
          actual = time.get(field);
          time.set(field, actual - (actual % value) + value);
        }

        break;

      case ONCE:
        temp = time.getTime();
        time.set(field, value);

        if (temp.compareTo(time.getTime()) >= 0) {
          time.add(field, time.getMaximum(field) + 1);
        }
        break;
    }
  }
示例#8
0
  // BEGIN Rental Charge Fee
  public static Double getRentalChargeFee(Date startFrom, Double monthlyFee) {

    Double finalChargeFee = 0d;
    Double dailyFee = 0d;
    Integer servedDay = 0;
    Integer maxDay = 0;
    Integer startDay = 0;
    Calendar cal = Calendar.getInstance();
    cal.setTime(startFrom);
    String startFromStr = TMUtils.dateFormatYYYYMMDD(cal.getTime());
    startDay = Integer.parseInt(startFromStr.substring(startFromStr.lastIndexOf("-") + 1));
    maxDay = cal.getMaximum(Calendar.DATE);
    dailyFee = TMUtils.bigDivide(monthlyFee, maxDay);
    servedDay = maxDay - startDay + 1;
    finalChargeFee = TMUtils.bigMultiply(dailyFee, servedDay);

    return finalChargeFee;
  }
 private static Date calculateLastestStartDateOfTask(Task task) {
   Date latestStartDate = null;
   Integer expiryTypeId = task.getExpiryTypeId();
   String expiryType = TaskExpiryTypeRef.getCode(expiryTypeId);
   if (TaskExpiryTypeRef.Status.NEX.toString().equals(expiryType)) {
     latestStartDate = null;
   } else if (TaskExpiryTypeRef.Status.EOY.toString().equals(expiryType)) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date());
     cal.set(Calendar.MONTH, Calendar.DECEMBER);
     cal.set(Calendar.DAY_OF_MONTH, 31);
     latestStartDate = new java.sql.Date(cal.getTimeInMillis());
   } else if (TaskExpiryTypeRef.Status.EOM.toString().equals(expiryType)) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date());
     int max = cal.getMaximum(Calendar.DAY_OF_MONTH);
     int actualMax = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
     cal.set(Calendar.DAY_OF_MONTH, actualMax);
     latestStartDate = new java.sql.Date(cal.getTimeInMillis());
   } else if (TaskExpiryTypeRef.Status.EOW.toString().equals(expiryType)) {
     // Assumes Sunday is beginning of week
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date());
     int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
     if (dayOfWeek == Calendar.SATURDAY) {
       // Today is Saturday, no need to expire it today. It should expire next Saturday
       cal.add(Calendar.DATE, 7);
       latestStartDate = new java.sql.Date(cal.getTimeInMillis());
       return latestStartDate;
     }
     while (dayOfWeek != Calendar.SATURDAY) {
       cal.add(Calendar.DATE, 1);
       dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
     }
     latestStartDate = new java.sql.Date(cal.getTimeInMillis());
   } else if (TaskExpiryTypeRef.Status.REL.toString().equals(expiryType)) {
     Calendar cal = Calendar.getInstance();
     cal.setTime(new Date());
     cal.add(Calendar.DAY_OF_MONTH, task.getExpiryNumOfDays().intValue());
     latestStartDate = new java.sql.Date(cal.getTimeInMillis());
   }
   return latestStartDate;
 }
示例#10
0
  /**
   * @param 取指定年,月,日的下一日的开始时间,小时,分,秒为00:00:00
   * @param 主要是用来取跨月份的日期
   * @return
   */
  public Date getNextDayStart(int year, int month, int date) {
    month = month - 1;
    boolean lastDayOfMonth = false;
    boolean lastDayOfYear = false;

    Calendar time = Calendar.getInstance();
    time.set(year, month, date, 0, 0, 0);
    Calendar nextMonthFirstDay = Calendar.getInstance();
    nextMonthFirstDay.set(year, month + 1, 1, 0, 0, 0);

    if (time.get(Calendar.DAY_OF_YEAR) + 1 == nextMonthFirstDay.get(Calendar.DAY_OF_YEAR))
      lastDayOfMonth = true;

    if (time.get(Calendar.DAY_OF_YEAR) == time.getMaximum(Calendar.DATE)) lastDayOfYear = true;

    time.roll(Calendar.DATE, 1);

    if (lastDayOfMonth) time.roll(Calendar.MONTH, 1);

    if (lastDayOfYear) time.roll(Calendar.YEAR, 1);

    return time.getTime();
  }
  /** {@inheritDoc} */
  @Override
  public void buildContent() {
    Calendar calendar = calendarView.calendarProperty().get();

    // get the maximum number of days in a week for this calendar.
    numberOfDaysPerWeek = calendar.getMaximum(Calendar.DAY_OF_WEEK);

    // get the maximum number of days a month could have.
    int maxNumberOfDaysInMonth = calendar.getMaximum(Calendar.DAY_OF_MONTH);

    // assume the first row has only 1 day, then distribute the rest among the remaining weeks and
    // add the first week.
    int numberOfRows =
        (int) Math.ceil((maxNumberOfDaysInMonth - 1) / (double) numberOfDaysPerWeek) + 1;

    // remove all controls
    getChildren().clear();

    int colOffset = calendarView.getShowWeeks() ? 1 : 0;

    if (calendarView.getShowWeeks()) {
      Label empty = new Label();
      empty.setMaxWidth(Double.MAX_VALUE);
      empty.getStyleClass().add(CSS_CALENDAR_WEEKDAYS);
      add(empty, 0, 0);
    }
    // iterate through the columns
    for (int i = 0; i < numberOfDaysPerWeek; i++) {
      Label label = new Label();
      label.getStyleClass().add(CSS_CALENDAR_WEEKDAYS);
      label.setMaxWidth(Double.MAX_VALUE);
      label.setAlignment(Pos.CENTER);
      add(label, i + colOffset, 0);
    }

    // iterate through the rows
    for (int rowIndex = 0; rowIndex < numberOfRows; rowIndex++) {

      if (calendarView.getShowWeeks()) {
        Label label = new Label();
        label.setMaxWidth(Double.MAX_VALUE);
        label.setMaxHeight(Double.MAX_VALUE);
        label.getStyleClass().add(CSS_CALENDAR_WEEK_NUMBER);
        add(label, 0, rowIndex + 1);
      }

      // iterate through the columns
      for (int colIndex = 0; colIndex < numberOfDaysPerWeek; colIndex++) {
        final Button button = new Button();
        button.setMaxWidth(Double.MAX_VALUE);
        button.setMaxHeight(Double.MAX_VALUE);

        GridPane.setVgrow(button, Priority.ALWAYS);
        GridPane.setHgrow(button, Priority.ALWAYS);
        button.setOnAction(
            new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent actionEvent) {

                calendarView.selectedDate.set((Date) button.getUserData());
              }
            });
        // add the button, starting at second row.
        add(button, colIndex + colOffset, rowIndex + 1);
      }
    }
  }