List of usage examples for java.util Calendar getActualMaximum
public int getActualMaximum(int field)
Calendar
. From source file:com.sun.toy.widget.CalendarView.java
public void setDate(long millis) { mMillis = millis;/*from ww w . j a v a 2 s . c o m*/ Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(millis); calendar.set(Calendar.DATE, 1); mDateOfWeek = calendar.get(Calendar.DAY_OF_WEEK); mMaxtDateOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); invalidate(); }
From source file:org.voidsink.anewjkuapp.fragment.CalendarFragment.java
private void loadMoreData() { if (this.isVisible() && !getLoaderManager().hasRunningLoaders()) { now = System.currentTimeMillis(); // if someone changed the time since last click // increase in month steps Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(then);//from w w w . j a v a 2s . com then += cal.getActualMaximum(Calendar.DAY_OF_MONTH) * DateUtils.DAY_IN_MILLIS; // set button text setButtonLoadText(); Analytics.eventLoadMoreEvents(getContext(), then - now); loadData(); } }
From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilter.java
@Override protected void doActivate(ComponentContext context) throws Exception { super.doActivate(context); @SuppressWarnings("unchecked") Dictionary<String, Object> props = context.getProperties(); dayOfMonth = PropertiesUtil.toString(props.get(PROP_EXPIRES_DAY_OF_MONTH), null); if (StringUtils.isBlank(dayOfMonth)) { throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month must be specified."); }/*from w w w .j av a 2 s . c om*/ if (!StringUtils.equalsIgnoreCase(LAST, dayOfMonth)) { // Make sure it's a valid value for Calendar. try { int intDay = Integer.parseInt(dayOfMonth); Calendar test = Calendar.getInstance(); if (intDay < test.getMinimum(Calendar.DAY_OF_MONTH)) { throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month is smaller than minimum allowed value."); } if (intDay > test.getActualMaximum(Calendar.DAY_OF_MONTH)) { throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month is larger than least maximum allowed value."); } } catch (NumberFormatException ex) { throw new ConfigurationException(PROP_EXPIRES_DAY_OF_MONTH, "Day of month is not a valid value."); } } }
From source file:org.shredzone.cilla.site.renderer.CalendarRenderStrategyImpl.java
/** * Writes the calendar table itself.//from ww w . j av a 2 s. c o m */ protected void writeCalendar() throws IOException { Calendar cal = generator.getDisplayCalendar(); int firstDay = cal.getFirstDayOfWeek() - 1; int firstWeekday = cal.get(Calendar.DAY_OF_WEEK) - 1; int numberOfDays = cal.getActualMaximum(Calendar.DATE); int skipDays = (firstWeekday + 7 - firstDay) % 7; out.append("<tr>"); int column = 0; for (int ix = -skipDays; ix < numberOfDays; ix++) { if (ix >= 0) { String url = generator.getDayUrl(ix + 1); if (url != null) { writeLinkedDay(ix + 1, url); } else { writeDay(ix + 1); } } else { writeEmptyDay(); } column++; if (column == 7) { column = 0; out.append("</tr>"); out.append("<tr>"); } } for (; column < 7; column++) { writeEmptyDay(); } out.append("</tr>"); }
From source file:com.timesheet.utils.Utils.java
public Date getLastDateOfMonth(Integer month) { Calendar currentCal = Calendar.getInstance(); currentCal.set(Calendar.MONTH, month); int lastDayOfMonth = currentCal.getActualMaximum(Calendar.DAY_OF_MONTH); currentCal.set(Calendar.DAY_OF_MONTH, lastDayOfMonth); Date endDate = currentCal.getTime(); return endDate; }
From source file:com.sunrun.crportal.util.CRPortalUtil.java
public static void setCalendarToLastDayOfTheMonth(Calendar thisDate) { int lastDate; lastDate = thisDate.getActualMaximum(Calendar.DATE); thisDate.set(Calendar.DATE, lastDate); thisDate.add(Calendar.DAY_OF_MONTH, 0); }
From source file:org.kuali.kfs.module.endow.businessobject.lookup.CalculateProcessDateUsingFrequencyCodeService.java
/** * This method will check and return either maximum days in the month as 28 or 29 for leap year. * It first sets the month to February and then checks the maximum days.. * @return maxDays Maximum number of days in the month of February for calendar. *//*w w w .j a va 2s . co m*/ protected int checkMaximumDaysInFebruary() { int maxDays; Calendar februaryMonthlyDateCalendar = Calendar.getInstance(); februaryMonthlyDateCalendar.set(Calendar.MONTH, Calendar.FEBRUARY); maxDays = februaryMonthlyDateCalendar.getActualMaximum(Calendar.DAY_OF_MONTH); return maxDays; }
From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilterTest.java
@Test public void testAdjustExpiresLastDayFuture() throws Exception { Calendar actual = Calendar.getInstance(); actual.add(Calendar.MINUTE, 1); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); actual.set(Calendar.DAY_OF_MONTH, actual.getActualMaximum(Calendar.DAY_OF_MONTH)); Calendar expected = Calendar.getInstance(); expected.setTime(actual.getTime());/*from www . j av a 2 s . c o m*/ final int month = expected.get(Calendar.MONTH); properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, "LAST"); filter.doActivate(componentContext); filter.adjustExpires(actual); assertTrue(DateUtils.isSameInstant(expected, actual)); assertEquals(month, actual.get(Calendar.MONTH)); }
From source file:com.adobe.acs.commons.http.headers.impl.MonthlyExpiresHeaderFilterTest.java
@Test public void testAdjustExpiresLastDayPast() throws Exception { Calendar actual = Calendar.getInstance(); actual.add(Calendar.MONTH, -1); actual.set(Calendar.SECOND, 0); actual.set(Calendar.MILLISECOND, 0); actual.set(Calendar.DAY_OF_MONTH, actual.getActualMaximum(Calendar.DAY_OF_MONTH)); Calendar expected = Calendar.getInstance(); expected.setTime(actual.getTime());/*from w w w .ja v a2 s .c o m*/ expected.add(Calendar.MONTH, 1); final int month = expected.get(Calendar.MONTH); properties.put(MonthlyExpiresHeaderFilter.PROP_EXPIRES_DAY_OF_MONTH, "LAST"); filter.doActivate(componentContext); filter.adjustExpires(actual); assertTrue(DateUtils.isSameInstant(expected, actual)); assertEquals(month, actual.get(Calendar.MONTH)); }
From source file:br.com.pontocontrol.controleponto.controller.impl.ExportadorXLSController.java
@Override public boolean extrair(FolhaMensalPonto folhaMensal, String outputFileDir) { Calendar data = Calendar.getInstance(); data.set(Calendar.MONTH, folhaMensal.getMes()); data.set(Calendar.YEAR, folhaMensal.getAno()); final String nomeArquivo = format("%s-%s_%s.xls", SessaoManager.getInstance().getUsuarioAutenticado().getLogin(), formatDate("yyyy-MMMM", data.getTime()), formatDate("yyyyMMddHHmmssSSS", new Date())); final String filePath = format("%s/%s", outputFileDir, nomeArquivo); File arquivoXLS = new File(filePath); FileOutputStream fos = null;// w w w. j av a 2 s . co m try { arquivoXLS.createNewFile(); fos = new FileOutputStream(arquivoXLS); HSSFWorkbook workbook = HSSFWorkbook.create(InternalWorkbook.createWorkbook()); final String nomePlanilha = formatDate("MMM-yy", data.getTime()); HSSFSheet planilha = workbook.createSheet(nomePlanilha); //TOTAL ROW HSSFRow totalRow = planilha.createRow(0); totalRow.createCell(CELL_INDEX.TOTAL_ROW.TOTAL_TXT).setCellValue("Total:"); totalRow.createCell(CELL_INDEX.TOTAL_ROW.TOTAL_VALUE).setCellValue(folhaMensal.calcularTotalMensal()); totalRow.createCell(CELL_INDEX.TOTAL_ROW.VAR_TXT).setCellValue("Variao:"); totalRow.createCell(CELL_INDEX.TOTAL_ROW.VAR_VALUE).setCellValue(folhaMensal.calcularVariacaoMensal()); //HEADER HSSFRow headerRow = planilha.createRow(1); headerRow.createCell(CELL_INDEX.DIA).setCellValue("Dia"); headerRow.createCell(CELL_INDEX.ENTRADA).setCellValue("Entrada"); headerRow.createCell(CELL_INDEX.ALMOCO).setCellValue("Almoo"); headerRow.createCell(CELL_INDEX.RETORNO).setCellValue("Retorno"); headerRow.createCell(CELL_INDEX.SAIDA).setCellValue("Sada"); headerRow.createCell(CELL_INDEX.TOTAL_EXP).setCellValue("Expediente"); headerRow.createCell(CELL_INDEX.VARIACAO).setCellValue("Variao"); formatHeaderRow(workbook, headerRow); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, folhaMensal.getAno()); cal.set(Calendar.MONTH, folhaMensal.getMes()); for (int dia = 1; dia <= cal.getActualMaximum(Calendar.DAY_OF_MONTH); dia++) { int i = planilha.getPhysicalNumberOfRows(); HSSFRow row = planilha.createRow(i); cal.set(Calendar.DAY_OF_MONTH, dia); row.createCell(CELL_INDEX.DIA).setCellValue(formatDate("MMM dd, EEE", cal.getTime())); RegistroDiarioPonto reg = folhaMensal.getRegistros().get(dia); if (reg != null) { row.createCell(CELL_INDEX.ENTRADA) .setCellValue(reg.getEntrada() != null ? reg.getEntrada().format(TIME_FORMATTER) : ""); row.createCell(CELL_INDEX.ALMOCO) .setCellValue(reg.getAlmoco() != null ? reg.getAlmoco().format(TIME_FORMATTER) : ""); row.createCell(CELL_INDEX.RETORNO) .setCellValue(reg.getRetorno() != null ? reg.getRetorno().format(TIME_FORMATTER) : ""); row.createCell(CELL_INDEX.SAIDA) .setCellValue(reg.getSaida() != null ? reg.getSaida().format(TIME_FORMATTER) : ""); row.createCell(CELL_INDEX.TOTAL_EXP).setCellValue( reg.isRegistroDiarioCompleto() ? reg.calcularTotalExpedienteAsNumber() : 0); row.createCell(CELL_INDEX.VARIACAO) .setCellValue(reg.isRegistroDiarioCompleto() ? reg.calcularVariacaoExpediente() : 0); } else { row.createCell(CELL_INDEX.ENTRADA).setCellValue(""); row.createCell(CELL_INDEX.ALMOCO).setCellValue(""); row.createCell(CELL_INDEX.RETORNO).setCellValue(""); row.createCell(CELL_INDEX.SAIDA).setCellValue(""); row.createCell(CELL_INDEX.TOTAL_EXP).setCellValue(""); row.createCell(CELL_INDEX.VARIACAO).setCellValue(""); } if (SessaoManager.getInstance().getUsuarioAutenticado().checarSeDiaExpediente(cal)) { formatRow(workbook, row); } else { formatHeaderRow(workbook, row); } } for (int i = 0; i < headerRow.getPhysicalNumberOfCells(); i++) { planilha.autoSizeColumn(i); } workbook.write(fos); fos.flush(); return true; } catch (IOException ex) { LOG.log(Level.SEVERE, "Erro ao criar arquivo XLS de sada", ex); return false; } finally { IOUtils.closeQuietly(fos); } }