Java Code Examples for org.joda.time.DateTime#getMillis()
The following examples show how to use
org.joda.time.DateTime#getMillis() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: incubator-pinot File: HierarchicalAnomaliesContent.java License: Apache License 2.0 | 6 votes |
/** * Retrieve the average wow baseline values * @param anomaly an instance of MergedAnomalyResultDTO * @param compareMode the way to compare, WoW, Wo2W, Wo3W, and Wo4W * @param start the start time of the monitoring window in millis * @param end the end time of the monitoring window in millis * @return baseline values based on compareMode * @throws Exception */ private Double getAvgComparisonBaseline(MergedAnomalyResultDTO anomaly, COMPARE_MODE compareMode, long start, long end) throws Exception{ AnomalyFunctionFactory anomalyFunctionFactory = new AnomalyFunctionFactory(thirdEyeAnomalyConfig.getFunctionConfigPath()); AnomalyFunctionDTO anomalyFunction = anomaly.getFunction(); DatasetConfigDTO datasetConfigDTO = DAORegistry.getInstance().getDatasetConfigDAO() .findByDataset(anomalyFunction.getCollection()); AnomalyDetectionInputContextBuilder contextBuilder = new AnomalyDetectionInputContextBuilder(anomalyFunctionFactory); contextBuilder.setFunction(anomalyFunction); DateTimeZone timeZone = DateTimeZone.forID(datasetConfigDTO.getTimezone()); DateTime startTime = new DateTime(start, timeZone); DateTime endTime = new DateTime(end, timeZone); Period baselinePeriod = getBaselinePeriod(compareMode); DateTime baselineStartTime = startTime.minus(baselinePeriod); DateTime baselineEndTime = endTime.minus(baselinePeriod); Pair<Long, Long> timeRange = new Pair<>(baselineStartTime.getMillis(), baselineEndTime.getMillis()); MetricTimeSeries baselineTimeSeries = contextBuilder.fetchTimeSeriesDataByDimension(Arrays.asList(timeRange), anomaly.getDimensions(), false) .build().getDimensionMapMetricTimeSeriesMap().get(anomaly.getDimensions()); return baselineTimeSeries.getMetricAvgs(0d)[0]; }
Example 2
Source Project: incubator-pinot File: AnomalyUtils.java License: Apache License 2.0 | 6 votes |
/** * Logs the known anomalies whose window overlaps with the given window, whose range is defined by windowStart * and windowEnd. * * Reason to log the overlapped anomalies: During anomaly detection, the know anomalies are supposedly used to remove * abnormal baseline values but not current values. This method provides a check before sending the known anomalies to * anomaly detection functions. * * @param windowStart the inclusive start time of the window * @param windowEnd the exclusive end time of the window * @param knownAnomalies the known anomalies */ public static void logAnomaliesOverlapWithWindow(DateTime windowStart, DateTime windowEnd, List<MergedAnomalyResultDTO> knownAnomalies) { if (CollectionUtils.isEmpty(knownAnomalies) || windowEnd.compareTo(windowStart) <= 0) { return; } List<MergedAnomalyResultDTO> overlappedAnomalies = new ArrayList<>(); for (MergedAnomalyResultDTO knownAnomaly : knownAnomalies) { if (knownAnomaly.getStartTime() <= windowEnd.getMillis() && knownAnomaly.getEndTime() >= windowStart.getMillis()) { overlappedAnomalies.add(knownAnomaly); } } if (overlappedAnomalies.size() > 0) { StringBuffer sb = new StringBuffer(); String separator = ""; for (MergedAnomalyResultDTO overlappedAnomaly : overlappedAnomalies) { sb.append(separator).append(overlappedAnomaly.getStartTime()).append("--").append(overlappedAnomaly.getEndTime()); separator = ", "; } LOG.warn("{} merged anomalies overlap with this window {} -- {}. Anomalies: {}", overlappedAnomalies.size(), windowStart, windowEnd, sb.toString()); } }
Example 3
Source Project: astor File: AgeCalculator.java License: GNU General Public License v2.0 | 6 votes |
private void updateResults() { try { DateTime dt = new DateTime(iBirthdateStr.trim(), iChronology); long minuend = System.currentTimeMillis(); long subtrahend = dt.getMillis(); for (int i=0; i<iFieldSets.length; i++) { iFieldSets[i].updateResults(minuend, subtrahend); } } catch (IllegalArgumentException e) { for (int i=0; i<iFieldSets.length; i++) { iFieldSets[i].setResultsText(""); } } }
Example 4
Source Project: incubator-gobblin File: MRStressTest.java License: Apache License 2.0 | 6 votes |
@Override public void run() { DescriptiveStatistics stats = this.limiter.getRateStatsSinceLastReport(); long now = System.currentTimeMillis(); this.runs++; if (stats != null) { long key; if (this.relativeKey) { key = 15 * this.runs; } else { DateTime nowTime = new DateTime(now).withMillisOfSecond(0); DateTime rounded = nowTime.withSecondOfMinute(15 * (nowTime.getSecondOfMinute() / 15)); key = rounded.getMillis() / 1000; } try { this.context.write(new LongWritable(key), new DoubleWritable(stats.getSum())); } catch (IOException | InterruptedException ioe) { log.error("Error: ", ioe); } } }
Example 5
Source Project: aion-germany File: InstanceCooltimeData.java License: GNU General Public License v3.0 | 6 votes |
private long getUpdateHours(String[] days, int hour) { DateTime now = DateTime.now(); DateTime repeatDate = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), hour, 0, 0); int curentDay = now.getDayOfWeek(); for (String name : days) { int day = getDay(name); if (day < curentDay) { continue; } if (day == curentDay) { if (now.isBefore(repeatDate)) { return repeatDate.getMillis(); } } else { repeatDate = repeatDate.plusDays(day - curentDay); return repeatDate.getMillis(); } } return repeatDate.plusDays((7 - curentDay) + getDay(days[0])).getMillis(); }
Example 6
Source Project: nakadi File: ExclusiveJobWrapperAT.java License: MIT License | 5 votes |
@Test public void whenExecuteJobThenOk() throws Exception { jobWrapper.runJobLocked(dummyJob); assertThat(jobExecuted.get(), CoreMatchers.is(true)); assertThat("lock node should be removed", CURATOR.checkExists().forPath(lockPath), CoreMatchers.is(CoreMatchers.nullValue())); final byte[] data = CURATOR.getData().forPath(latestPath); final DateTime lastCleaned = objectMapper.readValue(new String(data, Charsets.UTF_8), DateTime.class); final long msSinceCleaned = new DateTime().getMillis() - lastCleaned.getMillis(); assertThat("job was executed less than 5 seconds ago", msSinceCleaned, lessThan(5000L)); }
Example 7
Source Project: jadira File: TimestampColumnTimeOfDayMapper.java License: Apache License 2.0 | 5 votes |
@Override public Timestamp toNonNullValue(TimeOfDay value) { DateTime zonedValue = new LocalDateTime( 1970,1,1,value.getHourOfDay(), value.getMinuteOfHour(), value.getSecondOfMinute(), value.getMillisOfSecond(), value.getChronology() ).toDateTime(); final Timestamp timestamp = new Timestamp(zonedValue.getMillis()); return timestamp; }
Example 8
Source Project: ipst File: ProcessApiTest.java License: Mozilla Public License 2.0 | 5 votes |
@Test public void testGetByDate() throws Exception { DateTime dt = new DateTime(2016, 1, 16, 01, 0, 0, 0); String date = dt.toDateTimeISO().toString(); long dt_millis = dt.getMillis(); Response res = service.getProcessList(null, null, null, new DateTimeParameter(date), null, null); Assert.assertEquals(200, res.getStatus()); JSONArray arr = new JSONArray((String) res.getEntity()); Assert.assertEquals(1, arr.length()); JSONObject pn = arr.getJSONObject(0); long millis = DateTime.parse((String) pn.get("date")).getMillis(); Assert.assertEquals("Test filter by date", dt_millis, millis); }
Example 9
Source Project: frostmourne File: EsRestClientContainer.java License: MIT License | 5 votes |
public String[] buildIndices(DateTime from, DateTime to, String prefix, String datePattern) { DateTime now = DateTime.now(); if (now.getMillis() < to.getMillis()) { to = now; } List<String> indiceList = new ArrayList<>(); if (Strings.isNullOrEmpty(datePattern)) { indiceList.add(prefix); return indiceList.toArray(new String[0]); } if (datePattern.equals("*")) { indiceList.add(prefix + "*"); return indiceList.toArray(new String[0]); } DateTime cursor = DateTime.parse(from.minusDays(1).toString("yyyy-MM-dd")); while (cursor.getMillis() < to.getMillis()) { String index = prefix + cursor.toString(datePattern); if (prefix.contains("*")) { if (!indiceList.contains(index)) { indiceList.add(index); } } else if (checkIndexExists(index)) { if (!indiceList.contains(index)) { indiceList.add(index); } } cursor = cursor.minusDays(-1); } return indiceList.toArray(new String[0]); }
Example 10
Source Project: rice File: DateTimeServiceImpl.java License: Educational Community License v2.0 | 5 votes |
/** * @see org.kuali.rice.core.api.datetime.DateTimeService#convertToSqlDateUpperBound(java.lang.String) */ public java.sql.Date convertToSqlDateUpperBound(String dateString) throws ParseException { java.sql.Date date = convertToSqlDate(dateString); DateTime dateUpperBound = new DateTime(date).plusDays(1); return new java.sql.Date(dateUpperBound.getMillis()); }
Example 11
Source Project: jmxtrans-agent File: PerMinuteSummarizerOutputWriterTest.java License: MIT License | 5 votes |
@Test public void testPerMinute_null_previous_value() throws Exception { DateTime previousTime = new DateTime(2013, 01, 01, 14, 01, 31); QueryResult previous = new QueryResult("metric1", null, previousTime.getMillis()); // small offest of 45 millis caused by metrics collection DateTime currentTime = previousTime.plusSeconds(60).plusMillis(45); QueryResult current = new QueryResult("metric1", 13, currentTime.getMillis()); QueryResult actualResult = writer.perMinute(current, previous); int actualPerMinuteValue = (Integer) actualResult.getValue(); assertThat(actualPerMinuteValue, is(13)); }
Example 12
Source Project: incubator-pinot File: TaskManagerImpl.java License: Apache License 2.0 | 5 votes |
@Override public List<TaskDTO> findTimeoutTasksWithinDays(int days, long maxTaskTime) { DateTime activeDate = new DateTime().minusDays(days); Timestamp activeTimestamp = new Timestamp(activeDate.getMillis()); DateTime timeoutDate = new DateTime().minus(maxTaskTime); Timestamp timeoutTimestamp = new Timestamp(timeoutDate.getMillis()); Predicate statusPredicate = Predicate.EQ("status", TaskStatus.RUNNING.toString()); Predicate daysTimestampPredicate = Predicate.GE("createTime", activeTimestamp); Predicate timeoutTimestampPredicate = Predicate.LT("updateTime", timeoutTimestamp); return findByPredicate(Predicate.AND(statusPredicate, daysTimestampPredicate, timeoutTimestampPredicate)); }
Example 13
Source Project: hawkular-metrics File: CompressDataJobITest.java License: Apache License 2.0 | 5 votes |
private <T> void testCompressResults(MetricType<T> type, Metric<T> metric, DateTime start) throws Exception { if (metric.getDataPoints() != null && !metric.getDataPoints().isEmpty()) { doAction(() -> metricsService.addDataPoints(type, Observable.just(metric))); } CountDownLatch latch = new CountDownLatch(1); jobScheduler.onJobFinished(jobDetails -> { if(jobDetails.getJobName().equals(JOB_NAME)) { latch.countDown(); } }); jobScheduler.advanceTimeBy(1); assertTrue(latch.await(TIMEOUT, TimeUnit.SECONDS)); long startSlice = DateTimeService.getTimeSlice(start.getMillis(), Duration.standardHours(2)); long endSlice = DateTimeService.getTimeSlice(start.plusHours(1).plusMinutes(59).getMillis(), Duration .standardHours(2)); DataPointDecompressTransformer<T> decompressor = new DataPointDecompressTransformer<>(type, Order.ASC, 0, start .getMillis(), start.plusMinutes(30).getMillis()); Observable<DataPoint<T>> dataPoints = dataAccess.findCompressedData(metric.getMetricId(), startSlice, endSlice, 0, Order.ASC).compose(decompressor); TestSubscriber<DataPoint<T>> pointTestSubscriber = new TestSubscriber<>(); dataPoints.subscribe(pointTestSubscriber); pointTestSubscriber.awaitTerminalEvent(5, TimeUnit.SECONDS); pointTestSubscriber.assertCompleted(); List<DataPoint<T>> compressedPoints = pointTestSubscriber.getOnNextEvents(); assertEquals(metric.getDataPoints(), compressedPoints); }
Example 14
Source Project: AisAbnormal File: RecentEventsReportJob.java License: GNU Lesser General Public License v3.0 | 5 votes |
/** * The execute method is triggered by the scheduler, when the report should be generated. * * @param jobExecutionContext * @throws JobExecutionException */ @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { LOG.debug("RecentEventsReportJob triggered"); DateTime t2 = new DateTime(); DateTime t1 = lastRun >= 0 ? new DateTime(lastRun) : t2.minusHours(24); lastRun = t2.getMillis(); Multimap<Class<? extends Event>, Event> eventsByType = getEventsByType(t1.toDate(), t2.toDate()); String reportBody = generateReportBody(t1.toDate(), t2.toDate(), eventsByType); reportMailer.send("Abnormal events", reportBody); LOG.debug("RecentEventsReportJob finished"); }
Example 15
Source Project: nomulus File: DateTimeConverter.java License: Apache License 2.0 | 4 votes |
@Override @Nullable public Timestamp convertToDatabaseColumn(@Nullable DateTime attribute) { return attribute == null ? null : new Timestamp(attribute.getMillis()); }
Example 16
Source Project: incubator-gobblin File: DatePartitionedAvroFileExtractorTest.java License: Apache License 2.0 | 4 votes |
@BeforeClass public void setUp() throws IOException { this.schema = new Schema.Parser().parse(AVRO_SCHEMA); //set up datetime objects DateTime now = new DateTime(TZ).minusHours(6); this.startDateTime = new DateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), now.getHourOfDay(), 30, 0, TZ); //create records, shift their timestamp by 1 minute DateTime recordDt = startDateTime; recordTimestamps[0] = recordDt.getMillis(); recordDt = recordDt.plusHours(4); for (int i = 1; i < RECORD_SIZE; i++) { recordDt = recordDt.plusMinutes(1); recordTimestamps[i] = recordDt.getMillis(); } // create dummy data partitioned by minutes State state = new State(); state.setProp(TimeBasedAvroWriterPartitioner.WRITER_PARTITION_COLUMNS, PARTITION_COLUMN_NAME); state.setProp(ConfigurationKeys.WRITER_BUFFER_SIZE, ConfigurationKeys.DEFAULT_BUFFER_SIZE); state.setProp(ConfigurationKeys.WRITER_FILE_SYSTEM_URI, ConfigurationKeys.LOCAL_FS_URI); state.setProp(ConfigurationKeys.WRITER_STAGING_DIR, STAGING_DIR); state.setProp(ConfigurationKeys.WRITER_OUTPUT_DIR, OUTPUT_DIR); state.setProp(ConfigurationKeys.WRITER_FILE_PATH, SOURCE_ENTITY); state.setProp(ConfigurationKeys.WRITER_FILE_NAME, FILE_NAME); state.setProp(TimeBasedWriterPartitioner.WRITER_PARTITION_PATTERN, DATE_PATTERN); state.setProp(TimeBasedWriterPartitioner.WRITER_PARTITION_PREFIX, PREFIX); state.setProp(TimeBasedWriterPartitioner.WRITER_PARTITION_SUFFIX, SUFFIX); state.setProp(ConfigurationKeys.WRITER_PARTITIONER_CLASS, TimeBasedAvroWriterPartitioner.class.getName()); DataWriterBuilder<Schema, GenericRecord> builder = new AvroDataWriterBuilder() .writeTo(Destination.of(Destination.DestinationType.HDFS, state)) .writeInFormat(WriterOutputFormat.AVRO) .withWriterId("writer-1") .withSchema(this.schema) .withBranches(1).forBranch(0); this.writer = new PartitionedDataWriter<Schema, GenericRecord>(builder, state); GenericRecordBuilder genericRecordBuilder = new GenericRecordBuilder(this.schema); for (int i = 0; i < RECORD_SIZE; i++) { genericRecordBuilder.set(PARTITION_COLUMN_NAME, recordTimestamps[i]); this.writer.writeEnvelope(new RecordEnvelope<>(genericRecordBuilder.build())); } this.writer.close(); this.writer.commit(); }
Example 17
Source Project: presto File: TestDateTimeFunctionsBase.java License: Apache License 2.0 | 4 votes |
private static SqlDate toDate(DateTime dateDate) { long millis = dateDate.getMillis(); return new SqlDate(toIntExact(MILLISECONDS.toDays(millis))); }
Example 18
Source Project: orianna File: MatchHistory.java License: MIT License | 4 votes |
public Builder withStartTime(final DateTime startTime) { this.startTime = startTime.getMillis(); return this; }
Example 19
Source Project: astor File: StringConverter.java License: GNU General Public License v2.0 | 4 votes |
/** * Sets the value of the mutable interval from the string. * * @param writableInterval the interval to set * @param object the String to convert, must not be null * @param chrono the chronology to use, may be null */ public void setInto(ReadWritableInterval writableInterval, Object object, Chronology chrono) { String str = (String) object; int separator = str.indexOf('/'); if (separator < 0) { throw new IllegalArgumentException("Format requires a '/' separator: " + str); } String leftStr = str.substring(0, separator); if (leftStr.length() <= 0) { throw new IllegalArgumentException("Format invalid: " + str); } String rightStr = str.substring(separator + 1); if (rightStr.length() <= 0) { throw new IllegalArgumentException("Format invalid: " + str); } DateTimeFormatter dateTimeParser = ISODateTimeFormat.dateTimeParser(); dateTimeParser = dateTimeParser.withChronology(chrono); PeriodFormatter periodParser = ISOPeriodFormat.standard(); long startInstant = 0, endInstant = 0; Period period = null; Chronology parsedChrono = null; // before slash char c = leftStr.charAt(0); if (c == 'P' || c == 'p') { period = periodParser.withParseType(getPeriodType(leftStr)).parsePeriod(leftStr); } else { DateTime start = dateTimeParser.parseDateTime(leftStr); startInstant = start.getMillis(); parsedChrono = start.getChronology(); } // after slash c = rightStr.charAt(0); if (c == 'P' || c == 'p') { if (period != null) { throw new IllegalArgumentException("Interval composed of two durations: " + str); } period = periodParser.withParseType(getPeriodType(rightStr)).parsePeriod(rightStr); chrono = (chrono != null ? chrono : parsedChrono); endInstant = chrono.add(period, startInstant, 1); } else { DateTime end = dateTimeParser.parseDateTime(rightStr); endInstant = end.getMillis(); parsedChrono = (parsedChrono != null ? parsedChrono : end.getChronology()); chrono = (chrono != null ? chrono : parsedChrono); if (period != null) { startInstant = chrono.add(period, endInstant, -1); } } writableInterval.setInterval(startInstant, endInstant); writableInterval.setChronology(chrono); }
Example 20
Source Project: hortonmachine File: LasUtils.java License: GNU General Public License v3.0 | 2 votes |
/** * Converts an date object to standard gps time. * * @param dateTime the object (UTC). * @return the standard gps time in seconds. */ public static double dateTimeToStandardGpsTime( DateTime dateTime ) { long millis = dateTime.getMillis() - gpsEpoch.getMillis(); return millis / 1000.0; }