List of usage examples for org.joda.time DateTime plusHours
public DateTime plusHours(int hours)
From source file:com.addthis.hydra.task.map.DataPurgeServiceImpl.java
License:Apache License
@Override public boolean purgeData(DataPurgeConfig dataPurgeConfig, DateTime currentTime) { if (!validatePurgeParameters(dataPurgeConfig, currentTime)) { return false; }// w ww .j av a 2 s . c om DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dataPurgeConfig.getDatePathFormat()); DateTime oldestDataAllowed; if (dataPurgeConfig.getMaxAgeInDays() > 0) { oldestDataAllowed = currentTime.plusDays(-dataPurgeConfig.getMaxAgeInDays()); } else { oldestDataAllowed = currentTime.plusHours(-dataPurgeConfig.getMaxAgeInHours()); } logger.debug("Oldest data allowed {} , current time is {}", new Object[] { oldestDataAllowed, currentTime }); for (String directoryPrefix : dataPurgeConfig.getDirectoryPrefix()) { for (File prefixDirectory : expandPrefix(directoryPrefix)) { List<File> subdirectories = getSubdirectoryList(prefixDirectory, null); for (File subdirectory : subdirectories) { logger.trace("Considering directory {} for purge", subdirectory); safeDelete(prefixDirectory.getPath(), dateTimeFormatter, oldestDataAllowed, subdirectory, dataPurgeConfig.isFileBasedPurge(), dataPurgeConfig.getDateStartIndex(), dataPurgeConfig.getDateStringLength()); } if (dataPurgeConfig.getCleanEmptyParents()) { for (File directory : subdirectories) { if (directory.list() != null && directory.list().length == 0) { try { FileUtils.deleteDirectory(directory); } catch (IOException e) { logger.warn("Failed to delete empty directory {}", directory); } } } } } } return true; }
From source file:com.addthis.hydra.task.source.AbstractPersistentStreamSource.java
License:Apache License
/** * @return a list of dates given the start/end range from the config *///www . j a v a 2 s . co m private void fillDateList(DateTime start, DateTime end) { DateTime mark = start; while (mark.isBefore(end) || mark.isEqual(end)) { if (reverse) { dates.addFirst(mark); } else { dates.addLast(mark); } if ((dateIncrements != null && dateIncrements.equals("DAYS")) || dateFormat.length() == 6) { mark = mark.plusDays(1); } else if ((dateIncrements != null && dateIncrements.equals("HOURS")) || dateFormat.length() == 8) { mark = mark.plusHours(1); } else if ((dateIncrements != null && dateIncrements.equals("MONTHS"))) { mark = mark.plusMonths(1); } else if (dateIncrements == null) { log.warn("Non-Standard dateFormat: " + dateFormat + " defaulting to daily time increments\n" + "This can be modified to hourly time increments by setting dateIncrements to 'HOURS'"); mark = mark.plusDays(1); } } }
From source file:com.aionemu.gameserver.dataholders.InstanceCooltimeData.java
License:Open Source License
public long getInstanceEntranceCooltime(Player player, int worldId) { int instanceCooldownRate = InstanceService.getInstanceRate(player, worldId); long instanceCoolTime = 0; InstanceCooltime clt = getInstanceCooltimeByWorldId(worldId); if (clt != null) { instanceCoolTime = clt.getEntCoolTime(); if (clt.getCoolTimeType().isDaily()) { DateTime now = DateTime.now(); DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), (int) (instanceCoolTime / 100), 0, 0); if (now.isAfter(repeatDate)) { repeatDate = repeatDate.plusHours(24); instanceCoolTime = repeatDate.getMillis(); } else { instanceCoolTime = repeatDate.getMillis(); }//from www . jav a2 s . c o m } else if (clt.getCoolTimeType().isWeekly()) { String[] days = clt.getTypeValue().split(","); instanceCoolTime = getUpdateHours(days, (int) (instanceCoolTime / 100)); } else { instanceCoolTime = System.currentTimeMillis() + (instanceCoolTime * 60 * 1000); } } if (instanceCooldownRate != 1) { instanceCoolTime = System.currentTimeMillis() + ((instanceCoolTime - System.currentTimeMillis()) / instanceCooldownRate); } return instanceCoolTime; }
From source file:com.aionemu.gameserver.services.LoginEventService.java
License:Open Source License
private static Timestamp autoAddTimeColumn() { DateTime now = DateTime.now();/*from ww w . j a v a2 s. co m*/ DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 9, 0, 0); if (now.isAfter(repeatDate)) { repeatDate = repeatDate.plusHours(24); } return new Timestamp(repeatDate.getMillis()); }
From source file:com.aionemu.gameserver.services.LoginEventService.java
License:Open Source License
private static Timestamp countNextRepeatTime() { DateTime now = DateTime.now();//from www .java2 s. co m DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 9, 0, 0); if (now.isAfter(repeatDate)) { repeatDate = repeatDate.plusHours(24); } return new Timestamp(repeatDate.getMillis()); }
From source file:com.aionemu.gameserver.services.QuestService.java
License:Open Source License
private static Timestamp countNextRepeatTime(Player player, QuestTemplate template) { DateTime now = DateTime.now();/*from w ww . j a v a 2 s . co m*/ DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 9, 0, 0); if (template.isDaily()) { if (now.isAfter(repeatDate)) { repeatDate = repeatDate.plusHours(24); } PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400855, "9")); } else { int daysToAdd = 7; int startDay = 7; for (QuestRepeatCycle weekDay : template.getRepeatCycle()) { int diff = weekDay.getDay() - repeatDate.getDayOfWeek(); if (diff > 0 && diff < daysToAdd) { daysToAdd = diff; } if (startDay > weekDay.getDay()) { startDay = weekDay.getDay(); } } if (startDay == daysToAdd) { daysToAdd = 7; } else if (daysToAdd == 7 && startDay < 7) { daysToAdd = 7 - repeatDate.getDayOfWeek() + startDay; } repeatDate = repeatDate.plusDays(daysToAdd); PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400857, new DescriptionId(1800667), "9")); } return new Timestamp(repeatDate.getMillis()); }
From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java
License:Apache License
/** * Quick create an event.// www . jav a 2s . co m * * @param start * the start * @param end * the end * @param summary * the summary * @param location * the location * @param calendarId * the calendar id * @return the object node * @throws Exception * the exception */ public ObjectNode createEventQuick(@Optional @Name("start") String start, @Optional @Name("end") String end, @Optional @Name("summary") final String summary, @Optional @Name("location") final String location, @Optional @Name("calendarId") final String calendarId) throws Exception { final ObjectNode event = JOM.createObjectNode(); if (start == null) { // set start to current time, rounded to hours DateTime startDate = DateTime.now(); startDate = startDate.plusHours(1); startDate = startDate.minusMinutes(startDate.getMinuteOfHour()); startDate = startDate.minusSeconds(startDate.getSecondOfMinute()); startDate = startDate.minusMillis(startDate.getMillisOfSecond()); start = startDate.toString(); } final ObjectNode startObj = JOM.createObjectNode(); startObj.put("dateTime", start); event.put("start", startObj); if (end == null) { // set end to start +1 hour final DateTime startDate = new DateTime(start); final DateTime endDate = startDate.plusHours(1); end = endDate.toString(); } final ObjectNode endObj = JOM.createObjectNode(); endObj.put("dateTime", end); event.put("end", endObj); if (summary != null) { event.put("summary", summary); } if (location != null) { event.put("location", location); } return createEvent(event, calendarId); }
From source file:com.battlelancer.seriesguide.util.TimeTools.java
License:Apache License
private static DateTime applyUnitedStatesCorrections(@Nullable String country, @NonNull String localTimeZone, @NonNull DateTime dateTime) { // assumed base time zone for US shows by trakt is America/New_York // EST UTC5:00, EDT UTC4:00 // east feed (default): simultaneously in Eastern and Central // delayed 1 hour in Mountain // delayed three hours in Pacific // <==> // same local time in Eastern + Pacific (e.g. 20:00) // same local time in Central + Mountain (e.g. 19:00) // not a US show or no correction necessary (getting east feed) if (!ISO3166_1_UNITED_STATES.equals(country) || localTimeZone.equals(TIMEZONE_ID_US_EASTERN) || localTimeZone.equals(TIMEZONE_ID_US_EASTERN_DETROIT) || localTimeZone.equals(TIMEZONE_ID_US_CENTRAL)) { return dateTime; }//from www .j a v a2 s. c om int offset = 0; if (localTimeZone.equals(TIMEZONE_ID_US_MOUNTAIN)) { // MST UTC7:00, MDT UTC6:00 offset += 1; } else if (localTimeZone.equals(TIMEZONE_ID_US_ARIZONA)) { // is always UTC-07:00, so like Mountain, but no DST boolean noDstInEastern = DateTimeZone.forID(TIMEZONE_ID_US_EASTERN) .isStandardOffset(dateTime.getMillis()); if (noDstInEastern) { offset += 1; } else { offset += 2; } } else if (localTimeZone.equals(TIMEZONE_ID_US_PACIFIC)) { // PST UTC8:00 or PDT UTC7:00 offset += 3; } dateTime = dateTime.plusHours(offset); return dateTime; }
From source file:com.battlelancer.seriesguide.util.TimeTools.java
License:Apache License
/** * Returns a date time equal to the given date time plus the user-defined offset. *///from w w w . j a va 2 s . co m private static DateTime applyUserOffset(Context context, DateTime dateTime) { int offset = getUserOffset(context); if (offset != 0) { dateTime = dateTime.plusHours(offset); } return dateTime; }
From source file:com.cisco.dvbu.ps.utils.date.DateAddDate.java
License:Open Source License
/** * Called to invoke the stored procedure. Will only be called a * single time per instance. Can throw CustomProcedureException or * SQLException if there is an error during invoke. *//* w w w .j a va2 s. c om*/ @Override public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException { java.util.Date startDate = null; Calendar startCal = null; DateTime startDateTime = null; DateTime endDateTime = null; String datePart = null; int dateLength = 0; try { result = null; if (inputValues[0] == null || inputValues[1] == null || inputValues[2] == null) { return; } datePart = (String) inputValues[0]; dateLength = (Integer) inputValues[1]; startDate = (java.util.Date) inputValues[2]; startCal = Calendar.getInstance(); startCal.setTime(startDate); startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1, startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0); if (datePart.equalsIgnoreCase("second")) { endDateTime = startDateTime.plusSeconds(dateLength); } if (datePart.equalsIgnoreCase("minute")) { endDateTime = startDateTime.plusMinutes(dateLength); } if (datePart.equalsIgnoreCase("hour")) { endDateTime = startDateTime.plusHours(dateLength); } if (datePart.equalsIgnoreCase("day")) { endDateTime = startDateTime.plusDays(dateLength); } if (datePart.equalsIgnoreCase("week")) { endDateTime = startDateTime.plusWeeks(dateLength); } if (datePart.equalsIgnoreCase("month")) { endDateTime = startDateTime.plusMonths(dateLength); } if (datePart.equalsIgnoreCase("year")) { endDateTime = startDateTime.plusYears(dateLength); } result = new java.sql.Date(endDateTime.getMillis()); } catch (Throwable t) { throw new CustomProcedureException(t); } }