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.dajodi.scandic.Util.java
public static int daysBetween(Date before, Date after) { if (before == null || after == null) { return UNKNOWN_NIGHTS; }/*from w w w .ja v a2 s. c om*/ if (before.after(after)) { return UNKNOWN_NIGHTS; } // Creates two calendars instances Calendar cal1 = Calendar.getInstance(); cal1.setTime(before); int day1 = cal1.get(Calendar.DAY_OF_YEAR); Calendar cal2 = Calendar.getInstance(); cal2.setTime(after); int day2 = cal2.get(Calendar.DAY_OF_YEAR); long diffDays = UNKNOWN_NIGHTS; if (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)) { diffDays = Math.abs(day2 - day1); } // Calculate difference in days return (int) diffDays; }
From source file:net.sourceforge.subsonic.controller.ShareSettingsController.java
private Date parseExpireIn(String expireIn) { int days = Integer.parseInt(expireIn); if (days == 0) { return null; }/* ww w . j a v a 2 s .c o m*/ Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, days); return calendar.getTime(); }
From source file:com.acmeair.jpa.service.CustomerServiceImpl.java
@Transactional(propagation = Propagation.REQUIRED) @Override//from ww w. j av a 2 s .c o m public CustomerSession createSession(String customerId) { try { String sessionId = keyGenerator.generate().toString(); Date now = new Date(); Calendar c = Calendar.getInstance(); c.setTime(now); c.add(Calendar.DAY_OF_YEAR, DAYS_TO_ALLOW_SESSION); Date expiration = c.getTime(); CustomerSession cSession = new CustomerSession(sessionId, customerId, now, expiration); em.persist(cSession); return cSession; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.davidmendoza.esu.service.impl.ArticuloServiceImpl.java
@Override @SuppressWarnings("unchecked") public List<ReporteArticulo> articulosDelMes(Date date) { List<Map<String, Object>> x = publicacionRepository.todas(); Map<Long, Object> publicaciones = new HashMap<>(); Long articuloId = 0l;/*from w ww . ja va 2s . co m*/ for (Map<String, Object> a : x) { if (!Objects.equals(articuloId, a.get("articuloId"))) { articuloId = (Long) a.get("articuloId"); if (a.get("estatus").equals("PUBLICADO") && (a.get("tipo").equals("dialoga") || a.get("tipo").equals("comunica"))) { publicaciones.put(articuloId, a); } } } Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DAY_OF_YEAR, -1); Date fecha1 = cal.getTime(); List<Map<String, Object>> lista = articuloRepository.articulosDelDia(fecha1, date); log.debug("Lista: {}", lista.size()); List<ReporteArticulo> articulos = new ArrayList<>(); Map<Long, ReporteArticulo> mapa = new HashMap<>(); for (Map<String, Object> a : lista) { log.debug("Agregando {}", a.get("articulo")); Map<String, Object> c = (Map) publicaciones.get((Long) a.get("articuloId")); if (c != null) { ReporteArticulo b = new ReporteArticulo((Long) a.get("articuloId"), (String) a.get("articulo"), (String) a.get("nombre") + " " + (String) a.get("apellido"), (Integer) a.get("vistas")); b.setUrl("http://escuelasabaticauniversitaria.org/" + (c.get("tipo").equals("dialoga") ? "profundiza/" : "comparte/") + c.get("anio") + "/" + c.get("trimestre") + "/" + c.get("leccion") + "/" + c.get("tema")); articulos.add(b); mapa.put(b.getArticuloId(), b); } } cal.setTime(date); cal.add(Calendar.MONTH, -1); Date fecha2 = cal.getTime(); cal.add(Calendar.DAY_OF_YEAR, -1); fecha1 = cal.getTime(); lista = articuloRepository.articulosDelDia(fecha1, fecha2); for (Map<String, Object> a : lista) { if (publicaciones.get((Long) a.get("articuloId")) != null) { ReporteArticulo b = mapa.get((Long) a.get("articuloId")); if (b != null) { b.setVistas2((Integer) a.get("vistas")); } } } cal.setTime(date); cal.add(Calendar.MONTH, -2); fecha2 = cal.getTime(); cal.add(Calendar.DAY_OF_YEAR, -1); fecha1 = cal.getTime(); lista = articuloRepository.articulosDelDia(fecha1, fecha2); for (Map<String, Object> a : lista) { if (publicaciones.get((Long) a.get("articuloId")) != null) { ReporteArticulo b = mapa.get((Long) a.get("articuloId")); if (b != null) { b.setVistas3((Integer) a.get("vistas")); } } } cal.setTime(date); cal.add(Calendar.MONTH, -3); fecha2 = cal.getTime(); cal.add(Calendar.DAY_OF_YEAR, -1); fecha1 = cal.getTime(); lista = articuloRepository.articulosDelDia(fecha1, fecha2); for (Map<String, Object> a : lista) { if (publicaciones.get((Long) a.get("articuloId")) != null) { ReporteArticulo b = mapa.get((Long) a.get("articuloId")); if (b != null) { b.setVistas4((Integer) a.get("vistas")); } } } return articulos; }
From source file:edu.harvard.iq.dvn.core.index.IndexServiceBean.java
public void createIndexTimer() { for (Iterator it = timerService.getTimers().iterator(); it.hasNext();) { Timer timer = (Timer) it.next(); if (timer.getInfo().equals(INDEX_TIMER)) { logger.info("Cannot create IndexTimer, timer already exists."); logger.info("IndexTimer next timeout is " + timer.getNextTimeout()); return; }/*from ww w . j a v a 2 s .co m*/ } Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 1); logger.log(Level.INFO, "Indexer timer set for " + cal.getTime()); Date initialExpiration = cal.getTime(); // First timeout is 1:00 AM of next day long intervalDuration = 1000 * 60 * 60 * 24; // repeat every 24 hours timerService.createTimer(initialExpiration, intervalDuration, INDEX_TIMER); }
From source file:com.netflix.genie.web.tasks.leader.DatabaseCleanupTaskUnitTests.java
/** * Make sure the run method passes in the expected date. *//*from w w w .j av a2 s. c o m*/ @Test public void canRun() { final int days = 5; final int negativeDays = -1 * days; final int pageSize = 10; final int maxDeleted = 10_000; Mockito.when(this.cleanupProperties.getRetention()).thenReturn(days).thenReturn(negativeDays); Mockito.when(this.cleanupProperties.getPageSize()).thenReturn(pageSize); Mockito.when(this.cleanupProperties.getMaxDeletedPerTransaction()).thenReturn(maxDeleted); final ArgumentCaptor<Date> argument = ArgumentCaptor.forClass(Date.class); final long deletedCount1 = 6L; final long deletedCount2 = 18L; final long deletedCount3 = 2L; Mockito.when(this.jobPersistenceService.deleteBatchOfJobsCreatedBeforeDate(Mockito.any(Date.class), Mockito.anyInt(), Mockito.anyInt())).thenReturn(deletedCount1).thenReturn(0L) .thenReturn(deletedCount2).thenReturn(deletedCount3).thenReturn(0L); // The multiple calendar instances are to protect against running this test when the day flips final Calendar before = Calendar.getInstance(JobConstants.UTC); this.task.run(); Assert.assertThat(this.numDeletedJobs.get(), Matchers.is(deletedCount1)); Mockito.verify(this.deletionTimerId, Mockito.times(1)).withTags(MetricsUtils.newSuccessTagsMap()); this.task.run(); final Calendar after = Calendar.getInstance(JobConstants.UTC); Assert.assertThat(this.numDeletedJobs.get(), Matchers.is(deletedCount2 + deletedCount3)); Mockito.verify(this.deletionTimerId, Mockito.times(2)).withTags(MetricsUtils.newSuccessTagsMap()); Mockito.verify(this.deletionTimer, Mockito.times(2)).record(Mockito.anyLong(), Mockito.eq(TimeUnit.NANOSECONDS)); if (before.get(Calendar.DAY_OF_YEAR) == after.get(Calendar.DAY_OF_YEAR)) { Mockito.verify(this.jobPersistenceService, Mockito.times(5)).deleteBatchOfJobsCreatedBeforeDate( argument.capture(), Mockito.eq(maxDeleted), Mockito.eq(pageSize)); final Calendar date = Calendar.getInstance(JobConstants.UTC); date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); date.add(Calendar.DAY_OF_YEAR, negativeDays); Assert.assertThat(argument.getAllValues().get(0), Matchers.is(date.getTime())); Assert.assertThat(argument.getAllValues().get(1), Matchers.is(date.getTime())); } }
From source file:net.kourlas.voipms_sms.Api.java
public void updateSmses(boolean silent) { if (preferences.getEmail().equals("")) { if (!silent) { Toast.makeText(context.getApplicationContext(), "Update SMSes: VoIP.ms portal email not set", Toast.LENGTH_SHORT).show(); }/*from w w w . j a v a 2 s .c o m*/ } else if (preferences.getPassword().equals("")) { if (!silent) { Toast.makeText(context.getApplicationContext(), "Update SMSes: VoIP.ms API password not set", Toast.LENGTH_SHORT).show(); } } else if (preferences.getDid().equals("")) { if (!silent) { Toast.makeText(context.getApplicationContext(), "Update SMSes: DID not set", Toast.LENGTH_SHORT) .show(); } } else if (isNetworkConnectionAvailable()) { Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.add(Calendar.DAY_OF_YEAR, -preferences.getDaysToSync()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); try { String voipUrl = "https://www.voip.ms/api/v1/rest.php?" + "&" + "api_username=" + URLEncoder.encode(preferences.getEmail(), "UTF-8") + "&" + "api_password=" + URLEncoder.encode(preferences.getPassword(), "UTF-8") + "&" + "method=getSMS" + "&" + "did=" + URLEncoder.encode(preferences.getDid(), "UTF-8") + "&" + "limit=" + URLEncoder.encode("1000000", "UTF-8") + "&" + "from=" + URLEncoder.encode(sdf.format(calendar.getTime()), "UTF-8") + "&" + "to=" + URLEncoder.encode(sdf.format(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime()), "UTF-8") + "&" + "timezone=-1"; new UpdateSmsesAsyncTask().execute(voipUrl, Boolean.toString(silent)); return; } catch (UnsupportedEncodingException ex) { if (!silent) { Toast.makeText(context.getApplicationContext(), "Update SMSes: Email address or password contains invalid characters " + "(UnsupportedEncodingException)", Toast.LENGTH_SHORT).show(); } } } else { if (!silent) { Toast.makeText(context.getApplicationContext(), "Update SMSes: Network connection unavailable", Toast.LENGTH_SHORT).show(); } } if (context instanceof ConversationsActivity) { SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) ((ConversationsActivity) context) .findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setRefreshing(false); } else if (context instanceof ConversationActivity) { ProgressBar progressBar = (ProgressBar) ((ConversationActivity) context) .findViewById(R.id.progress_bar); progressBar.setVisibility(View.INVISIBLE); } }
From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java
static Date addDays(Date date, int numberOfDays) { final Calendar calendar = Calendar.getInstance(); calendar.setTime(date);/*from w w w .j a v a 2 s .co m*/ calendar.add(Calendar.DAY_OF_YEAR, numberOfDays); return calendar.getTime(); }
From source file:it.infn.ct.security.utilities.LDAPCleaner.java
private void stopUsers() { _log.info("Disable users who do not confirm the account extension"); Session session = factory.openSession(); session.beginTransaction();/* ww w . j ava2 s.c o m*/ Calendar cal = GregorianCalendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Calendar calEnd = GregorianCalendar.getInstance(); calEnd.setTime(cal.getTime()); calEnd.add(Calendar.DAY_OF_YEAR, 1); Session ses = factory.openSession(); List lstUserUpdates = ses.createCriteria(UserConfirmUpdate.class) .add(Restrictions.between("timelimit", cal.getTime(), calEnd.getTime())) .add(Restrictions.eq("updated", Boolean.FALSE)).list(); for (UserConfirmUpdate ucu : (List<UserConfirmUpdate>) lstUserUpdates) { UserRequest ur = LDAPUtils.getUser(ucu.getUsername()); LDAPUtils.disableUser(ucu.getUsername()); sendUserRemainder(ur, 0); } ses.close(); session.getTransaction().commit(); session.close(); }
From source file:com.lm.lic.manager.util.GenUtil.java
public static Timestamp timeNowPlusDaysAhead(int daysAhead) { Calendar cal = Calendar.getInstance(); int numDays = daysAhead + cal.get(Calendar.DAY_OF_YEAR); cal.set(Calendar.DAY_OF_YEAR, numDays); Timestamp ts = new Timestamp(cal.getTimeInMillis()); return ts;//w ww . java2s .co m }