/** * Converts this duration to a period in seconds assuming that there are the * standard number of milliseconds in a second. * <p> * This method assumes that there are 1000 milliseconds in a second. * All currently supplied chronologies use this definition. * * @return a period representing the number of standard seconds in this period, never null * @throws ArithmeticException if the number of seconds is too large to be represented * @since 1.6 */ public Seconds toStandardSeconds() { long seconds = getStandardSeconds(); return Seconds.seconds(FieldUtils.safeToInt(seconds)); }
/** * Converts this duration to a period in seconds assuming that there are the * standard number of milliseconds in a second. * <p> * This method assumes that there are 1000 milliseconds in a second. * All currently supplied chronologies use this definition. * * @return a period representing the number of standard seconds in this period, never null * @throws ArithmeticException if the number of seconds is too large to be represented * @since 1.6 */ public Seconds toStandardSeconds() { long seconds = getStandardSeconds(); return Seconds.seconds(FieldUtils.safeToInt(seconds)); }
/** * Converts a string representing a period/duration to corresponding milliseconds. * For ex, input "1d" would return 86400000L. Supported units are days (d), hours (h), * minutes (m) and seconds (s). * * @param timeStr string representing the duration * @return the corresponding time coverted to milliseconds * @throws IllegalArgumentException if the string does not conform to the expected format */ public static Long convertPeriodToMillis(String timeStr) { Long millis = 0L; if (timeStr != null) { try { Period p = PERIOD_FORMATTER.parsePeriod(timeStr); millis = p.toStandardDuration().getStandardSeconds() * 1000L; } catch (IllegalArgumentException e) { // rethrowing with more contextual information throw new IllegalArgumentException("Invalid time spec '" + timeStr + "' (Valid examples: '3h', '4h30m')", e); } } return millis; }
String creationTimeStr = _creationTime != Long.MIN_VALUE ? dateFormat.format(new Date(_creationTime)) : null; segmentMetadata.put("creationTimeReadable", creationTimeStr); segmentMetadata.put("timeGranularitySec", _timeGranularity != null ? _timeGranularity.getStandardSeconds() : null); if (_timeInterval == null) { segmentMetadata.set("startTimeMillis", null);
public static String humanDuration(final Duration dur) { final Period p = dur.toPeriod().normalizedStandard(); if (dur.getStandardSeconds() == 0) { return "0 seconds"; } else if (dur.getStandardSeconds() < 60) { return format("%d second%s", p.getSeconds(), p.getSeconds() > 1 ? "s" : ""); } else if (dur.getStandardMinutes() < 60) { return format("%d minute%s", p.getMinutes(), p.getMinutes() > 1 ? "s" : ""); } else if (dur.getStandardHours() < 24) { return format("%d hour%s", p.getHours(), p.getHours() > 1 ? "s" : ""); } else { return format("%d day%s", dur.getStandardDays(), dur.getStandardDays() > 1 ? "s" : ""); } }
this.sidecarConfiguration.sidecarUpdateInterval().toStandardDuration().getStandardSeconds(), this.sidecarConfiguration.sidecarSendStatus()), this.sidecarConfiguration.sidecarConfigurationOverride(),
/** * Return given duration in a human-friendly format. For example, "4 * minutes" or "1 second". Returns only largest meaningful unit of time, * from seconds up to hours. * * The longest duration it supports is hours. * * This method assumes that there are 60 minutes in an hour, * 60 seconds in a minute and 1000 milliseconds in a second. * All currently supplied chronologies use this definition. */ public static CharSequence formatDuration(Context context, ReadableDuration readableDuration) { Resources res = context.getResources(); Duration duration = readableDuration.toDuration(); final int hours = (int) duration.getStandardHours(); if (hours != 0) { return res.getQuantityString(R.plurals.joda_time_android_duration_hours, hours, hours); } final int minutes = (int) duration.getStandardMinutes(); if (minutes != 0) { return res.getQuantityString(R.plurals.joda_time_android_duration_minutes, minutes, minutes); } final int seconds = (int) duration.getStandardSeconds(); return res.getQuantityString(R.plurals.joda_time_android_duration_seconds, seconds, seconds); }
tuningConfig.getChatRetries() * (tuningConfig.getHttpTimeout().getStandardSeconds() + IndexTaskClient.MAX_RETRY_WAIT_SECONDS) );
@Override public long getAllTimeRate() { Duration sinceStart = new Duration(start, new DateTime()); if (sinceStart.getStandardSeconds() == 0) { return 0; } return allTimeCounter.getValue() / sinceStart.getStandardSeconds(); }
@Override public long getAllTimeRate() { Duration sinceStart = new Duration(start, getNow()); if (sinceStart.getStandardSeconds() == 0) { return 0; } return allTimeCounter.getValue() / sinceStart.getStandardSeconds(); }
@Override public long getValue() { Duration periodSize = getPeriodSize(); if (periodSize.getStandardSeconds() == 0) { return 0; } return counter.getValue() / periodSize.getStandardSeconds(); }
public String evaluate(String dateString, String dateFormat, String periodString) { if (dateString == null) { return null; } if (dateFormat == null) { dateFormat = "YYYY-MM-dd HH:mm:ss"; } DateTimeFormatter dateFormatter = org.joda.time.format.DateTimeFormat.forPattern(dateFormat); DateTime input = dateFormatter.parseDateTime(dateString); Duration duration = periodFormatter.parsePeriod(periodString).toStandardDuration(); long seconds = duration.getStandardSeconds(); DateTime output = input.plusSeconds(Long.valueOf(seconds).intValue()); return dateFormatter.print(output); } }
/** * Converts this duration to a period in seconds assuming that there are the * standard number of milliseconds in a second. * <p> * This method assumes that there are 1000 milliseconds in a second. * All currently supplied chronologies use this definition. * * @return a period representing the number of standard seconds in this period, never null * @throws ArithmeticException if the number of seconds is too large to be represented * @since 1.6 */ public Seconds toStandardSeconds() { long seconds = getStandardSeconds(); return Seconds.seconds(FieldUtils.safeToInt(seconds)); }
private long calcRate(EventCounterIf<GaugeCounter> counter) { long value = counter.getValue(); ReadableDateTime end = counter.getEnd(); ReadableDateTime start = counter.getStart(); ReadableDateTime now = new DateTime(); Duration duration = now.isBefore(end) ? new Duration(start, now) : // so far new Duration(start, end); long secs = duration.getStandardSeconds(); return secs > 0 ? value / secs : value; }
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { _name = name; _params = params; String value = (String)params.get("ssh.sleep"); _sleep = NumbersUtil.parseInt(value, 10) * 1000; value = (String)params.get("ssh.retry"); _retry = NumbersUtil.parseInt(value, 36); value = (String)params.get("ssh.port"); _port = NumbersUtil.parseInt(value, 3922); value = (String)params.get("router.aggregation.command.each.timeout"); _eachTimeout = Duration.standardSeconds(NumbersUtil.parseInt(value, (int)VRScripts.VR_SCRIPT_EXEC_TIMEOUT.getStandardSeconds())); if (s_logger.isDebugEnabled()){ s_logger.debug("The router.aggregation.command.each.timeout in seconds is set to " + _eachTimeout.getStandardSeconds()); } if (_vrDeployer == null) { throw new ConfigurationException("Unable to find the resource for VirtualRouterDeployer!"); } _vrAggregateCommandsSet = new HashMap<>(); return true; }
&& timeOut.getStandardSeconds() > 0L && (timeOut.compareTo(DEFAULT_MAX_TIMEOUT) <= 0) && executor != null); retVal = processFuture.get(timeOut.getStandardSeconds(), TimeUnit.SECONDS); } catch (ExecutionException e) { retVal = -2;
@Override public Boolean checkingHB() { Script cmd = new Script(vmActivityCheckPath, activityScriptTimeout.getStandardSeconds(), LOG); cmd.add("-i", nfsStoragePool._poolIp); cmd.add("-p", nfsStoragePool._poolMountSourcePath); cmd.add("-m", nfsStoragePool._mountDestPath); cmd.add("-h", hostIP); cmd.add("-u", volumeUuidList); cmd.add("-t", String.valueOf(String.valueOf(System.currentTimeMillis() / 1000))); cmd.add("-d", String.valueOf(suspectTimeInSeconds)); OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser(); String result = cmd.execute(parser); LOG.debug("KVMHAVMActivityChecker pool: " + nfsStoragePool._poolIp); LOG.debug("KVMHAVMActivityChecker result: " + result); LOG.debug("KVMHAVMActivityChecker parser: " + parser.getLine()); if (result == null && parser.getLine().contains("DEAD")) { return false; } else { return true; } }
ScriptConfigItem scriptConfigItem = new ScriptConfigItem(VRScripts.VR_CFG, "-c " + VRScripts.CONFIG_CACHE_LOCATION + cfgFileName); Duration timeout = _eachTimeout.withDurationAdded(_eachTimeout.getStandardSeconds(), answerCounts); if (s_logger.isDebugEnabled()){ s_logger.debug("Aggregate action timeout in seconds is " + timeout.getStandardSeconds());
client.setValidateServerHttpsCertificate(false); client.setShouldRequestsExpire(false); client.setConnectionTimeout((int) cmd.getTimeout().getStandardSeconds());
@Test(groups = "fast") public void testRateAndSum() throws Exception { int expectedRatePerSecond = 10; int numHours = 2; long totalSeconds = Duration.standardHours(numHours).getStandardSeconds(); long expectedTotal = totalSeconds * expectedRatePerSecond; TimeUtil.setNow(new DateTime("2012-01-01")); // generate rate using second granularity for (int i = 0; i < totalSeconds; i++) { stats.incrementRate("rate1", expectedRatePerSecond); TimeUtil.advanceNow(Duration.standardSeconds(1)); } assertCounterValue("rate1.sum.60", 60 * expectedRatePerSecond); assertCounterValue("rate1.sum.600", 600 * expectedRatePerSecond); assertCounterValue("rate1.sum.3600", 3600 * expectedRatePerSecond); assertCounterValue("rate1.sum", expectedTotal); assertCounterValue("rate1.rate.60", expectedRatePerSecond); assertCounterValue("rate1.rate.600", expectedRatePerSecond); assertCounterValue("rate1.rate.3600", expectedRatePerSecond); assertCounterValue("rate1.rate", expectedRatePerSecond); }