Example usage for java.util Calendar getActualMaximum

List of usage examples for java.util Calendar getActualMaximum

Introduction

In this page you can find the example usage for java.util Calendar getActualMaximum.

Prototype

public int getActualMaximum(int field) 

Source Link

Document

Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.

Usage

From source file:org.meveocrm.admin.action.reporting.MeasurementBean.java

public void generateMVModel() throws ParseException {
    if (measurableQuantity != null && selectedDate != null) {
        mainMVModel = new ArrayList<MeasuredValue>();
        Calendar cal = Calendar.getInstance();
        cal.setTime(selectedDate);//  ww  w .j  a  v  a 2 s  .co  m

        int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

        for (int i = 0; i < daysInMonth; i++) {
            String dateCol = StringUtils
                    .leftPad(StringUtils.leftPad(String.valueOf(String.valueOf(i + 1)), 2, '0') + "/"
                            + String.valueOf(cal.get(Calendar.MONTH) + 1), 2, '0')
                    + "/" + String.valueOf(cal.get(Calendar.YEAR));
            Date date = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(dateCol);
            MeasuredValue mv = measuredValueService.getByDate(date, period, measurableQuantity);
            if (mv == null) {
                mv = new MeasuredValue();
                mv.setMeasurableQuantity(measurableQuantity);
                mv.setDate(date);
                mv.setMeasurementPeriod(period);
            }
            mainMVModel.add(mv);
        }
    }
}

From source file:nl.strohalm.cyclos.services.accounts.cards.CardServiceImpl.java

private Card buildNewCard(final Member member) {

    final Calendar now = Calendar.getInstance();

    final Card newCard = new Card();
    final CardType cardType = member.getMemberGroup().getCardType();
    newCard.setCardType(cardType);/*from w w w .  j  av a2s. c o m*/
    newCard.setOwner(member);
    newCard.setCreationDate(now);
    newCard.setStatus(Status.PENDING);

    final Calendar expirationDate = (Calendar) now.clone();
    expirationDate.add(cardType.getDefaultExpiration().getField().getValue(),
            cardType.getDefaultExpiration().getNumber());
    if (cardType.isIgnoreDayInExpirationDate()) {
        expirationDate.set(Calendar.DAY_OF_MONTH, expirationDate.getActualMaximum(Calendar.DAY_OF_MONTH));
    }
    newCard.setExpirationDate(expirationDate);
    newCard.setCardNumber(buildCardNumber(cardType.getCardFormatNumber()));

    if (cardType.getCardSecurityCode() == CardType.CardSecurityCode.AUTOMATIC) {
        newCard.setCardSecurityCode(buildCardSecurityCode(cardType.getCardSecurityCodeLength().getMax()));
    }

    return newCard;
}

From source file:com.rogchen.common.xml.UtilDateTime.java

public static String getLastDayOfMonth(int year, int month) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE));
    return new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
}

From source file:com.huateng.ebank.framework.util.DateUtil.java

/**
 * ?/*from  w  w  w  .  ja va 2 s.com*/
 *
 * @param startDate
 * @param endDate
 * @return
 */
public static boolean isSameDate(Date startDate, Date endDate) {
    Calendar calendarStartDate = Calendar.getInstance();
    Calendar calendarEndDate = Calendar.getInstance();

    // 
    calendarStartDate.setTime(startDate);
    calendarEndDate.setTime(endDate);
    if (startDate.after(endDate)) {
        Calendar swap = calendarStartDate;
        calendarStartDate = calendarEndDate;
        calendarEndDate = swap;
    }

    if (calendarStartDate.get(Calendar.DATE) == calendarEndDate.get(Calendar.DATE))
        return true;

    if (calendarStartDate.get(Calendar.DATE) > calendarEndDate.get(Calendar.DATE)) {
        if (calendarEndDate.get(Calendar.DATE) == calendarEndDate.getActualMaximum(Calendar.DATE))
            return true;
    }

    return false;
}

From source file:org.techytax.business.zk.calendar.CalendarController.java

@Listen("onClick = #invoiceButton")
public void createInvoice() throws IOException {
    InputStream is = null;/*  w w w .  j  av  a  2 s .  c o  m*/
    try {

        Calendar cal = GregorianCalendar.getInstance();
        Date calendarDate = calendars.getCurrentDate();
        cal.setTime(calendarDate);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
        Date endDate = cal.getTime();

        cal.set(Calendar.DAY_OF_MONTH, 1);
        Date beginDate = cal.getTime();
        List<CalendarEvent> eventList = calendarModel.get(beginDate, endDate, null);

        invoice = new Invoice();
        invoice.setUnitsOfWork(countUnitsOfWork(eventList));
        invoice.setMonth(DateHelper.getMaand(endDate));
        int jaar = cal.get(Calendar.YEAR);
        String factuurNummerString = Integer.toString(jaar);
        invoice.setYear(jaar);
        int maand = cal.get(Calendar.MONTH) + 1;
        if (maand < 10) {
            factuurNummerString += "0";
        }
        factuurNummerString += Integer.toString(maand);

        List<Cost> sentAndPaidInvoicesInPeriod = costDao
                .getInvoicesSentAndPaid(new FiscalPeriod(beginDate, new Date()));
        List<Cost> invoices = new ArrayList<>();

        for (Cost cost : sentAndPaidInvoicesInPeriod) {
            if (cost.getCostType().equals(INVOICE_SENT)) {
                if (cost.getDescription().contains(factuurNummerString)) {
                    invoices.add(cost);
                }
            }
        }

        int factuurAantal = invoices.size() + 1;
        String factuurAantalString = Integer.toString(factuurAantal);
        if (factuurAantal < 10) {
            factuurAantalString = "0" + factuurAantalString;
        }
        factuurNummerString += factuurAantalString;
        invoice.setInvoiceNumber(Integer.parseInt(factuurNummerString));
        invoice.setInvoiceDate(DateHelper.getInvoiceDateString(new Date()));
        invoice.setNofDays(44);
        invoice.setExpiryDate(DateHelper.getInvoiceDateString(DateHelper.getDateAfterDays(44)));

        Customer customer = selectedProject.getCustomer();
        sendInvoiceButton.setLabel(Labels.getLabel("send.invoice.to") + ": " + customer.getEmailInvoice());

        invoice.setConsumerAddress(customer.getFullAddress());
        invoice.setConsumerName(customer.getName());
        invoice.setVat(selectedProject.getVatType().getValueAsInteger(new Date()));
        invoice.setActivityDescription(selectedProject.getActivityDescription());
        invoice.setRate(selectedProject.getRate());

        BigDecimal netAmount = new BigDecimal(invoice.getUnitsOfWork() * invoice.getRate().floatValue());
        netAmount = AmountHelper.round(netAmount);

        invoice.setNetAmount(netAmount);
        invoice.setEmail(customer.getEmailInvoice());
        BigDecimal netAmountAfterDiscount = netAmount;
        if (StringUtils.isNotEmpty(discount.getValue())) {
            int discountPercentage = Integer.parseInt(discount.getValue());
            invoice.setDiscountPercentage(discountPercentage);
            BigDecimal discount = new BigDecimal(netAmount.doubleValue() * discountPercentage / 100.0d);
            invoice.setDiscount(discount);
            netAmountAfterDiscount = netAmount.subtract(discount);
            invoice.setNetAmountAfterDiscount(netAmountAfterDiscount);
        }
        BigDecimal btwBedrag = new BigDecimal(netAmountAfterDiscount.doubleValue() * invoice.getVat() / 100.0d);
        btwBedrag = AmountHelper.round(btwBedrag);
        BigDecimal totaalBedrag = netAmountAfterDiscount.add(btwBedrag);
        totaalBedrag = AmountHelper.round(totaalBedrag);
        invoice.setVatAmount(btwBedrag);
        invoice.setTotalAmount(totaalBedrag);
        invoice.setNetAmountAfterDiscount(netAmountAfterDiscount);
        PdfInvoiceHelper pdfInvoiceHelper = new PdfInvoiceHelper();
        invoiceBuf = pdfInvoiceHelper.createPdfInvoice(invoice, getUser());

        // prepare the AMedia for iframe
        final InputStream mediais = new ByteArrayInputStream(invoiceBuf);
        final AMedia amedia = new AMedia("Invoice.pdf", "pdf", "application/pdf", mediais);

        // set iframe content
        invoiceFrame = (Iframe) Path.getComponent("/win/invoiceWindow/invoiceFrame");
        invoiceFrame.setContent(amedia);
        invoiceWindow.doPopup();
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}

From source file:net.groupbuy.controller.admin.StaticController.java

/**
 * ???//from  www.  ja  v  a2 s .c o  m
 */
@RequestMapping(value = "/build", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> build(BuildType buildType, Long articleCategoryId,
        Long productCategoryId, Date beginDate, Date endDate, Integer first, Integer count) {
    long startTime = System.currentTimeMillis();
    if (beginDate != null) {
        Calendar calendar = DateUtils.toCalendar(beginDate);
        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));
        beginDate = calendar.getTime();
    }
    if (endDate != null) {
        Calendar calendar = DateUtils.toCalendar(endDate);
        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));
        endDate = calendar.getTime();
    }
    if (first == null || first < 0) {
        first = 0;
    }
    if (count == null || count <= 0) {
        count = 50;
    }
    int buildCount = 0;
    boolean isCompleted = true;
    if (buildType == BuildType.index) {
        buildCount = staticService.buildIndex();
    } else if (buildType == BuildType.article) {
        ArticleCategory articleCategory = articleCategoryService.find(articleCategoryId);
        List<Article> articles = articleService.findList(articleCategory, beginDate, endDate, first, count);
        for (Article article : articles) {
            buildCount += staticService.build(article);
        }
        first += articles.size();
        if (articles.size() == count) {
            isCompleted = false;
        }
    } else if (buildType == BuildType.product) {
        ProductCategory productCategory = productCategoryService.find(productCategoryId);
        List<Product> products = productService.findList(productCategory, beginDate, endDate, first, count);
        for (Product product : products) {
            buildCount += staticService.build(product);
        }
        first += products.size();
        if (products.size() == count) {
            isCompleted = false;
        }
    } else if (buildType == BuildType.other) {
        buildCount = staticService.buildOther();
    }
    long endTime = System.currentTimeMillis();
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("first", first);
    map.put("buildCount", buildCount);
    map.put("buildTime", endTime - startTime);
    map.put("isCompleted", isCompleted);
    return map;
}

From source file:DateUtil.java

/**
 * Returns true if the two calendars represent dates that fall in the same
 * week, else false. A week here is defined by the Calendar.WEEK_OF_YEAR
 * package. Special provisions have been made to test weeks than may span the
 * end/beginning of a year, and returning true if the two calendars are
 * specifying dates within such a week, despite Calendar.WEEK_OF_YEAR being
 * unequal for the two Calendars./*from  ww  w .  j  av a 2s  .c o  m*/
 * 
 * @param c1
 *          Calendar one.
 * @param c2
 *          Calendar two.
 * @return boolean.
 */
public static boolean inSameWeek(Calendar c1, Calendar c2) {
    if (inSameYear(c1, c2) && (c1.get(Calendar.WEEK_OF_YEAR) == c2.get(Calendar.WEEK_OF_YEAR)))
        return true;

    Calendar tmp;
    if (c1.before(c2)) {
        tmp = c2;
        c2 = c1;
        c1 = tmp;
    }

    int c1week = c1.get(Calendar.WEEK_OF_YEAR);
    int c2week = c1.get(Calendar.WEEK_OF_YEAR);

    if (c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR) + 1) {
        if (c1week == c1.getActualMinimum(Calendar.WEEK_OF_YEAR)
                && c2week == c2.getActualMaximum(Calendar.WEEK_OF_YEAR)) {
            tmp = (Calendar) c2.clone();
            tmp.add(Calendar.DAY_OF_YEAR, 7);
            if (tmp.get(Calendar.WEEK_OF_YEAR) > c1week)
                return true;
        }
    }

    return false;
}

From source file:org.projectforge.framework.persistence.api.QueryFilter.java

/**
 * Adds Expression.between for given time period.
 * /*from  w  w  w  .ja va2s. c o m*/
 * @param dateField
 * @param year if <= 0 do nothing.
 * @param month if < 0 choose whole year, otherwise given month. (Calendar.MONTH);
 */
public void setYearAndMonth(final String dateField, final int year, final int month) {
    if (year > 0) {
        final Calendar cal = DateHelper.getUTCCalendar();
        cal.set(Calendar.YEAR, year);
        java.sql.Date lo = null;
        java.sql.Date hi = null;
        if (month >= 0) {
            cal.set(Calendar.MONTH, month);
            cal.set(Calendar.DAY_OF_MONTH, 1);
            lo = new java.sql.Date(cal.getTimeInMillis());
            final int lastDayOfMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            cal.set(Calendar.DAY_OF_MONTH, lastDayOfMonth);
            hi = new java.sql.Date(cal.getTimeInMillis());
        } else {
            cal.set(Calendar.DAY_OF_YEAR, 1);
            lo = new java.sql.Date(cal.getTimeInMillis());
            final int lastDayOfYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
            cal.set(Calendar.DAY_OF_YEAR, lastDayOfYear);
            hi = new java.sql.Date(cal.getTimeInMillis());
        }
        add(Restrictions.between(dateField, lo, hi));
    }
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.EtatJournauxPanel.java

private JPanel creerJournalMoisPanel(final Date date, long debit, long credit, final Journal jrnl) {

    final JPanel panelMoisCompte = new JPanel();
    panelMoisCompte.setLayout(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridx = 0;//from  w ww. j a  va  2 s. c o  m
    c.gridy = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 1;
    c.weighty = 0;

    panelMoisCompte.setBorder(BorderFactory.createTitledBorder(dateFormat.format(date)));

    // Date du mois
    panelMoisCompte.add(new JLabel(dateFormat.format(date)), c);

    // Totaux du mois
    c.gridx++;
    panelMoisCompte.add(new JLabel(" dbit : " + GestionDevise.currencyToString(debit)), c);
    c.gridx++;
    panelMoisCompte.add(new JLabel(" crdit : " + GestionDevise.currencyToString(credit)), c);

    // Bouton dtails
    JButton boutonShow = new JButton("+/-");
    boutonShow.setOpaque(false);
    boutonShow.setHorizontalAlignment(SwingConstants.LEFT);

    c.weightx = 0;
    c.gridx++;
    panelMoisCompte.add(boutonShow, c);

    boutonShow.addActionListener(new ActionListener() {
        private boolean isShow = false;
        private ListPanelEcritures listEcriture;

        public void actionPerformed(ActionEvent e) {

            System.err.println(this.isShow);

            // Afficher la JTable du compte
            if (!this.isShow) {
                final SQLElement element = Configuration.getInstance().getDirectory().getElement("ECRITURE");
                final SQLTable ecrTable = element.getTable();

                Calendar cal = Calendar.getInstance();

                cal.setTime(date);
                cal.set(Calendar.DATE, 1);
                Date inf = cal.getTime();

                cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
                Date sup = cal.getTime();

                System.out.println("Inf : " + inf + " Sup : " + sup);
                Where w = new Where(ecrTable.getField("ID_JOURNAL"), "=", jrnl.getId());
                Where w2 = new Where(ecrTable.getField("DATE"), inf, sup);

                if (!UserManager.getInstance().getCurrentUser().getRights()
                        .haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) {
                    // TODO Show Restricted acces in UI
                    w = w.and(new Where(ecrTable.getField("COMPTE_NUMERO"), "LIKE", "411%"));
                }

                this.listEcriture = new ListPanelEcritures(element, w.and(w2));
                this.listEcriture.setModificationVisible(false);
                this.listEcriture.setAjoutVisible(false);
                this.listEcriture.setSuppressionVisible(false);
                this.listEcriture.getListe().setSQLEditable(false);

                Dimension d;
                // Taille limite  200 maximum
                if (this.listEcriture.getListe().getPreferredSize().height > 200) {
                    d = new Dimension(this.listEcriture.getListe().getPreferredSize().width, 200);
                } else {
                    d = new Dimension(this.listEcriture.getListe().getPreferredSize().width,
                            this.listEcriture.getListe().getPreferredSize().height + 30);
                }
                this.listEcriture.getListe().setPreferredSize(d);

                // c.gridy = 2;
                c.gridx = 0;
                c.gridy = 1;

                c.gridwidth = 4;
                c.weightx = 1;
                c.weighty = 1;
                c.fill = GridBagConstraints.BOTH;

                this.listEcriture.getListe().setSQLEditable(false);

                panelMoisCompte.add(this.listEcriture, c);
                this.listEcriture.getListe().getJTable().addMouseListener(new MouseAdapter() {
                    public void mousePressed(MouseEvent e) {
                        if (e.getButton() == MouseEvent.BUTTON3) {
                            JPopupMenu menu = new JPopupMenu();
                            menu.add(new AbstractAction("Voir la source") {
                                public void actionPerformed(ActionEvent e) {

                                    SQLRow row = base.getTable("ECRITURE")
                                            .getRow(listEcriture.getListe().getSelectedId());

                                    MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
                                }
                            });

                            menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);

                        }
                    }
                });

            } else {

                panelMoisCompte.remove(this.listEcriture);
                System.out.println("Hide ListEcriture");

                panelMoisCompte.repaint();
                panelMoisCompte.revalidate();
            }

            this.isShow = !this.isShow;
            SwingUtilities.getRoot(panelMoisCompte).repaint();
        }
    });

    return panelMoisCompte;
}

From source file:fr.paris.lutece.plugins.suggest.utils.SuggestUtils.java

/**
 * return a timestamp Object which correspond with the string specified in
 * parameter./*from www  .  j  av a 2s . c o  m*/
 * @param strDate the date who must convert
 * @param locale the locale
 * @return a timestamp Object which correspond with the string specified in
 *         parameter.
 */
public static Timestamp getLastMinute(String strDate, Locale locale) {
    try {
        Date date;
        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
        dateFormat.setLenient(false);
        date = dateFormat.parse(strDate.trim());

        Calendar caldate = new GregorianCalendar();
        caldate.setTime(date);
        caldate.set(Calendar.MILLISECOND, 0);
        caldate.set(Calendar.SECOND, 0);
        caldate.set(Calendar.HOUR_OF_DAY, caldate.getActualMaximum(Calendar.HOUR_OF_DAY));
        caldate.set(Calendar.MINUTE, caldate.getActualMaximum(Calendar.MINUTE));

        Timestamp timeStamp = new Timestamp(caldate.getTimeInMillis());

        return timeStamp;
    } catch (ParseException e) {
        return null;
    }
}