List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java
License:Open Source License
/** * Creates a new Period instance that matches all the instants between N months before the instantiation and the * instantiation./*from ww w .j ava 2 s .c o m*/ * * @param numberOfMonths number of months to substract from current date * @return The corresponding period object */ public static Period createSinceMonthsPeriod(int numberOfMonths) { DateTime dt = new DateTime(); return createPeriod(dt.minusMonths(numberOfMonths).getMillis(), dt.getMillis()); }
From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java
License:Open Source License
/** * Creates a new Period instance that matches all the instants between N years before the instantiation and the * instantiation./*from www . ja va2s . c o m*/ * * @param numberOfYears number of years to substract from current date * @return The corresponding period object */ public static Period createSinceYearsPeriod(int numberOfYears) { DateTime dt = new DateTime(); return createPeriod(dt.minusYears(numberOfYears).getMillis(), dt.getMillis()); }
From source file:com.xpn.xwiki.stats.impl.xwiki.XWikiStatsReader.java
License:Open Source License
/** * Shows how the statistics for the specified action have evolved over the specified period of time. * /*w w w . ja va 2s.c o m*/ * @param action the action for which to retrieve statistics. * @param scope the set of documents to consider. * @param period the period of time, including its start date but excluding its end date. * @param step the step used for sampling the period. * @param context the XWiki context. * @return a map of (date, actionCount) pairs. */ public Map<DateTime, Integer> getActionStatistics(String action, Scope scope, Period period, Duration step, XWikiContext context) { DateTime stepStart = new DateTime(period.getStart()); DateTime periodEnd = new DateTime(period.getEnd()); org.joda.time.Period stepDuration = new org.joda.time.Period(step.getYears(), step.getMonths(), step.getWeeks(), step.getDays(), 0, 0, 0, 0); Map<DateTime, Integer> activity = new HashMap<DateTime, Integer>(); while (stepStart.compareTo(periodEnd) < 0) { DateTime stepEnd = stepStart.plus(stepDuration); if (stepEnd.compareTo(periodEnd) > 0) { stepEnd = periodEnd; } List<DocumentStats> stats = getDocumentStatistics(action, scope, new Period(stepStart.getMillis(), stepEnd.getMillis()), RangeFactory.FIRST, context); int actionCount = 0; if (stats.size() > 0) { actionCount = stats.get(0).getPageViews(); } activity.put(stepStart, new Integer(actionCount)); stepStart = stepEnd; } return activity; }
From source file:com.xpn.xwiki.stats.impl.xwiki.XWikiStatsReader.java
License:Open Source License
/** * Converts the rows retrieved from the database to a list of VisitStats instances. * /*from w ww . ja v a2s.c o m*/ * @param resultSet the result of a database query for visitor statistics. * @param startDate the start date used in the query. * @param endDate the end date used in the query. * @return a list of {@link com.xpn.xwiki.stats.impl.VisitStats} objects. * @see #getVisitStatistics(String, Period, Range, XWikiContext) */ private List<VisitStats> getVisitStatistics(List<?> resultSet, DateTime startDate, DateTime endDate) { List<VisitStats> stats = new ArrayList<VisitStats>(resultSet.size()); for (Iterator<?> it = resultSet.iterator(); it.hasNext();) { Object[] result = (Object[]) it.next(); String name = (String) result[0]; String uniqueID = ""; String cookie = ""; String ip = ""; String userAgent = ""; int pageSaves = ((Number) result[1]).intValue(); int pageViews = ((Number) result[2]).intValue(); int downloads = ((Number) result[3]).intValue(); VisitStats vs = new VisitStats(name, uniqueID, cookie, ip, userAgent, new Date(startDate.getMillis()), PeriodType.DAY); vs.setStartDate(new Date(startDate.getMillis())); vs.setEndDate(new Date(endDate.getMillis())); vs.setPageSaves(pageSaves); vs.setPageViews(pageViews); vs.setDownloads(downloads); stats.add(vs); } return stats; }
From source file:com.yahoo.xpathproto.handler.RfcTimestampHandler.java
License:Open Source License
public Object parseDate(final String dateStr) { DateTime date; try {//ww w . ja v a 2s. co m date = formatter.parseDateTime(dateStr).toDateTime(DateTimeZone.UTC); } catch (final IllegalArgumentException e) { logger.error("Failed to parse date: " + dateStr, e); return null; } return date.getMillis() / 1000; }
From source file:com.yunguchang.data.ApplicationRepository.java
public List<TBusApproveSugEntity> listApplyApproveInfo(DateTime startTime, DateTime endTime, PrincipalExt principalExtOrNull) { if (startTime == null) { startTime = DateTimeUtil.appStartTime; }/*from www .ja v a2 s . c o m*/ if (endTime == null) { endTime = DateTimeUtil.appEndTime; } CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<TBusApproveSugEntity> cq = cb.createQuery(TBusApproveSugEntity.class); Root<TBusApproveSugEntity> approveRoot = cq.from(TBusApproveSugEntity.class); approveRoot.fetch(TBusApproveSugEntity_.application); approveRoot.fetch(TBusApproveSugEntity_.user, JoinType.LEFT); cq.select(approveRoot); Predicate predicate = cb.and( cb.between(approveRoot.get(TBusApproveSugEntity_.operatedate), new Timestamp(startTime.getMillis()), new Timestamp(endTime.getMillis())), cb.or(cb.isNull(approveRoot.get(TBusApproveSugEntity_.updateBySync)), cb.isFalse(approveRoot.get(TBusApproveSugEntity_.updateBySync)))); cq.where(predicate); TypedQuery<TBusApproveSugEntity> query = em.createQuery(cq); applySecurityFilter("applications", principalExtOrNull); return query.getResultList(); }
From source file:com.zaradai.bloodstone.system.actions.CurrentTime.java
License:Apache License
@Override public ActivityResult execute() throws Exception { DateTime now = DateTime.now(); date = now.toDate();/*w ww . ja va2s . c o m*/ millis = now.getMillis(); return ActivityResult.SUCCESS; }
From source file:com.zaradai.kunzite.trader.services.timer.DefaultTimerEngine.java
License:Apache License
@Override public UUID subscribe(DateTime target, TimerListener listener) { return subscribe(target.getMillis() - timeBase.now(), TimeUnit.MILLISECONDS, false, listener); }
From source file:controllers.AdminHandler.java
License:Apache License
/** * Delete a time-specified number of MailTransactions <br/> * GET /admin/mtxs/delete/{time}//from w w w. ja v a 2 s. c om * * @param time * the time in days (all before will be deleted) * @return to the MailTransaction-Page */ public Result deleteMTXProcess(@PathParam("time") Integer time, Context context) { if (time == null) return Results.redirect(context.getContextPath() + "/admin/mtxs"); if (time == -1) { // all entries will be deleted MailTransaction.deleteTxInPeriod(null); } else { // calculate the time and delete all entries before DateTime dt = DateTime.now().minusDays(time); MailTransaction.deleteTxInPeriod(dt.getMillis()); } return Results.redirect(context.getContextPath() + "/admin/mtxs"); }
From source file:controllers.api.DashboardsApiController.java
License:Open Source License
protected List<Map<String, Object>> formatWidgetValueResults(final int maxDataPoints, final Object resultValue, final String functionType, final String interval, final Map<String, Object> timeRange, final boolean allQuery) { final ImmutableList.Builder<Map<String, Object>> pointListBuilder = ImmutableList.builder(); if (resultValue instanceof Map) { final Map<?, ?> resultMap = (Map) resultValue; DateTime from;// w w w. j a v a2 s. com if (allQuery) { String firstTimestamp = (String) resultMap.entrySet().iterator().next().getKey(); from = new DateTime(Long.parseLong(firstTimestamp) * 1000, DateTimeZone.UTC); } else { from = DateTime.parse((String) timeRange.get("from")).withZone(DateTimeZone.UTC); } final DateTime to = DateTime.parse((String) timeRange.get("to")); final MutableDateTime currentTime = new MutableDateTime(from); final Duration step = estimateIntervalStep(interval); final int dataPoints = (int) ((to.getMillis() - from.getMillis()) / step.getMillis()); // using the absolute value guarantees, that there will always be enough values for the given resolution final int factor = (maxDataPoints != -1 && dataPoints > maxDataPoints) ? dataPoints / maxDataPoints : 1; int index = 0; floorToBeginningOfInterval(interval, currentTime); while (currentTime.isBefore(to) || currentTime.isEqual(to)) { if (index % factor == 0) { String timestamp = Long.toString(currentTime.getMillis() / 1000); Object value = resultMap.get(timestamp); if (functionType != null && value != null) { value = ((Map) value).get(functionType); } Object result = value == null ? 0 : value; final Map<String, Object> point = ImmutableMap.of("x", Long.parseLong(timestamp), "y", result); pointListBuilder.add(point); } index++; nextStep(interval, currentTime); } } return pointListBuilder.build(); }