List of usage examples for org.joda.time MutableDateTime MutableDateTime
public MutableDateTime()
ISOChronology
in the default time zone. From source file:se.toxbee.sleepfighter.text.DateTextUtils.java
License:Open Source License
/** * Returns an array of strings with weekday names. * * @param indiceLength how long each string should be. * @param locale the desired locale.//w w w . j a v a2 s . com * @return the array of strings. */ public static final String[] getWeekdayNames(int indiceLength, Locale locale) { DateTimeFormatter fmt = DateTimeFormat.forPattern(Strings.repeat("E", indiceLength)).withLocale(locale); MutableDateTime time = new MutableDateTime(); time.setDayOfWeek(DateTimeConstants.MONDAY); String[] names = new String[DateTimeConstants.DAYS_PER_WEEK]; for (int day = 0; day < DateTimeConstants.DAYS_PER_WEEK; day++) { String name = fmt.print(time); if (name.length() > indiceLength) { name = name.substring(0, indiceLength); } names[day] = name; time.addDays(1); } return names; }
From source file:tv.arte.resteventapi.core.services.impl.EventServiceImpl.java
License:Open Source License
/** * {@inheritDoc}//ww w . j ava 2 s .com */ public RestEvent processRestEvent(String id) { RestEvent restEvent = restEventRepository.findById(id); if (restEvent == null) { logger.warn("Unable to process event with id " + id + ". The event do not exists."); return restEvent; } if (RestEventStatus.SENT.equals(restEvent.getStatus())) { logger.info( "No action will be performed for event with id " + id + ". The event has already been sent."); return restEvent; } if (restEvent.getMaxAttempts() <= restEvent.getCounter()) { logger.info("No action will be performed for event with id " + id + ". The event has no more attempts left."); return restEvent; } if (logger.isDebugEnabled()) logger.debug("Event scheduled for " + restEvent.getNextExecution().toString() + ", is acctualy executed at " + Calendar.getInstance().getTime().toString()); try { RestClientExecutionResult executionResult = RestEventApiRestClient.execute(restEvent); restEvent.setHttpResponseCode(executionResult.getResponseCode()); if (RestClientCallState.OK.equals(executionResult.getState()) && ((executionResult.getResponseCode() >= 200 && executionResult.getResponseCode() < 300) || executionResult.getResponseCode() == 304)) { restEvent.setStatus(RestEventStatus.SENT); } else { if (RestClientCallState.TIMEOUT.equals(executionResult.getState())) { logger.info("The request for RestEvent with id " + id + " has been timed out."); } restEvent.setStatus(RestEventStatus.ERROR); } } catch (Exception e) { restEvent.setStatus(RestEventStatus.ERROR); } restEvent.setCounter(restEvent.getCounter() != null ? restEvent.getCounter() + 1 : 1); if (!RestEventStatus.SENT.equals(restEvent.getStatus()) && restEvent.getCounter() < restEvent.getMaxAttempts()) { MutableDateTime nextExecution = new MutableDateTime(); nextExecution.addSeconds(restEvent.getInterval()); restEvent.setNextExecution(nextExecution.toDate()); } restEvent.setVersion(restEvent.getVersion() != null ? restEvent.getVersion() + 1L : 1L); restEvent.setLastModified(Calendar.getInstance().getTime()); restEventRepository.save(restEvent); return restEvent; }