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.metasoft.claim.service.impl.claim.ClaimServiceImpl.java
@Override public ClaimSearchResultVoPaging searchPaging(String paramJobDateStart, String paramJobDateEnd, String paramPartyInsuranceId, String paramTotalDayOfMaturity, String paramClaimTypeId, String paramClaimNumber, String paramJobStatusId, int start, int length, SecUser user) { Date jobDateStart = null;// w ww. j a v a2 s .co m Date jobDateEnd = null; StdInsurance partyInsurance = null; Date maturityDate = null; ClaimType claimType = null; JobStatus jobStatus = null; if (StringUtils.isNotBlank(paramJobDateStart)) { jobDateStart = DateToolsUtil.convertStringToDate(paramJobDateStart, DateToolsUtil.LOCALE_TH); } if (StringUtils.isNotBlank(paramJobDateEnd)) { jobDateEnd = DateToolsUtil.convertStringToDate(paramJobDateEnd, DateToolsUtil.LOCALE_TH); } if (StringUtils.isNotBlank(paramPartyInsuranceId)) { partyInsurance = insuranceService.findById(Integer.parseInt(paramPartyInsuranceId)); } if (StringUtils.isNotBlank(paramTotalDayOfMaturity)) { int totalDayOfMaturity = NumberToolsUtil.parseToInteger(paramTotalDayOfMaturity); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, +totalDayOfMaturity); maturityDate = cal.getTime(); } if (StringUtils.isNotBlank(paramClaimTypeId)) { claimType = ClaimType.getById(Integer.parseInt(paramClaimTypeId)); } if (StringUtils.isNotBlank(paramJobStatusId)) { jobStatus = JobStatus.getById(Integer.parseInt(paramJobStatusId)); } return searchPaging(jobDateStart, jobDateEnd, partyInsurance, maturityDate, claimType, paramClaimNumber, jobStatus, start, length, user); }
From source file:com.intuit.tank.harness.functions.JexlDateFunctions.java
/** * Get the date x days from now.// w w w. jav a 2s. co m * * @param days * The number of days to add (negative number to remove) * @param format * The format of the response (MM-dd-yyyy, MMddyyyy, etc) * @return The new date */ public String addDays(Object odays, String format) { int days = FunctionHandler.getInt(odays); Calendar now = Calendar.getInstance(); now.add(Calendar.DAY_OF_YEAR, days); DateFormat formatter = getFormatter(format); return formatter.format(now.getTime()); }
From source file:com.fb.audiencenetwork.scrollapp.NasaRequester.java
public void getPost() throws IOException { String date = mDateFormat.format(mCalendar.getTime()); String urlRequest = BASE_URL + DATE_PARAMETER + date + API_KEY_PARAMETER + mContext.getString(R.string.api_key); Request request = new Request.Builder().url(urlRequest).build(); mLoadingData = true;/*from ww w . ja va 2s . c o m*/ mClient.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { mLoadingData = false; e.printStackTrace(); } @Override public void onResponse(Call call, Response response) throws IOException { try { JSONObject photoJSON = new JSONObject(response.body().string()); mCalendar.add(Calendar.DAY_OF_YEAR, -1); if (!photoJSON.getString(MEDIA_TYPE_KEY).equals(MEDIA_TYPE_VIDEO_VALUE)) { NasaPost post = new NasaPost(photoJSON); mResponseListener.receivedPost(post); mLoadingData = false; } else { getPost(); } } catch (JSONException e) { mLoadingData = false; e.printStackTrace(); } } }); }
From source file:ai.ilikeplaces.logic.sits9.SubscriberNotifications.java
@Override public void startTimer() { final int timeout = TGIF_TIMING == 0 ? 7 //Days of Week * 24 //Hour of Day * 60 //Minutes of Hour * 60 //Seconds of Minute * 1000 //Milliseconds of Second : TGIF_TIMING;//from ww w . ja v a2s .co m final SmartLogger sl = SmartLogger.start(Loggers.LEVEL.INFO, Loggers.CODE_MEMC + "HELLO, STARTING " + this.getClass().getSimpleName() + " TIMER WITH TIMER INTERVAL:" + timeout, 60000, null, true); final Calendar _calendar = Calendar.getInstance(); final int todayDay = _calendar.get(Calendar.DAY_OF_WEEK); if (todayDay != Calendar.FRIDAY) { _calendar.add(Calendar.DAY_OF_YEAR, (Calendar.SATURDAY - todayDay + 6) % 7); } if (TGIF_TIMING == 0) { final Date _time = _calendar.getTime(); timerService.createTimer(_time, timeout, null); String format = new SimpleDateFormat("yyyy/MM/dd").format(_time); sl.appendToLogMSG("Starting timer on " + format); } else { timerService.createTimer(0, timeout, null); } if (TGIF_ON_STARTUP == 1) { final Calendar now = Calendar.getInstance(); now.add(Calendar.SECOND, 30); timerService.createTimer(now.getTime(), timeout, null); } sl.complete(Loggers.LEVEL.INFO, Loggers.DONE); }
From source file:se.ivankrizsan.messagecowboy.services.taskexecutionstatus.TaskExecutionStatusServiceTest.java
/** * Performs test preparations.//from www . ja va 2 s . c om * * @throws Exception If error occurs setting up for the test. */ @Before public void setUp() throws Exception { Calendar theCalendar = Calendar.getInstance(); MessageCowboySchedulableTaskConfig theTaskConfiguration = AbstractTestBaseClass .createOneTaskConfiguration(); /* Save name in order to query for the task configuration later. */ mTestTaskConfigurationName = theTaskConfiguration.getName(); /* Create an execution status that is five days old. */ theCalendar.add(Calendar.DAY_OF_YEAR, -5); TaskExecutionStatus theTaskExecutionStatus = new TaskExecutionStatusSuccess(theTaskConfiguration, "Success 1", theCalendar.getTime()); theTaskConfiguration.addTaskExecutionStatus(theTaskExecutionStatus); /* Create an execution status that is two days old. */ theCalendar = Calendar.getInstance(); theCalendar.add(Calendar.DAY_OF_YEAR, -2); theTaskExecutionStatus = new TaskExecutionStatusError(theTaskConfiguration, "Failure 1", theCalendar.getTime()); theTaskConfiguration.addTaskExecutionStatus(theTaskExecutionStatus); /* Create an execution status for an execution that just finished. */ theCalendar = Calendar.getInstance(); theTaskExecutionStatus = new TaskExecutionStatusNoMessageReceived(theTaskConfiguration, "No Msg Received 1", theCalendar.getTime()); theTaskConfiguration.addTaskExecutionStatus(theTaskExecutionStatus); mTaskConfigurationService.save(theTaskConfiguration); }
From source file:nz.net.orcon.kanban.tools.DateInterpreterTest.java
@Test public void testConversion_pastDate() throws Exception { final Calendar calFutureDate = Calendar.getInstance(); calFutureDate.add(Calendar.DAY_OF_YEAR, -3); int dayOfMonth = calFutureDate.get(Calendar.DAY_OF_MONTH); int month = calFutureDate.get(Calendar.MONTH); int year = calFutureDate.get(Calendar.YEAR); final Date interpretDate = dateInterpreter.interpretDateFormula("today-3days"); Calendar calInterpreted = Calendar.getInstance(); calInterpreted.setTime(interpretDate); Assert.assertEquals(dayOfMonth, calInterpreted.get(Calendar.DAY_OF_MONTH)); Assert.assertEquals(month, calInterpreted.get(Calendar.MONTH)); Assert.assertEquals(year, calInterpreted.get(Calendar.YEAR)); }
From source file:com.pearson.eidetic.driver.threads.MonitorSnapshotVolumeTime.java
@Override public void run() { Calendar calendar_int = Calendar.getInstance(); //0-365//from w w w .j av a 2s . c o m today_ = calendar_int.get(Calendar.DAY_OF_YEAR); ConcurrentHashMap<Region, ArrayList<Volume>> localVolumeTime; localVolumeTime = awsAccount_.getVolumeTime_Copy(); for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) { Region region = entry.getKey(); splitFactorDay_.put(region, 10); HashSet<Date> newHashSet = new HashSet<>(); didMySnapshotDay_.put(entry.getKey(), newHashSet); } addAlreadyDoneTodaySnapshots(localVolumeTime); while (true) { try { //Reset my stuff if (isItTomorrow(today_)) { calendar_int = Calendar.getInstance(); today_ = calendar_int.get(Calendar.DAY_OF_YEAR); resetDidMySnapshotDay(); } localVolumeTime = awsAccount_.getVolumeTime_Copy(); for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) { Region region = entry.getKey(); if (localVolumeTime.get(region).isEmpty()) { continue; } timeDay_.put(region, extractRunAt(localVolumeTime.get(region))); } for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) { Region region = entry.getKey(); if (localVolumeTime.get(region).isEmpty()) { continue; } timeDay_.get(region).keySet().removeAll(didMySnapshotDay_.get(region)); Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); now = dayFormat_.parse(dayFormat_.format(now)); List<Date> lessThanNow = findLessThanNow(timeDay_.get(region).keySet(), now); if (!lessThanNow.isEmpty()) { for (Date date : lessThanNow) { ArrayList<Volume> volumes = timeDay_.get(region).get(date); List<List<Volume>> listOfLists = Lists.partition(volumes, splitFactorDay_.get(region)); if (localVolumeTimeListDay_.get(region) == null || localVolumeTimeListDay_.get(region).isEmpty()) { localVolumeTimeListDay_.put(region, listsToArrayLists(listOfLists)); } else { try { localVolumeTimeListDay_.get(region).add(listsToArrayLists(listOfLists).get(0)); } catch (Exception e) { } } ArrayList<SnapshotVolumeTime> threads = new ArrayList<>(); for (ArrayList<Volume> vols : listsToArrayLists(listOfLists)) { threads.add(new SnapshotVolumeTime(awsAccount_.getAwsAccessKeyId(), awsAccount_.getAwsSecretKey(), awsAccount_.getUniqueAwsAccountIdentifier(), awsAccount_.getMaxApiRequestsPerSecond(), ApplicationConfiguration.getAwsCallRetryAttempts(), region, vols)); } didMySnapshotDay_.get(region).add(date); EideticSubThreads_.put(region, threads); } } } //localVolumeTimeListDay now has hashmaps of regions with keys of arrays of arrays of volumes to take snapshots of. HashMap<Region, Integer> secsSlept = new HashMap<>(); HashMap<Region, Boolean> allDead = new HashMap<>(); for (Map.Entry<Region, ArrayList<Volume>> entry : localVolumeTime.entrySet()) { Region region = entry.getKey(); if (localVolumeTimeListDay_.get(region) == null || localVolumeTimeListDay_.get(region).isEmpty()) { continue; } //Initializing content secsSlept.put(region, 0); //Initializing content allDead.put(region, false); Threads.threadExecutorFixedPool(EideticSubThreads_.get(region), splitFactorDay_.get(region), 300, TimeUnit.MINUTES); } //LETS SEE IF THEY'RE DEAD Boolean ejection = false; Boolean theyreDead; while (true) { for (Map.Entry<Region, ArrayList<SnapshotVolumeTime>> entry : EideticSubThreads_.entrySet()) { Region region = entry.getKey(); if (areAllThreadsDead(EideticSubThreads_.get(region))) { allDead.put(region, true); } else { secsSlept.replace(region, secsSlept.get(region), secsSlept.get(region) + 1); if (secsSlept.get(region) > 1800) { splitFactorDay_.replace(region, splitFactorDay_.get(region), splitFactorDay_.get(region) + 1); logger.info( "Event=\"increasing_splitFactor\", Monitor=\"SnapshotVolumeTime\", splitFactor=\"" + Integer.toString(splitFactorDay_.get(region)) + "\", VolumeTimeSize=\"" + Integer.toString(localVolumeTime.get(region).size()) + "\""); ejection = true; break; } } } //I dont like this theyreDead = true; for (Map.Entry<Region, ArrayList<SnapshotVolumeTime>> entry : EideticSubThreads_.entrySet()) { Region region = entry.getKey(); //If any of them have false if (!allDead.get(region)) { theyreDead = false; } } if (ejection || theyreDead) { break; } Threads.sleepSeconds(1); } //See if decrease splitfactor for (Map.Entry<Region, ArrayList<SnapshotVolumeTime>> entry : EideticSubThreads_.entrySet()) { Region region = entry.getKey(); int timeRemaining = 1800 - secsSlept.get(region); if ((splitFactorDay_.get(region) > 5) & (timeRemaining > 60)) { splitFactorDay_.replace(region, splitFactorDay_.get(region), splitFactorDay_.get(region) - 1); logger.info("awsAccountNickname=\"" + awsAccount_.getUniqueAwsAccountIdentifier() + "\",Event=\"decreasing_splitFactor\", Monitor=\"SnapshotVolumeNoTime\", splitFactor=\"" + Integer.toString(splitFactorDay_.get(region)) + "\", VolumeNoTimeSize=\"" + Integer.toString(localVolumeTime.get(region).size()) + "\""); } } localVolumeTimeListDay_.clear(); EideticSubThreads_.clear(); Threads.sleepSeconds(30); } catch (Exception e) { logger.error("awsAccountNickname=\"" + awsAccount_.getUniqueAwsAccountIdentifier() + "\",Error=\"MonitorSnapshotVolumeTimeFailure\", stacktrace=\"" + e.toString() + System.lineSeparator() + StackTrace.getStringFromStackTrace(e) + "\""); } } }
From source file:com.netflix.genie.web.tasks.job.JobMonitoringCoordinatorUnitTests.java
/** * Setup for the tests.// w w w . j a v a 2 s. c o m * * @throws IOException on error */ @Before public void setup() throws IOException { final Calendar cal = Calendar.getInstance(JobConstants.UTC); cal.add(Calendar.DAY_OF_YEAR, 1); this.tomorrow = cal.getTime(); this.jobSearchService = Mockito.mock(JobSearchService.class); this.jobSubmitterService = Mockito.mock(JobSubmitterService.class); final Executor executor = Mockito.mock(Executor.class); this.scheduler = Mockito.mock(TaskScheduler.class); this.eventMulticaster = Mockito.mock(ApplicationEventMulticaster.class); final Registry registry = Mockito.mock(Registry.class); this.unableToCancel = Mockito.mock(Counter.class); Mockito.when(registry.counter(Mockito.anyString())).thenReturn(this.unableToCancel); final File jobsFile = this.folder.newFolder(); final Resource jobsDir = Mockito.mock(Resource.class); Mockito.when(jobsDir.getFile()).thenReturn(jobsFile); this.coordinator = new JobMonitoringCoordinator(HOSTNAME, this.jobSearchService, Mockito.mock(ApplicationEventPublisher.class), this.eventMulticaster, this.scheduler, executor, registry, jobsDir, new JobsProperties(), jobSubmitterService); }
From source file:es.udc.fic.test.model.CerrarMangaTest.java
@Test public void cerrarMangaTRealSinPenal() { //Creamos una sola regata con la instancia de todos los objetos en memoria Regata regata = new Regata(); regata.setNombre("Mock Regata"); regata.setDescripcion("Mock Desc"); regataDao.save(regata);/* w w w. j a v a 2 s . com*/ Tipo tipoVLigera = new Tipo("Vela ligera", "Desc Vela ligera", true); tipoDao.save(tipoVLigera); Tipo tipoLanchas = new Tipo("Lanchas", "Desc Lanchas", true); tipoDao.save(tipoLanchas); Barco b1 = new Barco(204566, "Juan Sebastian El Cano", tipoVLigera, null, "Lagoon 421"); inscripcionService.inscribir(regata, b1, "Iago Surez"); Barco b2 = new Barco(199012, "El Holandes Errante", tipoVLigera, null, "SWAN 66 FD"); inscripcionService.inscribir(regata, b2, "Samu Paredes"); Barco b3 = new Barco(201402, "La Perla Negra", tipoVLigera, null, "X6"); inscripcionService.inscribir(regata, b3, "Adrian Pallas"); //Ponemos otro tipo para ver como funciona la clasificacion Barco b4 = new Barco(206745, "Apolo", tipoLanchas, null, "Laser Radial"); inscripcionService.inscribir(regata, b4, "Diego Bascoy"); Calendar dia1 = Calendar.getInstance(); dia1.add(Calendar.DAY_OF_YEAR, -18); Calendar dia2 = Calendar.getInstance(); dia2.add(Calendar.DAY_OF_YEAR, -18); dia2.add(Calendar.HOUR, 2); Calendar dia3 = Calendar.getInstance(); dia3.add(Calendar.DAY_OF_YEAR, -17); Manga manga1 = new Manga(dia1, regata, null, 100); List<Posicion> posManga1 = new ArrayList<Posicion>(); //Velas Ligeras //Primero -> Puntos 1 posManga1.add(new Posicion((long) 3200, Posicion.Penalizacion.NAN, manga1, b1, (long) 0)); //Segundo-> Puntos 2 posManga1.add(new Posicion((long) 3300, Posicion.Penalizacion.NAN, manga1, b2, (long) 0)); //Tercero -> Puntos 3 posManga1.add(new Posicion((long) 3400, Posicion.Penalizacion.NAN, manga1, b3, (long) 0)); //Lanchas //Primero -> Puntos 1 posManga1.add(new Posicion((long) 3300, Posicion.Penalizacion.NAN, manga1, b4, (long) 0)); manga1.setPosiciones(posManga1); regata.addManga(manga1); mangaService.cerrarYGuardarManga(manga1); //Comprobamos que todas las posiciones tienen puntos mayores que 0 for (Posicion p : manga1.getPosiciones()) { assertTrue(p.getPuntos() > 0); } //Comprobamos que los puntos son correctos //Guardamos las posiciones por tipos Map<Barco, Posicion> posPorBarco = new HashMap<Barco, Posicion>(); for (Posicion p : manga1.getPosiciones()) { //Aadimos la posicionActual posPorBarco.put(p.getBarco(), p); } //Velas Ligeras //Primero -> Puntos 1 assertEquals(posPorBarco.get(b1).getPuntos(), 1); //Segundo-> Puntos 2 assertEquals(posPorBarco.get(b2).getPuntos(), 2); //Tercero -> Puntos 3 assertEquals(posPorBarco.get(b3).getPuntos(), 3); //Lanchas //Primero -> Puntos 1 assertEquals(posPorBarco.get(b4).getPuntos(), 1); }
From source file:se.acrend.christopher.server.service.impl.BillingServiceImpl.java
public SubscriptionInfo billingCompleted(final String productId) { Entity subscription = subscriptionController.findSubscription(); SubscriptionInfo result = new SubscriptionInfo(); log.debug("Anvndare {} har kpt produkt {}.", new Object[] { subscription.getProperty("userEmail"), productId }); Entity product = productDao.findByProductId(productId); if (product == null) { log.error("Hittade inte produkt med id {}", productId); result.setReturnCode(ReturnCode.Failure); return result; }/*from ww w .ja v a2 s. co m*/ ProductCategory category = ProductCategory.valueOf((String) product.getProperty("category")); ProductType type = ProductType.valueOf((String) product.getProperty("type")); String value = (String) product.getProperty("value"); if (category == ProductCategory.Notification) { if (type == ProductType.Day) { Calendar now = DateUtil.createCalendar(); Calendar expireDate = DateUtil.createCalendar(); expireDate.setTime((Date) subscription.getProperty("notificationExpireDate")); if (expireDate.before(now)) { expireDate = now; } int days = Integer.parseInt(value); expireDate.add(Calendar.DAY_OF_YEAR, days); subscription.setProperty("notificationExpireDate", expireDate.getTime()); } if (type == ProductType.Count) { int currentCount = (Integer) subscription.getProperty("notificationCount"); int count = Integer.parseInt(value); subscription.setProperty("notificationCount", currentCount + count); } } subscriptionController.update(subscription); result.setNotificationCount(EntityUtil.getInt(subscription, "notificationCount", 0)); result.setTravelWarrantCount(EntityUtil.getInt(subscription, "travelWarrantCount", 0)); result.setNotificationExpireDate( DateUtil.toCalendar((Date) subscription.getProperty("notificationExpireDate"))); result.setTravelWarrantExpireDate( DateUtil.toCalendar((Date) subscription.getProperty("travelWarrantExpireDate"))); result.setReturnCode(ReturnCode.Success); return result; }