List of usage examples for org.joda.time MutableDateTime MutableDateTime
public MutableDateTime(Object instant)
From source file:com.tmathmeyer.sentinel.utils.Months.java
License:Open Source License
public static DateTime nextWeek(DateTime time) { MutableDateTime mdt = new MutableDateTime(time); mdt.addDays(7); return mdt.toDateTime(); }
From source file:com.tmathmeyer.sentinel.utils.Months.java
License:Open Source License
public static DateTime prevWeek(DateTime time) { MutableDateTime mdt = new MutableDateTime(time); mdt.addDays(-7); return mdt.toDateTime(); }
From source file:com.tmathmeyer.sentinel.utils.Months.java
License:Open Source License
/** * //from w w w . ja v a 2s .c om * @param d any DateTime * @return get's the Sundae of the provided day's week */ public static DateTime getWeekStart(DateTime d) { MutableDateTime t = new MutableDateTime(d); t.addDays(-(d.getDayOfWeek() % 7)); return t.toDateTime(); }
From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java
License:Open Source License
/** * Creates a new Period instance that matches exactly the day that includes the specified time stamp. * // w ww . jav a2 s.co m * @param timestamp The milliseconds from 1970-01-01T00:00:00Z * @return A new Period instance */ public static Period createDayPeriod(long timestamp) { MutableDateTime mdt = new MutableDateTime(timestamp); return createPeriod(toDayStart(mdt).getMillis(), toDayEnd(mdt).getMillis()); }
From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java
License:Open Source License
/** * Creates a new Period instance that matches exactly the hour that includes the specified time stamp. * /*from w ww . j a v a 2s . c o m*/ * @param timestamp The milliseconds from 1970-01-01T00:00:00Z * @return A new Period instance */ public static Period createHourPeriod(long timestamp) { MutableDateTime mdt = new MutableDateTime(timestamp); return createPeriod(toHourStart(mdt).getMillis(), toHourEnd(mdt).getMillis()); }
From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java
License:Open Source License
/** * Creates a new Period instance that matches exactly the week that includes the specified time stamp. * //from w w w.j av a 2 s. c o m * @param timestamp The milliseconds from 1970-01-01T00:00:00Z * @return A new Period instance */ public static Period createWeekPeriod(long timestamp) { MutableDateTime mdt = new MutableDateTime(timestamp); return createPeriod(toWeekStart(mdt).getMillis(), toWeekEnd(mdt).getMillis()); }
From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java
License:Open Source License
/** * Creates a new Period instance that matches exactly the month that includes the specified time stamp. * /*from w w w . j av a 2s . c o m*/ * @param timestamp The milliseconds from 1970-01-01T00:00:00Z * @return A new Period instance */ public static Period createMonthPeriod(long timestamp) { MutableDateTime mdt = new MutableDateTime(timestamp); return createPeriod(toMonthStart(mdt).getMillis(), toMonthEnd(mdt).getMillis()); }
From source file:com.xpn.xwiki.criteria.impl.PeriodFactory.java
License:Open Source License
/** * Creates a new Period instance that matches exactly the year that includes the specified time stamp. * //from www . j a v a 2 s. co m * @param timestamp The milliseconds from 1970-01-01T00:00:00Z * @return A new Period instance */ public static Period createYearPeriod(long timestamp) { MutableDateTime mdt = new MutableDateTime(timestamp); return createPeriod(toYearStart(mdt).getMillis(), toYearEnd(mdt).getMillis()); }
From source file:com.xpn.xwiki.plugin.jodatime.JodaTimePlugin.java
License:Open Source License
/** * @see org.joda.time.MutableDateTime#MutableDateTime(long) *//*from w ww . java2s . c om*/ public MutableDateTime getMutableDateTime(long instant) { return new MutableDateTime(instant); }
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;/*from w w w.j av a 2s. co m*/ 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(); }