List of usage examples for org.joda.time DateTime DateTime
public DateTime()
ISOChronology
in the default time zone. From source file:com.addthis.basis.time.Dates.java
License:Apache License
/** * Truncate interval start and end by current time * (start/end values after current time are set to current time) * <p/>//from ww w . ja v a 2 s . com * Truncate interval start by a specified number of period types * (eg. 30 days, 52 weeks, etc.) * <p/> * If type is null, no truncation is performed. * <p/> * When no truncation is performed, the input interval is returned * (this is useful for efficiently testing if truncation was performed). * * @param interval * @param limit number of TYPE periods above which interval should be truncated * @param type single field period type (the result of this method is undefined for multi-field period types) * @return */ public static Interval truncateInterval(Interval interval, int limit, PeriodType type) { Interval truncatedInterval = interval; if (type != null) { // Truncate end DateTime now = new DateTime(); if (interval.getEnd().isAfter(now)) { if (interval.getStart().isAfter(now)) { truncatedInterval = new Interval(now, now); } else { truncatedInterval = interval.withEnd(now); } } // Truncate start if (truncatedInterval.toPeriod(type).getValue(0) > --limit) { Period limitPeriod = period(limit, type); DateTime truncatedStart = truncatedInterval.getEnd().minus(limitPeriod); truncatedInterval = truncatedInterval.withStart(truncatedStart); } } return truncatedInterval; }
From source file:com.addthis.basis.time.Dates.java
License:Apache License
/** * Create an interval from two date strings * <p/>//www. j ava 2 s. c o m * begStr | endStr | return * ------------------------- * bad | bad | (now, now) * bad | E | (E, E) * B | bad | (B, B) * B | E | (B, E) * B(>E)| E(<B)| (E, E) * <p/> * ("bad" in the table above indicates that the input * is either null or fails to parse) * <p/> * TODO: accept default beg/end parameters * * @param begStr beginning of interval * @param endStr end of interval * @return */ public static Interval parseInterval(String begStr, String endStr, DateTimeFormatter format) { DateTime beg = null; DateTime end = null; boolean begFailed = false; boolean endFailed = false; try { beg = format.parseDateTime(begStr); } catch (Exception e) { begFailed = true; } try { end = format.parseDateTime(endStr); } catch (Exception e) { endFailed = true; } if (begFailed && endFailed) { end = beg = new DateTime(); } else if (begFailed) { beg = end; } else if (endFailed) { end = beg; } if (beg.isAfter(end)) { beg = end; } return new Interval(beg, end); }
From source file:com.addthis.hydra.data.filter.bundle.BundleFilterTimeRange.java
License:Apache License
private long convertDate(String date) { // return days offset into the past if (date.startsWith("-")) { return new DateTime().minusDays(Integer.parseInt(date.substring(1))).toDate().getTime(); }// w w w . j a v a 2 s . c o m if (format != null) { return format.parseMillis(date); } // return YYMMDD(HH)(MM) formatted time switch (date.length()) { case 6: return ymd.parseMillis(date); case 8: return ymdh.parseMillis(date); case 10: return ymdhm.parseMillis(date); default: return 0; } }
From source file:com.addthis.hydra.data.util.DateUtil.java
License:Apache License
public static DateTime getDateTime(DateTimeFormatter formatter, String date) { if (date.startsWith(NOW_PREFIX) && date.endsWith(NOW_POSTFIX)) { if (date.equals(NOW)) { return new DateTime(); }//from ww w . j a v a 2 s. c o m DateTime time = new DateTime(); int pos; if ((pos = date.indexOf("+")) > 0) { time = time .plusDays(Integer.parseInt(date.substring(pos + 1, date.length() - NOW_POSTFIX.length()))); } else if ((pos = date.indexOf("-")) > 0) { time = time .minusDays(Integer.parseInt(date.substring(pos + 1, date.length() - NOW_POSTFIX.length()))); } return time; } return formatter.parseDateTime(date); }
From source file:com.addthis.hydra.task.source.AbstractPersistentStreamSource.java
License:Apache License
/** */ private DateTime parseDateTime(String dateString) { DateTime time;/*from w w w . j a v a 2 s .com*/ if (dateString.contains(NOW_PREFIX)) { // TODO: be better to get this time from a service time = new DateTime(); time = time.plusDays(findDaysOffset(dateString)); } else { time = formatter.parseDateTime(dateString); } return time; }
From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java
License:Open Source License
public void profileWrites(final ProceedingJoinPoint call, final Object model) throws Throwable { if (LOGGER.isTraceEnabled()) { final DateTime start = new DateTime(); call.proceed();/*from w w w. j av a 2s. c om*/ logProfileCall(call, model, (new Duration(start, new DateTime()).getMillis())); } else { call.proceed(); } }
From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java
License:Open Source License
public Object profileFind(final ProceedingJoinPoint call) throws Throwable { if (LOGGER.isTraceEnabled()) { final DateTime start = new DateTime(); final Object model = call.proceed(); logProfileCall(call, model, (new Duration(start, new DateTime()).getMillis())); return model; } else {/*from ww w.j a v a 2 s . c om*/ return call.proceed(); } }
From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java
License:Open Source License
public Object profileFindList(final ProceedingJoinPoint call) throws Throwable { if (LOGGER.isTraceEnabled()) { final DateTime start = new DateTime(); @SuppressWarnings({ "unchecked" }) final List<Object> models = (List<Object>) call.proceed(); logProfileCall(call, models, (new Duration(start, new DateTime()).getMillis())); return models; } else {/* www . jav a 2 s. co m*/ return call.proceed(); } }
From source file:com.agenmate.lollipop.addedit.AddEditFragment.java
License:Apache License
private long getDueDate() { if (timePickerLayout.getDueDateStatus() == TimePickerLayout.NO_DUE_DATE) return 0; else {//www.j a va2s . c o m long time = timePickerLayout.getTimeFromPicker().getMillis() * 1000; DateTime now = new DateTime().withSecondOfMinute(0).withMillisOfSecond(0).plusMinutes(1); if (now.getMillis() * 1000 < time) return time; else { // TODO turn off alarm return -1; } } }
From source file:com.aionemu.gameserver.model.house.MaintenanceTask.java
License:Open Source License
@Override protected void executeTask() { if (!HousingConfig.ENABLE_HOUSE_PAY) { return;// w w w . j a va 2s . co m } // Get times based on configuration values DateTime now = new DateTime(); DateTime previousRun = now.minus(getPeriod()); // usually week ago DateTime beforePreviousRun = previousRun.minus(getPeriod()); // usually two weeks ago for (House house : maintainedHouses) { if (house.isFeePaid()) { continue; // player already paid, don't check } long payTime = house.getNextPay().getTime(); long impoundTime = 0; int warnCount = 0; PlayerCommonData pcd = null; Player player = World.getInstance().findPlayer(house.getOwnerId()); if (player == null) { pcd = DAOManager.getDAO(PlayerDAO.class).loadPlayerCommonData(house.getOwnerId()); } else { pcd = player.getCommonData(); } if (pcd == null) { // player doesn't exist already for some reasons log.warn("House " + house.getAddress().getId() + " had player assigned but no player exists. Auctioned."); putHouseToAuction(house, null); continue; } if (payTime <= beforePreviousRun.getMillis()) { DateTime plusDay = beforePreviousRun.minusDays(1); if (payTime <= plusDay.getMillis()) { // player didn't pay after the second warning and one day passed impoundTime = now.getMillis(); warnCount = 3; putHouseToAuction(house, pcd); } else { impoundTime = now.plusDays(1).getMillis(); warnCount = 2; } } else if (payTime <= previousRun.getMillis()) { // player did't pay 1 period impoundTime = now.plus(getPeriod()).plusDays(1).getMillis(); warnCount = 1; } else { continue; // should not happen } if (pcd.isOnline()) { if (warnCount == 3) { PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_HOUSING_SEQUESTRATE); } else { PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_MSG_HOUSING_OVERDUE); } } MailFormatter.sendHouseMaintenanceMail(house, warnCount, impoundTime); } }