/* * (non-Javadoc) * @see com.almende.eve.agent.AgentCore#onReady() */ public void onReady() { DateTime now = DateTime.now(); super.onReady(); LOG.warning("OnReady called!"); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); }
public static String formatUTCToLocal(String datetime) { String returnTimeDate = ""; DateTime dtUTC = null; DateTimeZone timezone = DateTimeZone.getDefault(); DateTimeFormatter formatDT = DateTimeFormat.forPattern("MMM dd, yyyy hh:mma"); try { DateTime dateDateTime1 = formatDT.parseDateTime(datetime); DateTime now = new DateTime(); DateTime nowUTC = new LocalDateTime(now).toDateTime(DateTimeZone.UTC); long instant = now.getMillis(); long instantUTC = nowUTC.getMillis(); long offset = instantUTC - instant; // convert to local time dtUTC = dateDateTime1.withZoneRetainFields(DateTimeZone.UTC); // dtUTC = dateDateTime1.toDateTime(timezone); dtUTC = dtUTC.plusMillis((int) offset); returnTimeDate = dtUTC.toString(formatDT); } catch (Exception e) { returnTimeDate = "null"; e.printStackTrace(); } return returnTimeDate; }
private void logProgress(final long count, final long total, final DateTime begin) { DateTime current = DateTime.now(); long duration = current.getMillis() - begin.getMillis(); int rate = (int) (count / duration) + 1; int remaining = (int) ((total - count) / rate); DateTime done = current.plusMillis(remaining); System.out.printf( "Imported %d of %d (%.2f%%). Estimated completion time: %s\n", count, total, 100.0 * count / total, done.toString("HH:mm:ss")); }
private SignalTimeHolder getNextTimeForOffsetType( SignalTime signalTime, List<SignalTimeHolder> previousTimes, Long experimentId) { if (previousTimes.size() == 0) { return createNullSignalTimeHolder( signalTime); // we don't allow offset types as the first signalTime } SignalTimeHolder previousTimePair = previousTimes.get(previousTimes.size() - 1); DateTime basis = computeBasisTimeForOffsetType(signalTime, previousTimePair, experimentId); if (basis != null) { DateTime chosenTime = basis.plusMillis(signalTime.getOffsetTimeMillis()); return new SignalTimeHolder(null, null, chosenTime, signalTime); } else { return createNullSignalTimeHolder(signalTime); } }
@Test public void testOthersCallOutOfBounds_OtherIsMax() { DateTime instant = new DateTime(2013, 9, 20, 4, 40, 11); BigDecimal expectedResult = new BigDecimal("15.00"); BigDecimal actualResult = executeGetInvoice( callee, join( generateSMS("007", "008", instant, HOUR, 10), generateSMS("007", "008", instant, HOUR + 20, 10), generateSMS("007", "any", instant.plusMillis(HOUR * 11 + 100), 0, 1)), billingPeriod, callee, called) .getAmount(); assertEquals(expectedResult, actualResult); }
public TimelineSourceEventAccumulator( final TimelineDao dao, final TimelineCoder timelineCoder, final SampleCoder sampleCoder, final BackgroundDBChunkWriter backgroundWriter, final int sourceId, final int eventCategoryId, final DateTime firstSampleTime, final Integer timelineLengthMillis) { this.timelineLengthMillis = timelineLengthMillis; this.backgroundWriter = backgroundWriter; this.timelineCoder = timelineCoder; this.sampleCoder = sampleCoder; this.sourceId = sourceId; this.eventCategoryId = eventCategoryId; // Set the end-of-chunk time by tossing a random number, to evenly distribute the db writeback // load. this.chunkEndTime = timelineLengthMillis != null ? firstSampleTime.plusMillis(rand.nextInt(timelineLengthMillis)) : null; }
/** * 计算指定时间之后的日期 * * @param date 待计算时间 * @param random 待计算数 * @param timeType 时间类型枚举 * @see org.codingsills.modules.utils.DateKit.TimeType * @return Date */ public static Date nextDate(Date date, int random, TimeType timeType) { Date nextDate = null; if (date == null) { return nextDate; } DateTime dateTime = fromDate(date); random = Math.abs(random); switch (timeType.getCode()) { case "Y": nextDate = dateTime.plusYears(random).toDate(); break; case "M": nextDate = dateTime.plusMonths(random).toDate(); break; case "W": nextDate = dateTime.plusWeeks(random).toDate(); break; case "D": nextDate = dateTime.plusDays(random).toDate(); break; case "H": nextDate = dateTime.plusHours(random).toDate(); break; case "MIN": nextDate = dateTime.plusMinutes(random).toDate(); break; case "S": nextDate = dateTime.plusSeconds(random).toDate(); break; case "MS": nextDate = dateTime.plusMillis(random).toDate(); break; default: break; } return nextDate; }
@SuppressWarnings("unchecked") // TODO - we can probably do better than synchronize the whole method public synchronized void addSourceSamples(final SourceSamplesForTimestamp samples) { final DateTime timestamp = samples.getTimestamp(); if (chunkEndTime != null && chunkEndTime.isBefore(timestamp)) { extractAndQueueTimelineChunks(); startTime = timestamp; chunkEndTime = timestamp.plusMillis(timelineLengthMillis); } if (startTime == null) { startTime = timestamp; } if (endTime == null) { endTime = timestamp; } else if (!timestamp.isAfter(endTime)) { log.warn( "Adding samples for host {}, timestamp {} is not after the end time {}; ignored", new Object[] {sourceId, dateFormatter.print(timestamp), dateFormatter.print(endTime)}); return; } sampleSequenceNumber++; latestSampleAddTime = new DateTime(); for (final Map.Entry<Integer, ScalarSample> entry : samples.getSamples().entrySet()) { final Integer metricId = entry.getKey(); final SampleSequenceNumber counter = metricIdCounters.get(metricId); if (counter != null) { counter.setSequenceNumber(sampleSequenceNumber); } else { metricIdCounters.put(metricId, new SampleSequenceNumber(sampleSequenceNumber)); } final ScalarSample sample = entry.getValue(); TimelineChunkAccumulator timeline = timelines.get(metricId); if (timeline == null) { timeline = new TimelineChunkAccumulator(sourceId, metricId, sampleCoder); if (sampleCount > 0) { addPlaceholders(timeline, sampleCount); } timelines.put(metricId, timeline); } final ScalarSample compressedSample = sampleCoder.compressSample(sample); timeline.addSample(compressedSample); } for (final Map.Entry<Integer, SampleSequenceNumber> entry : metricIdCounters.entrySet()) { final SampleSequenceNumber counter = entry.getValue(); if (counter.getSequenceNumber() < sampleSequenceNumber) { counter.setSequenceNumber(sampleSequenceNumber); final int metricId = entry.getKey(); final TimelineChunkAccumulator timeline = timelines.get(metricId); timeline.addSample(nullSample); } } // Now we can update the state endTime = timestamp; sampleCount++; times.add(timestamp); if (checkEveryAccess) { checkSampleCounts(sampleCount); } }
private static RubyTime createTime(IRubyObject recv, IRubyObject[] args, boolean gmt) { Ruby runtime = recv.getRuntime(); int len = ARG_SIZE; Boolean isDst = null; DateTimeZone dtz; if (gmt) { dtz = DateTimeZone.UTC; } else if (args.length == 10 && args[9] instanceof RubyString) { dtz = getTimeZone(runtime, ((RubyString) args[9]).toString()); } else { dtz = getLocalTimeZone(runtime); } if (args.length == 10) { if (args[8] instanceof RubyBoolean) { isDst = ((RubyBoolean) args[8]).isTrue(); } args = new IRubyObject[] { args[5], args[4], args[3], args[2], args[1], args[0], runtime.getNil() }; } else { // MRI accepts additional wday argument which appears to be ignored. len = args.length; if (len < ARG_SIZE) { IRubyObject[] newArgs = new IRubyObject[ARG_SIZE]; System.arraycopy(args, 0, newArgs, 0, args.length); for (int i = len; i < ARG_SIZE; i++) { newArgs[i] = runtime.getNil(); } args = newArgs; len = ARG_SIZE; } } if (args[0] instanceof RubyString) { args[0] = RubyNumeric.str2inum(runtime, (RubyString) args[0], 10, false); } int year = (int) RubyNumeric.num2long(args[0]); int month = 1; if (len > 1) { if (!args[1].isNil()) { IRubyObject tmp = args[1].checkStringType(); if (!tmp.isNil()) { String monthString = tmp.toString().toLowerCase(); Integer monthInt = MONTHS_MAP.get(monthString); if (monthInt != null) { month = monthInt; } else { try { month = Integer.parseInt(monthString); } catch (NumberFormatException nfExcptn) { throw runtime.newArgumentError("Argument out of range."); } } } else { month = (int) RubyNumeric.num2long(args[1]); } } if (1 > month || month > 12) { throw runtime.newArgumentError("Argument out of range: for month: " + month); } } int[] int_args = {1, 0, 0, 0, 0, 0}; for (int i = 0; int_args.length >= i + 2; i++) { if (!args[i + 2].isNil()) { if (!(args[i + 2] instanceof RubyNumeric)) { args[i + 2] = args[i + 2].callMethod(runtime.getCurrentContext(), "to_i"); } long value = RubyNumeric.num2long(args[i + 2]); if (time_min[i] > value || value > time_max[i]) { throw runtime.newArgumentError("argument out of range."); } int_args[i] = (int) value; } } if (!runtime.is1_9()) { if (0 <= year && year < 39) { year += 2000; } else if (69 <= year && year < 139) { year += 1900; } } DateTime dt; // set up with min values and then add to allow rolling over try { dt = new DateTime(year, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); dt = dt.plusMonths(month - 1) .plusDays(int_args[0] - 1) .plusHours(int_args[1]) .plusMinutes(int_args[2]) .plusSeconds(int_args[3]); if (runtime.is1_9() && !args[5].isNil()) { double millis = RubyFloat.num2dbl(args[5]); int int_millis = (int) (millis * 1000) % 1000; dt = dt.plusMillis(int_millis); } dt = dt.withZoneRetainFields(dtz); // we might need to perform a DST correction if (isDst != null) { // the instant at which we will ask dtz what the difference between DST and // standard time is long offsetCalculationInstant = dt.getMillis(); // if we might be moving this time from !DST -> DST, the offset is assumed // to be the same as it was just before we last moved from DST -> !DST if (dtz.isStandardOffset(dt.getMillis())) { offsetCalculationInstant = dtz.previousTransition(offsetCalculationInstant); } int offset = dtz.getStandardOffset(offsetCalculationInstant) - dtz.getOffset(offsetCalculationInstant); if (!isDst && !dtz.isStandardOffset(dt.getMillis())) { dt = dt.minusMillis(offset); } if (isDst && dtz.isStandardOffset(dt.getMillis())) { dt = dt.plusMillis(offset); } } } catch (org.joda.time.IllegalFieldValueException e) { throw runtime.newArgumentError("time out of range"); } RubyTime time = new RubyTime(runtime, (RubyClass) recv, dt); // Ignores usec if 8 args (for compatibility with parsedate) or if not supplied. if (args.length != 8 && !args[6].isNil()) { int usec = int_args[4] % 1000; int msec = int_args[4] / 1000; if (int_args[4] < 0) { msec -= 1; usec += 1000; } time.dt = dt.withMillis(dt.getMillis() + msec); time.setUSec(usec); } time.callInit(IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); return time; }
private double gScore(FakeNode node) { return node.node.cost.getCost( startTime.plusMillis((int) Math.round((currentNode.g_scores * 1000.0)))) + currentNode.g_scores; }
public synchronized DateTime addmillisecond() { systemDate = systemDate.plusMillis(1); return systemDate; }
public synchronized DateTime addmilliseconds(int milliseconds) { systemDate = systemDate.plusMillis(milliseconds); return systemDate; }