List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting the last day of the month * /*from www . j a v a2s . c om*/ * @param date * @return */ public static Date getLastDayOfMonth(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.DATE, c.getActualMaximum(Calendar.DAY_OF_MONTH)); return c.getTime(); }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting the last day of the week * /*from ww w . j a v a2 s .c o m*/ * @param date * @return date */ public static Date getLastDayOfWeek(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.DATE, c.getActualMaximum(Calendar.DAY_OF_WEEK)); return c.getTime(); }
From source file:org.kuali.kfs.module.endow.document.service.impl.FrequencyDatesServiceImpl.java
/** * This method will check the current month and set the calendar to that month * @param month, dayOfMonth month to set the calendar, dayOfMonth day of the month to set to * @return calendar calendar is set to the month selected *///from w ww .j a v a 2 s. co m protected void setCalendarWithDays(Calendar calendar, String dayOfMonth) { int dayInMonthToSet; int calendarMonth = calendar.get(Calendar.MONTH); if (StringUtils.equalsIgnoreCase(dayOfMonth, EndowConstants.FrequencyMonthly.MONTH_END)) { // month end for the month so need to get max days... dayInMonthToSet = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); } else { dayInMonthToSet = Integer.parseInt(dayOfMonth); if (dayInMonthToSet > calendar.getActualMaximum(Calendar.DAY_OF_MONTH)) { dayInMonthToSet = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); } } calendar.set(Calendar.DAY_OF_MONTH, dayInMonthToSet); }
From source file:it.f2informatica.webapp.controller.ConsultantController.java
private void setExperiencePeriods(ExperienceModel experienceModel) { String monthFrom = experienceModel.getMonthFrom(); String yearFrom = experienceModel.getYearFrom(); Date periodFrom = periodParser.resolveDateByMonthAndYear(monthFrom, yearFrom); experienceModel.setPeriodFrom(periodFrom); if (!experienceModel.isCurrent()) { Calendar calendar = Calendar.getInstance(); String monthTo = experienceModel.getMonthTo(); String yearTo = experienceModel.getYearTo(); Date dateTo = periodParser.resolveDateByMonthAndYear(monthTo, yearTo); calendar.setTime(dateTo);/* ww w . j a v a 2 s .c o m*/ calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); experienceModel.setPeriodTo(calendar.getTime()); } }
From source file:com.mb.framework.util.DateTimeUtil.java
/** * This method is used for getting number of day of month * //from w w w. j a va2s. c o m * @param currentMonth * @return */ public static int getNumOfDaysOfMonth(Date currentMonth) { Calendar calendar = Calendar.getInstance(); calendar.setTime(currentMonth); return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); }
From source file:org.projectforge.web.timesheet.TimesheetEventsProvider.java
/** * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime) *//*from w ww . ja v a 2 s . co m*/ @Override protected void buildEvents(final DateTime start, final DateTime end) { totalDuration = 0; for (int i = 0; i < durationsPerDayOfMonth.length; i++) { durationsPerDayOfMonth[i] = 0; } for (int i = 0; i < durationsPerDayOfYear.length; i++) { durationsPerDayOfYear[i] = 0; } final Integer userId = calFilter.getTimesheetUserId(); if (userId == null) { return; } breaksMap = new HashMap<String, TimesheetDO>(); int breaksCounter = 0; final TimesheetFilter filter = new TimesheetFilter(); filter.setUserId(userId); filter.setStartTime(start.toDate()); filter.setStopTime(end.toDate()); filter.setOrderType(OrderDirection.ASC); timesheets = timesheetDao.getList(filter); boolean longFormat = false; days = Days.daysBetween(start, end).getDays(); if (days < 10) { // Week or day view: longFormat = true; month = null; firstDayOfMonth = null; } else { // Month view: final DateTime currentMonth = new DateTime(start.plusDays(10), PFUserContext.getDateTimeZone()); // Now we're definitely in the right // month. month = currentMonth.getMonthOfYear(); firstDayOfMonth = currentMonth.withDayOfMonth(1); } if (CollectionUtils.isEmpty(timesheets) == false) { DateTime lastStopTime = null; for (final TimesheetDO timesheet : timesheets) { final DateTime startTime = new DateTime(timesheet.getStartTime(), PFUserContext.getDateTimeZone()); final DateTime stopTime = new DateTime(timesheet.getStopTime(), PFUserContext.getDateTimeZone()); if (stopTime.isBefore(start) == true || startTime.isAfter(end) == true) { // Time sheet doesn't match time period start - end. continue; } if (calFilter.isShowBreaks() == true) { if (lastStopTime != null && DateHelper.isSameDay(stopTime, lastStopTime) == true && startTime.getMillis() - lastStopTime.getMillis() > 60000) { // Show breaks between time sheets of one day (> 60s). final Event breakEvent = new Event(); breakEvent.setEditable(false); final String breakId = String.valueOf(++breaksCounter); breakEvent.setClassName(BREAK_EVENT_CLASS_NAME).setId(breakId).setStart(lastStopTime) .setEnd(startTime).setTitle(getString("timesheet.break")); breakEvent.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9"); events.put(breakId, breakEvent); final TimesheetDO breakTimesheet = new TimesheetDO().setStartDate(lastStopTime.toDate()) .setStopTime(startTime.getMillis()); breaksMap.put(breakId, breakTimesheet); } lastStopTime = stopTime; } final long duration = timesheet.getDuration(); final MyEvent event = new MyEvent(); final String id = "" + timesheet.getId(); event.setClassName(EVENT_CLASS_NAME); event.setId(id); event.setStart(startTime); event.setEnd(stopTime); final String title = getTitle(timesheet); if (longFormat == true) { // Week or day view: event.setTitle(title + "\n" + getToolTip(timesheet) + "\n" + formatDuration(duration, false)); } else { // Month view: event.setTitle(title); } if (month != null && startTime.getMonthOfYear() != month && stopTime.getMonthOfYear() != month) { // Display time sheets of other month as grey blue: event.setTextColor("#222222").setBackgroundColor("#ACD9E8").setColor("#ACD9E8"); } events.put(id, event); if (month == null || startTime.getMonthOfYear() == month) { totalDuration += duration; addDurationOfDay(startTime.getDayOfMonth(), duration); } final int dayOfYear = startTime.getDayOfYear(); addDurationOfDayOfYear(dayOfYear, duration); event.setTooltip(getString("timesheet"), new String[][] { { title }, { timesheet.getLocation(), getString("timesheet.location") }, { KostFormatter.formatLong(timesheet.getKost2()), getString("fibu.kost2") }, { TaskFormatter.instance().getTaskPath(timesheet.getTaskId(), true, OutputType.PLAIN), getString("task") }, { timesheet.getDescription(), getString("description") } }); } } if (calFilter.isShowStatistics() == true) { // Show statistics: duration of every day is shown as all day event. DateTime day = start; final Calendar cal = DateHelper.getCalendar(); cal.setTime(start.toDate()); final int numberOfDaysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR); int paranoiaCounter = 0; do { if (++paranoiaCounter > 1000) { log.error( "Paranoia counter exceeded! Dear developer, please have a look at the implementation of buildEvents."); break; } final int dayOfYear = day.getDayOfYear(); final long duration = durationsPerDayOfYear[dayOfYear]; final boolean firstDayOfWeek = day.getDayOfWeek() == PFUserContext.getJodaFirstDayOfWeek(); if (firstDayOfWeek == false && duration == 0) { day = day.plusDays(1); continue; } final Event event = new Event().setAllDay(true); final String id = "s-" + (dayOfYear); event.setId(id); event.setStart(day); final String durationString = formatDuration(duration, false); if (firstDayOfWeek == true) { // Show week of year at top of first day of week. long weekDuration = 0; for (short i = 0; i < 7; i++) { int d = dayOfYear + i; if (d > numberOfDaysInYear) { d -= numberOfDaysInYear; } weekDuration += durationsPerDayOfYear[d]; } final StringBuffer buf = new StringBuffer(); buf.append(getString("calendar.weekOfYearShortLabel")).append(DateHelper.getWeekOfYear(day)); if (days > 1 && weekDuration > 0) { // Show total sum of durations over all time sheets of current week (only in week and month view). buf.append(": ").append(formatDuration(weekDuration, false)); } if (duration > 0) { buf.append(", ").append(durationString); } event.setTitle(buf.toString()); } else { event.setTitle(durationString); } event.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9"); event.setEditable(false); events.put(id, event); day = day.plusDays(1); } while (day.isAfter(end) == false); } }
From source file:com.rogchen.common.xml.UtilDateTime.java
public static Timestamp getYearEnd(Timestamp stamp, TimeZone timeZone, Locale locale) { Calendar tempCal = toCalendar(stamp, timeZone, locale); tempCal.set(tempCal.get(Calendar.YEAR), tempCal.getActualMaximum(Calendar.MONTH) + 1, 0, 0, 0, 0); return getMonthEnd(new Timestamp(tempCal.getTimeInMillis()), timeZone, locale); }
From source file:org.openconcerto.erp.core.finance.accounting.ui.ClotureMensuellePayePanel.java
public ClotureMensuellePayePanel() { super();//from ww w . ja va2 s. c om this.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; c.insets = new Insets(2, 2, 1, 2); c.weightx = 0; c.weighty = 0; c.gridheight = 1; c.gridwidth = 1; c.gridx = 0; c.gridy = 0; JLabel labelMois = new JLabel("Cloture du mois de "); this.add(labelMois, c); final ElementComboBox selMois = new ElementComboBox(true, 25); selMois.init(((ComptaPropsConfiguration) Configuration.getInstance()).getDirectory() .getElement(MoisSQLElement.class)); selMois.setButtonsVisible(false); c.gridx++; this.add(selMois, c); JLabel labelAnnee = new JLabel("Anne"); c.gridx++; this.add(labelAnnee, c); final JTextField textAnnee = new JTextField(5); c.gridx++; this.add(textAnnee, c); DateFormat format = new SimpleDateFormat("yyyy"); textAnnee.setText(format.format(new Date())); c.gridy++; c.gridx = 0; final JCheckBox boxValid = new JCheckBox("Valider toutes les payes du mois"); final JCheckBox boxCompta = new JCheckBox("Gnrer les critures comptables associes"); c.gridwidth = GridBagConstraints.REMAINDER; this.add(boxValid, c); boxValid.setSelected(true); c.gridy++; this.add(boxCompta, c); JButton buttonClot = new JButton("Clturer"); JButton buttonFermer = new JButton("Fermer"); JPanel panelButton = new JPanel(); panelButton.add(buttonClot); panelButton.add(buttonFermer); c.anchor = GridBagConstraints.SOUTHEAST; c.fill = GridBagConstraints.NONE; c.weighty = 1; c.gridy++; this.add(panelButton, c); buttonFermer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ((JFrame) SwingUtilities.getRoot(ClotureMensuellePayePanel.this)).dispose(); } }); buttonClot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { // Valider les fiches non valids des salaris actifs if (boxValid.isSelected()) { SQLSelect selFiche = new SQLSelect(); SQLTable tableFiche = ClotureMensuellePayePanel.this.base.getTable("FICHE_PAYE"); SQLTable tableSalarie = ClotureMensuellePayePanel.this.base.getTable("SALARIE"); SQLTable tableInfosSal = ClotureMensuellePayePanel.this.base.getTable("INFOS_SALARIE_PAYE"); selFiche.addSelect(tableFiche.getField("ID")); selFiche.setWhere(new Where(tableFiche.getField("VALIDE"), "=", Boolean.FALSE)); selFiche.andWhere(new Where(tableFiche.getField("ID_MOIS"), "=", selMois.getSelectedId())); selFiche.andWhere( new Where(tableFiche.getField("ANNEE"), "=", new Integer(textAnnee.getText()))); selFiche.andWhere( new Where(tableSalarie.getField("ID"), "=", tableFiche.getField("ID_SALARIE"))); selFiche.andWhere(new Where(tableInfosSal.getField("ID"), "=", tableSalarie.getField("ID_INFOS_SALARIE_PAYE"))); // FIXME ne pas valider les fiches d'un employ renvoy // Where w2 = new Where(tableInfosSal.getField("DATE_SORTIE"), "IS", // "NULL"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DATE, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); cal.set(Calendar.YEAR, Integer.parseInt(textAnnee.getText())); cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); Where w = new Where(tableInfosSal.getField("DATE_SORTIE"), "<=", cal.getTime()); w = w.or(new Where(tableInfosSal.getField("DATE_SORTIE"), "=", (Object) null)); selFiche.andWhere(w); String req = selFiche.asString(); System.err.println(req); List l = (List) ClotureMensuellePayePanel.this.base.getDataSource().execute(req, new ArrayListHandler()); for (int i = 0; i < l.size(); i++) { Object[] tmp = (Object[]) l.get(i); SQLRow rowFicheTmp = tableFiche.getRow(Integer.parseInt(tmp[0].toString())); System.err.println(rowFicheTmp); FichePayeSQLElement.validationFiche(rowFicheTmp.getID()); } } // cloture du mois et generation compta SQLSelect selFiche = new SQLSelect(ClotureMensuellePayePanel.this.base); SQLTable tableFiche = ClotureMensuellePayePanel.this.base.getTable("FICHE_PAYE"); SQLTable tableMois = ClotureMensuellePayePanel.this.base.getTable("MOIS"); selFiche.addSelect(tableFiche.getField("ID")); selFiche.setWhere(new Where(tableFiche.getField("VALIDE"), "=", Boolean.TRUE)); selFiche.andWhere(new Where(tableFiche.getField("ID_MOIS"), "=", selMois.getSelectedId())); selFiche.andWhere( new Where(tableFiche.getField("ANNEE"), "=", new Integer(textAnnee.getText()))); String req = selFiche.asString(); List l = (List) ClotureMensuellePayePanel.this.base.getDataSource().execute(req, new ArrayListHandler()); if (l != null && l.size() > 0) { int[] idS = new int[l.size()]; SQLRow rowMois = tableMois.getRow(selMois.getSelectedId()); for (int i = 0; i < l.size(); i++) { Object[] tmp = (Object[]) l.get(i); idS[i] = Integer.parseInt(tmp[0].toString()); SQLRow rowFiche = tableFiche.getRow(idS[i]); FichePayeSQLElement.clotureMensuelle(selMois.getSelectedId(), Integer.parseInt(textAnnee.getText()), rowFiche.getInt("ID_SALARIE")); } if (boxCompta.isSelected()) { new GenerationMvtFichePaye(idS, rowMois.getString("NOM"), textAnnee.getText()); } } System.err.println( "ClotureMensuellePayePanel.ClotureMensuellePayePanel().new ActionListener() {...}.actionPerformed()"); JOptionPane.showMessageDialog(null, "Clture termine"); } catch (Exception ex) { ExceptionHandler.handle("Unable to complete operation", ex); } } }); }
From source file:org.projectforge.core.QueryFilter.java
/** * Adds Expression.between for given time period. * @param dateField/* ww w . j a v a 2 s. c om*/ * @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) { 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()); 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()); int lastDayOfYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR); cal.set(Calendar.DAY_OF_YEAR, lastDayOfYear); hi = new java.sql.Date(cal.getTimeInMillis()); } add(Expression.between(dateField, lo, hi)); } }
From source file:com.persistent.cloudninja.controller.RunningInstancesJSONDataController.java
public List<String> generateStartAndEndTime(int year, int month) { DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.sss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); Date currentDate = cal.getTime(); int currentMonth = cal.get(Calendar.MONTH) + 1; String start = month + "/01/" + year + " 00:00:00.000"; String end = null;/* w w w .j a va 2 s . c o m*/ if (month == currentMonth) { end = dateFormat.format(currentDate); } else { try { cal.setTime(dateFormat.parse(start)); int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); end = month + "/" + maxDay + "/" + year + " 23:59:59.000"; } catch (ParseException e) { e.printStackTrace(); } } List<String> time = new ArrayList<String>(); time.add(start); time.add(end); return time; }