List of usage examples for org.joda.time MutableDateTime getMillis
public long getMillis()
From source file:app.decoder.data.wrap.WrapEntry.java
License:BSD License
public TimeValue getTradeDate() { if (MessageRules.hasTradeDate(getMessage(), entry)) { final int days = MessageRules.getTradeDate(getMessage(), entry); final MutableDateTime date = new MutableDateTime(0, DateTimeZone.UTC); date.addDays(days);/*from w w w. j a v a2 s .co m*/ return ValueBuilder.newTime(date.getMillis()); } else { return ValueConst.NULL_TIME; } }
From source file:com.carmatech.cassandra.ShardingFrequency.java
License:Apache License
public static long calculateBucket(final long timestamp, final ShardingFrequency frequency) { final MutableDateTime dateTime = new MutableDateTime(timestamp); if (frequency.compareTo(SECONDLY) >= 0) dateTime.setMillisOfSecond(0);/*from w ww. j a v a2 s . c om*/ if (frequency.compareTo(MINUTELY) >= 0) dateTime.setSecondOfMinute(0); if (frequency.compareTo(HOURLY) >= 0) dateTime.setMinuteOfHour(0); if (frequency.compareTo(DAILY) >= 0) dateTime.setHourOfDay(0); if (frequency.compareTo(WEEKLY) >= 0) dateTime.setDayOfWeek(1); if (frequency.compareTo(MONTHLY) >= 0) dateTime.setDayOfMonth(1); return dateTime.getMillis(); }
From source file:com.evolveum.midpoint.web.component.DateInput.java
License:Apache License
public Date computeDateTime() { Date dateFieldInput = getDate(); if (dateFieldInput == null) { return null; }//from www . j ava2 s. c o m Integer hoursInput = getHours(); Integer minutesInput = getMinutes(); AM_PM amOrPmInput = getAmOrPm(); // Get year, month and day ignoring any timezone of the Date object Calendar cal = Calendar.getInstance(); cal.setTime(dateFieldInput); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hours = (hoursInput == null ? 0 : hoursInput % 24); int minutes = (minutesInput == null ? 0 : minutesInput); // Use the input to create a date object with proper timezone MutableDateTime date = new MutableDateTime(year, month, day, hours, minutes, 0, 0, DateTimeZone.forTimeZone(getClientTimeZone())); // Adjust for halfday if needed if (use12HourFormat()) { int halfday = (amOrPmInput == AM_PM.PM ? 1 : 0); date.set(DateTimeFieldType.halfdayOfDay(), halfday); date.set(DateTimeFieldType.hourOfHalfday(), hours % 12); } // The date will be in the server's timezone return newDateInstance(date.getMillis()); }
From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java
License:Open Source License
/** Encode {@code dt} as a MySQL internal TIMESTAMP. Range is unchecked. */ public static int getTimestamp(long[] dt, String tz) { MutableDateTime dateTime = toJodaDateTime(dt, tz); return (int) (dateTime.getMillis() / 1000L); }
From source file:com.google.gerrit.server.config.ScheduleConfig.java
License:Apache License
private static long initialDelay(Config rc, String section, String subsection, String keyStartTime, DateTime now, long interval) { long delay = MISSING_CONFIG; String start = rc.getString(section, subsection, keyStartTime); try {//w w w . j av a 2s. com if (start != null) { DateTimeFormatter formatter; MutableDateTime startTime = now.toMutableDateTime(); try { formatter = ISODateTimeFormat.hourMinute(); LocalTime firstStartTime = formatter.parseLocalTime(start); startTime.hourOfDay().set(firstStartTime.getHourOfDay()); startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour()); } catch (IllegalArgumentException e1) { formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US); LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start); startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek()); startTime.hourOfDay().set(firstStartDateTime.getHourOfDay()); startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour()); } startTime.secondOfMinute().set(0); startTime.millisOfSecond().set(0); long s = startTime.getMillis(); long n = now.getMillis(); delay = (s - n) % interval; if (delay <= 0) { delay += interval; } } else { log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section, keyStartTime)); } } catch (IllegalArgumentException e2) { log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime), e2); delay = INVALID_CONFIG; } return delay; }
From source file:com.graphaware.module.timetree.domain.TimeInstant.java
License:Open Source License
/** * Create an instant immediately following the current one, i.e. with its resolution unit incremented by 1. * * @return next instant.// w w w. ja v a 2 s .c om */ public TimeInstant next() { MutableDateTime time = new MutableDateTime(getTime()); time.add(getResolution().getDateTimeFieldType().getDurationType(), 1); return new TimeInstant(time.getMillis(), getTimezone(), getResolution()); }
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 ww. jav a 2 s.c om 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(); }
From source file:controllers.api.SearchApiController.java
License:Open Source License
/** * Create a list with histogram results that would be serialized to JSON like this * <p/>// w ww.j a v a2 s .c o m * [{ x: -1893456000, y: 92228531 }, { x: -1577923200, y: 106021568 }] */ protected List<Map<String, Long>> formatHistogramResults(DateHistogramResult histogram, int maxDataPoints, boolean allQuery) { final List<Map<String, Long>> points = Lists.newArrayList(); final Map<String, Long> histogramResults = histogram.getResults(); DateTime from; if (allQuery) { String firstTimestamp = histogramResults.entrySet().iterator().next().getKey(); from = new DateTime(Long.parseLong(firstTimestamp) * 1000, DateTimeZone.UTC); } else { from = DateTime.parse(histogram.getHistogramBoundaries().getFrom()); } final DateTime to = DateTime.parse(histogram.getHistogramBoundaries().getTo()); final MutableDateTime currentTime = new MutableDateTime(from); final Duration step = estimateIntervalStep(histogram.getInterval()); 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(histogram.getInterval(), currentTime); while (currentTime.isBefore(to) || currentTime.isEqual(to)) { if (index % factor == 0) { String timestamp = Long.toString(currentTime.getMillis() / 1000); Long result = histogramResults.get(timestamp); Map<String, Long> point = Maps.newHashMap(); point.put("x", Long.parseLong(timestamp)); point.put("y", result != null ? result : 0); points.add(point); } index++; nextStep(histogram.getInterval(), currentTime); } return points; }
From source file:ddf.metrics.reporting.internal.rrd4j.RrdMetricsRetriever.java
License:Open Source License
private void createSummary(Workbook wb, List<String> metricNames, String metricsDir, long startTime, long endTime, SUMMARY_INTERVALS summaryInterval) throws IOException, MetricsGraphException { // convert seconds to milliseconds startTime = TimeUnit.SECONDS.toMillis(startTime); endTime = TimeUnit.SECONDS.toMillis(endTime); DateTime reportStart = new DateTime(startTime, DateTimeZone.UTC); DateTime reportEnd = new DateTime(endTime, DateTimeZone.UTC); Sheet sheet = wb.createSheet();//from ww w. j a v a 2 s . c o m wb.setSheetName(0, reportStart.toString(SUMMARY_TIMESTAMP) + " to " + reportEnd.toString(SUMMARY_TIMESTAMP)); Row headingRow = sheet.createRow(0); int columnMax = 1; for (String metricName : metricNames) { MutableDateTime chunkStart = new MutableDateTime(reportStart); MutableDateTime chunkEnd = new MutableDateTime(chunkStart); Row row = sheet.createRow(metricNames.indexOf(metricName) + 1); int columnCounter = 1; Boolean isSum = null; while (reportEnd.compareTo(chunkEnd) > 0 && columnCounter < EXCEL_MAX_COLUMNS) { increment(chunkEnd, summaryInterval); if (chunkEnd.isAfter(reportEnd)) { chunkEnd.setMillis(reportEnd); } // offset range by one millisecond so rrd will calculate granularity correctly chunkEnd.addMillis(-1); MetricData metricData = getMetricData(getRrdFilename(metricsDir, metricName), TimeUnit.MILLISECONDS.toSeconds(chunkStart.getMillis()), TimeUnit.MILLISECONDS.toSeconds(chunkEnd.getMillis())); isSum = metricData.hasTotalCount(); chunkEnd.addMillis(1); if (headingRow.getCell(columnCounter) == null) { Cell headingRowCell = headingRow.createCell(columnCounter); headingRowCell.getCellStyle().setWrapText(true); headingRowCell.setCellValue(getTimestamp(chunkStart, chunkEnd, columnCounter, summaryInterval)); } Cell sumOrAvg = row.createCell(columnCounter); if (isSum) { sumOrAvg.setCellValue((double) metricData.getTotalCount()); } else { sumOrAvg.setCellValue(cumulativeRunningAverage(metricData.getValues())); } chunkStart.setMillis(chunkEnd); columnCounter++; } columnMax = columnCounter; if (isSum != null) { row.createCell(0).setCellValue(convertCamelCase(metricName) + " (" + (isSum ? "sum" : "avg") + ")"); } } for (int i = 0; i < columnMax; i++) { sheet.autoSizeColumn(i); } }
From source file:de.pro.dbw.util.impl.DateConverter.java
License:Open Source License
public Long addDays(int days) { final MutableDateTime mdtNow = MutableDateTime.now(); mdtNow.addDays(days);//w ww . j a v a 2 s . c om return mdtNow.getMillis(); }