List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:com.fengduo.bee.commons.util.DateViewTools.java
public static boolean isSameDay(Calendar cal1, Calendar cal2) { if (cal1 == null || cal2 == null) { return false; }//from ww w .j av a2s.c o m return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); }
From source file:org.openmrs.module.dominicamodule.web.controller.EditPatientDrugsPortletController.java
Date getExpireDateFromDuration(Date date, DrugOrderExtension doe) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//from ww w .j ava 2 s . c o m switch (DurationUnit.values()[doe.getDurationUnit()]) { case hours: cal.add(Calendar.HOUR, doe.getDuration()); break; case days: cal.add(Calendar.DAY_OF_YEAR, doe.getDuration()); break; case weeks: cal.add(Calendar.WEEK_OF_YEAR, doe.getDuration()); break; case months: cal.add(Calendar.MONTH, doe.getDuration()); break; case years: cal.add(Calendar.YEAR, doe.getDuration()); break; } return cal.getTime(); }
From source file:Main.java
/** * Returns the number of millis of a datefield, if this is a constant value * //from w w w. jav a2 s . co m * @param unit A Calendar field which is a valid unit for a fragment * @return number of millis * @throws IllegalArgumentException if date can't be represented in millisenconds * @since 2.4 */ private static long getMillisPerUnit(int unit) { long result = Long.MAX_VALUE; switch (unit) { case Calendar.DAY_OF_YEAR: case Calendar.DATE: result = MILLIS_PER_DAY; break; case Calendar.HOUR_OF_DAY: result = MILLIS_PER_HOUR; break; case Calendar.MINUTE: result = MILLIS_PER_MINUTE; break; case Calendar.SECOND: result = MILLIS_PER_SECOND; break; case Calendar.MILLISECOND: result = 1; break; default: throw new IllegalArgumentException("The unit " + unit + " cannot be represented is milleseconds"); } return result; }
From source file:com.fengduo.bee.commons.util.DateViewTools.java
public static boolean isSameHour(Calendar cal1, Calendar cal2) { return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.MONTH) == cal2.get(Calendar.MONTH) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) && cal1.get(Calendar.HOUR_OF_DAY) == cal2.get(Calendar.HOUR_OF_DAY); }
From source file:es.alvsanand.webpage.services.cms.CmsServiceImpl.java
private Map<Date, Map<Date, Map<Date, List<Article>>>> convertListToDateTree(List<Article> articles) { Map<Date, Map<Date, Map<Date, List<Article>>>> articleTree = new TreeMap<Date, Map<Date, Map<Date, List<Article>>>>(); if (articles != null && articles.size() > 0) { for (Article article : articles) { Calendar calendar = GregorianCalendar.getInstance(); calendar.setTime(article.getDate()); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 1); Date dayDate = new Date(calendar.getTimeInMillis()); calendar.set(Calendar.DAY_OF_MONTH, 1); Date monthDate = new Date(calendar.getTimeInMillis()); calendar.set(Calendar.DAY_OF_YEAR, 1); Date yearDate = new Date(calendar.getTimeInMillis()); Map<Date, Map<Date, List<Article>>> yearMap = articleTree.get(yearDate); if (yearMap == null) { yearMap = new TreeMap<Date, Map<Date, List<Article>>>(); articleTree.put(yearDate, yearMap); }//from www . j ava2 s . c o m Map<Date, List<Article>> monthMap = yearMap.get(monthDate); if (monthMap == null) { monthMap = new TreeMap<Date, List<Article>>(); yearMap.put(monthDate, monthMap); } List<Article> dayList = monthMap.get(dayDate); if (dayList == null) { dayList = new ArrayList<Article>(); monthMap.put(dayDate, dayList); } dayList.add(article); } } return articleTree; }
From source file:com.webbfontaine.valuewebb.model.util.Utils.java
public static int daysNumberFromYearBeginning(Calendar cal) { return cal.get(Calendar.DAY_OF_YEAR); }
From source file:br.com.hslife.orcamento.controller.LancamentoContaController.java
public void findByPeriodo() { try {//from w w w .j av a 2 s . c o m if (criterioBusca.getConta() == null) { warnMessage("Informe a conta!"); return; } criterioBusca.limparCriterios(); // Busca o fechamento do perodo anterior FechamentoPeriodo fechamentoAnterior; if (fechamentoPeriodo != null) fechamentoAnterior = fechamentoPeriodoService.buscarFechamentoPeriodoAnterior(fechamentoPeriodo); else fechamentoAnterior = fechamentoPeriodoService.buscarUltimoFechamentoConta(criterioBusca.getConta()); // Determina a data de incio do perodo if (fechamentoAnterior == null) { criterioBusca.setDataInicio(criterioBusca.getConta().getDataAbertura()); criterioBusca.setDataFim(new Date()); } else { Calendar temp = Calendar.getInstance(); temp.setTime(fechamentoAnterior.getData()); temp.add(Calendar.DAY_OF_YEAR, 1); criterioBusca.setDataInicio(temp.getTime()); } // Determina a data de fim do perodo if (fechamentoPeriodo == null) { criterioBusca.setDataFim(new Date()); } else { criterioBusca.setDataFim(fechamentoPeriodo.getData()); } // Correo do problema da dataIncio ser maior que dataFim if (criterioBusca.getDataInicio().after(criterioBusca.getDataFim())) { criterioBusca.setDataFim(null); } criterioBusca.setLimiteResultado(getOpcoesSistema().getLimiteQuantidadeRegistros()); listEntity = getService().buscarPorCriterioBusca(criterioBusca); } catch (ValidationException | BusinessException be) { errorMessage(be.getMessage()); } }
From source file:com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy.java
@Override public <I extends TopLevelItem> Collection<I> orphanedItems(ComputedFolder<I> owner, Collection<I> orphaned, TaskListener listener) throws IOException, InterruptedException { List<I> toRemove = new ArrayList<I>(); if (pruneDeadBranches && (numToKeep != -1 || daysToKeep != -1)) { listener.getLogger().printf("Evaluating orphaned items in %s%n", owner.getFullDisplayName()); List<I> candidates = new ArrayList<I>(orphaned); Collections.sort(candidates, new Comparator<I>() { @Override/*from w w w . ja v a2 s .c o m*/ public int compare(I i1, I i2) { // most recent build first long ms1 = lastBuildTime(i1); long ms2 = lastBuildTime(i2); return (ms2 < ms1) ? -1 : ((ms2 == ms1) ? 0 : 1); // TODO Java 7+: Long.compare(ms2, ms1); } }); CANDIDATES: for (Iterator<I> iterator = candidates.iterator(); iterator.hasNext();) { I item = iterator.next(); for (Job<?, ?> job : item.getAllJobs()) { // Enumerating all builds is inefficient. But we will most likely delete this job anyway, // which will have a cost proportional to the number of builds just to delete those files. for (Run<?, ?> build : job.getBuilds()) { if (build.isBuilding()) { listener.getLogger().printf("Will not remove %s as %s is still in progress%n", item.getDisplayName(), build.getFullDisplayName()); iterator.remove(); continue CANDIDATES; } String whyKeepLog = build.getWhyKeepLog(); if (whyKeepLog != null) { listener.getLogger().printf( "Will not remove %s as %s is marked to not be removed: %s%n", item.getDisplayName(), build.getFullDisplayName(), whyKeepLog); iterator.remove(); continue CANDIDATES; } } } } int count = 0; if (numToKeep != -1) { for (Iterator<I> iterator = candidates.iterator(); iterator.hasNext();) { I item = iterator.next(); count++; if (count <= numToKeep) { listener.getLogger().printf("Will not remove %s as it is only #%d in the list%n", item.getDisplayName(), count); continue; } listener.getLogger().printf("Will remove %s as it is #%d in the list%n", item.getDisplayName(), count); toRemove.add(item); iterator.remove(); } } if (daysToKeep != -1) { Calendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_YEAR, -daysToKeep); for (I item : candidates) { if (lastBuildTime(item) > cal.getTimeInMillis()) { listener.getLogger().printf("Will not remove %s because it is new%n", item.getDisplayName()); continue; } listener.getLogger().printf("Will remove %s as it is too old%n", item.getDisplayName()); toRemove.add(item); } } } return toRemove; }
From source file:net.solarnetwork.node.power.enasolar.ws.EnaSolarXMLDatumDataSource.java
private boolean isSampleOnSameDay(final Date sampleDate) { final Date lastKnownDate = (sample != null ? sample.getCreated() : null); if (sampleDate == null || lastKnownDate == null) { return false; }//from w w w . j a va 2s . c om final Calendar sampleCal = Calendar.getInstance(); sampleCal.setTime(sampleDate); final Calendar lastKnownCal = Calendar.getInstance(); lastKnownCal.setTime(lastKnownDate); return (sampleCal.get(Calendar.DAY_OF_YEAR) == lastKnownCal.get(Calendar.DAY_OF_YEAR) && sampleCal.get(Calendar.YEAR) == lastKnownCal.get(Calendar.YEAR)); }
From source file:org.auraframework.integration.test.http.AuraResourceServletHttpTest.java
/** * GET with If-Modified-Since header 45 days from now, will return 304 with empty body. *//*from w w w .jav a 2 s . co m*/ @AuraTestLabels("auraSanity") @Test public void testGetWithIfModifiedSinceNew() throws Exception { String url = "/l/" + AuraTextUtil.urlencode(getSimpleContext(Format.JS, false)) + "/app.js"; Calendar stamp = Calendar.getInstance(); stamp.add(Calendar.DAY_OF_YEAR, 45); Header[] headers = new Header[] { new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE, new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(stamp.getTime())) }; HttpGet get = obtainGetMethod(url, headers); HttpResponse httpResponse = perform(get); int statusCode = getStatusCode(httpResponse); String response = getResponseBody(httpResponse); get.releaseConnection(); assertEquals(HttpStatus.SC_NOT_MODIFIED, statusCode); assertNull(response); }