static {
   try {
     START_DATE = DateUtils.parseDate("01-01-12", new String[] {"dd-MM-yy"});
     END_DATE = DateUtils.addMonths(START_DATE, 1);
   } catch (ParseException e) {
     throw new RuntimeException(e);
   }
 }
  public static CoveringInfo getMonthlyCoveringInfo(Date from, Date to) {
    // Move 'from' to end of month, unless its the first day of month
    boolean coverable = true;
    if (!from.equals(DateUtils.truncate(from, MONTH))) {
      from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1);
      coverable = false;
    }

    // Move 'to' to beginning of next month, unless its the first day of the month
    if (!to.equals(DateUtils.truncate(to, MONTH))) {
      to = DateUtils.truncate(to, MONTH);
      coverable = false;
    }

    int months = 0;
    while (from.before(to)) {
      from = DateUtils.addMonths(from, 1);
      months++;
    }
    return new CoveringInfo(months, coverable);
  }
 public static Date getRangeDate(Date midDate, int unitRange, TsUnit aTsUnit, int addOrSub) {
   Date result = null;
   if (aTsUnit == TsUnit.YEARLY) {
     result = DateUtils.addYears(midDate, unitRange * addOrSub);
   } else if (aTsUnit == TsUnit.DAILY) {
     result = DateUtils.addDays(midDate, unitRange * addOrSub);
   } else if (aTsUnit == TsUnit.MONTHLY) {
     result = DateUtils.addMonths(midDate, unitRange * addOrSub);
   } else {
     EUtils.throwNotSupportedException(Version.V1_0_0);
   }
   return result;
 }
 private void initComponents() {
   fechaInicial = new JXDatePicker();
   Date ini = DateUtils.addMonths(new Date(), -2);
   fechaInicial.setDate(ini);
   fechaInicial.setFormats("dd/MM/yyyy");
   fechaFinal = new JXDatePicker();
   fechaFinal.setFormats("dd/MM/yyyy");
   sucursalControl = createSucursalControl();
   lineaControl = buildLineaControl();
   NumberFormatter formatter = new NumberFormatter(NumberFormat.getNumberInstance());
   formatter.setValueClass(Double.class);
   // formatter.setMaximum(new Integer(0));
   meses = new JFormattedTextField(formatter);
   meses.setValue(new Double(0));
   ordenBox = new JComboBox(TIPO_DE_ORDENAMIENTO);
   formaBox = new JComboBox(ORDENAMIENTO);
   filtrosBox =
       new JComboBox(
           new Object[] {
             new ParamLabelValue("TODOS", " LIKE '%'"),
             new ParamLabelValue("ALCANCE MAYOR", ">$P{MESESF}"),
             new ParamLabelValue("ALCANCE MENOR", "<=$P{MESESF}")
           });
   mesesF = new JFormattedTextField(formatter);
   mesesF.setValue(new Double(0));
   alcance = new JCheckBox("", false);
   todasLasSucursales = new JCheckBox("", false);
   todasLasSucursales.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           sucursalControl.setEnabled(!todasLasSucursales.isSelected());
         }
       });
   filtro2Box =
       new JComboBox(
           new Object[] {
             new ParamLabelValue("TODOS", " "),
             new ParamLabelValue("DE LINEA", "AND DELINEA IS TRUE"),
             new ParamLabelValue("ESPECIALES", "AND DELINEA IS FALSE")
           });
 }
 public static CoveringInfo getYearlyCoveringInfo(Date from, Date to) {
   CoveringInfo monthlyCoveringInfo = getMonthlyCoveringInfo(from, to);
   if (monthlyCoveringInfo.getCountBetween() < 12) {
     return new CoveringInfo(0, false);
   }
   boolean coverable = monthlyCoveringInfo.isCoverable();
   if (!from.equals(DateUtils.truncate(from, MONTH))) {
     from = DateUtils.addMonths(DateUtils.truncate(from, MONTH), 1);
     coverable = false;
   }
   Calendar cal = Calendar.getInstance();
   cal.setTime(from);
   int fromMonth = cal.get(MONTH);
   int beginOffset = (12 - fromMonth % 12) % 12;
   int endOffset = (monthlyCoveringInfo.getCountBetween() - beginOffset) % 12;
   if (beginOffset > 0 || endOffset > 0) {
     coverable = false;
   }
   return new CoveringInfo(
       (monthlyCoveringInfo.getCountBetween() - beginOffset - endOffset) / 12, coverable);
 }
Exemple #6
0
  /**
   * 8、日期
   *
   * @throws ParseException
   */
  @Test
  public void test8() throws ParseException {
    // 生成Date对象
    Date date = DateUtils.parseDate("2010/01/01 11:22:33", new String[] {"yyyy/MM/dd HH:mm:ss"});

    // 10天后
    Date tenDaysAfter = DateUtils.addDays(date, 10); // => 2010/01/11
    // 11:22:33
    System.out.println(DateFormatUtils.format(tenDaysAfter, "yyyy/MM/dd HH:mm:ss"));

    // 前一个月
    Date prevMonth = DateUtils.addMonths(date, -1); // => 2009/12/01
    // 11:22:33
    System.out.println(DateFormatUtils.format(prevMonth, "yyyy/MM/dd HH:mm:ss"));

    // 判断是否是同一天
    Date date1 = DateUtils.parseDate("2010/01/01 11:22:33", new String[] {"yyyy/MM/dd HH:mm:ss"});
    Date date2 = DateUtils.parseDate("2010/01/01 22:33:44", new String[] {"yyyy/MM/dd HH:mm:ss"});
    System.out.println(DateUtils.isSameDay(date1, date2)); // true

    // 日期格式化
    System.out.println(DateFormatUtils.format(new Date(), "yyyy/MM/dd HH:mm:ss"));
  }
Exemple #7
0
 public static Date nextMonth(Date date) {
   return DateUtils.addMonths(new Date(), 30);
 }
Exemple #8
0
 public static Date lastMonth(Date date) {
   return DateUtils.addMonths(new Date(), -1);
 }
Exemple #9
0
 /** 查看 */
 @RequestMapping(value = "/view", method = RequestMethod.GET)
 public String view(Type type, Date beginDate, Date endDate, Model model) {
   if (type == null) {
     type = Type.month;
   }
   if (beginDate == null) {
     beginDate = DateUtils.addMonths(new Date(), -11);
   }
   if (endDate == null) {
     endDate = new Date();
   }
   Map<Date, BigDecimal> salesAmountMap = new LinkedHashMap<Date, BigDecimal>();
   Map<Date, Integer> salesVolumeMap = new LinkedHashMap<Date, Integer>();
   Calendar beginCalendar = DateUtils.toCalendar(beginDate);
   Calendar endCalendar = DateUtils.toCalendar(endDate);
   int beginYear = beginCalendar.get(Calendar.YEAR);
   int endYear = endCalendar.get(Calendar.YEAR);
   int beginMonth = beginCalendar.get(Calendar.MONTH);
   int endMonth = endCalendar.get(Calendar.MONTH);
   for (int year = beginYear; year <= endYear; year++) {
     if (salesAmountMap.size() >= MAX_SIZE) {
       break;
     }
     Calendar calendar = Calendar.getInstance();
     calendar.set(Calendar.YEAR, year);
     if (type == Type.year) {
       calendar.set(Calendar.MONTH, calendar.getActualMinimum(Calendar.MONTH));
       calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
       calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
       calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
       calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
       Date begin = calendar.getTime();
       calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH));
       calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
       calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
       calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
       calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
       Date end = calendar.getTime();
       BigDecimal salesAmount = orderService.getSalesAmount(begin, end);
       Integer salesVolume = orderService.getSalesVolume(begin, end);
       salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO);
       salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0);
     } else {
       for (int month = year == beginYear ? beginMonth : calendar.getActualMinimum(Calendar.MONTH);
           month <= (year == endYear ? endMonth : calendar.getActualMaximum(Calendar.MONTH));
           month++) {
         if (salesAmountMap.size() >= MAX_SIZE) {
           break;
         }
         calendar.set(Calendar.MONTH, month);
         calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
         calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMinimum(Calendar.HOUR_OF_DAY));
         calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE));
         calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND));
         Date begin = calendar.getTime();
         calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
         calendar.set(Calendar.HOUR_OF_DAY, calendar.getActualMaximum(Calendar.HOUR_OF_DAY));
         calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE));
         calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND));
         Date end = calendar.getTime();
         BigDecimal salesAmount = orderService.getSalesAmount(begin, end);
         Integer salesVolume = orderService.getSalesVolume(begin, end);
         salesAmountMap.put(begin, salesAmount != null ? salesAmount : BigDecimal.ZERO);
         salesVolumeMap.put(begin, salesVolume != null ? salesVolume : 0);
       }
     }
   }
   model.addAttribute("types", Type.values());
   model.addAttribute("type", type);
   model.addAttribute("beginDate", beginDate);
   model.addAttribute("endDate", endDate);
   model.addAttribute("salesAmountMap", salesAmountMap);
   model.addAttribute("salesVolumeMap", salesVolumeMap);
   return "/admin/sales/view";
 }