use of org.joda.time.Duration in project service-proxy by membrane.
the class AMRateLimiter method fillPolicyCleanupTimes.
private void fillPolicyCleanupTimes() {
policyRateLimits.clear();
for (Policy policy : amc.getPolicies().values()) {
String name = policy.getName();
int requests = policy.getRateLimit().getRequests();
Duration interval = Duration.standardSeconds(policy.getRateLimit().getInterval());
HashSet<String> services = new HashSet<String>(policy.getServiceProxies());
PolicyRateLimit prl = new PolicyRateLimit();
prl.setName(name);
prl.setRequests(requests);
prl.setInterval(interval);
prl.setServices(services);
prl.incrementNextCleanup();
policyRateLimits.put(name, prl);
}
}
use of org.joda.time.Duration in project substitution-schedule-parser by vertretungsplanme.
the class ParserUtils method parseDate.
static LocalDate parseDate(String string) {
if (string == null)
return null;
reinitIfNeeded();
string = string.replace("Stand:", "").replace("Import:", "").replaceAll(", Woche [A-Z]", "").trim();
int i = 0;
for (DateTimeFormatter f : dateFormatters) {
try {
LocalDate d = f.parseLocalDate(string);
if (dateFormats[i].contains("yyyy")) {
return d;
} else {
Duration currentYearDifference = abs(new Duration(DateTime.now(), d.toDateTimeAtCurrentTime()));
Duration lastYearDifference = abs(new Duration(DateTime.now(), d.minusYears(1).toDateTimeAtCurrentTime()));
Duration nextYearDifference = abs(new Duration(DateTime.now(), d.plusYears(1).toDateTimeAtCurrentTime()));
if (lastYearDifference.isShorterThan(currentYearDifference)) {
return DateTimeFormat.forPattern(dateFormats[i]).withLocale(Locale.GERMAN).withDefaultYear(f.getDefaultYear() - 1).parseLocalDate(string);
} else if (nextYearDifference.isShorterThan(currentYearDifference)) {
return DateTimeFormat.forPattern(dateFormats[i]).withLocale(Locale.GERMAN).withDefaultYear(f.getDefaultYear() + 1).parseLocalDate(string);
} else {
return d;
}
}
} catch (IllegalArgumentException e) {
// Does not match this format, try the next one
}
i++;
}
// Does not match any known format :(
return null;
}
use of org.joda.time.Duration in project watchdog by TestRoots.
the class IntervalBase method getDurationString.
/**
* @return A human-readable duration.
*/
public String getDurationString() {
Duration duration = getDuration();
Period period = duration.toPeriod();
return PeriodFormat.getDefault().print(period);
}
use of org.joda.time.Duration in project molgenis by molgenis.
the class ProgressImpl method success.
@Override
public void success() {
jobExecution.setEndDate(Instant.now());
jobExecution.setStatus(SUCCESS);
jobExecution.setProgressInt(jobExecution.getProgressMax());
Duration yourDuration = Duration.millis(timeRunning());
Period period = yourDuration.toPeriod();
PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d ").appendHours().appendSuffix("h ").appendMinutes().appendSuffix("m ").appendSeconds().appendSuffix("s ").appendMillis().appendSuffix("ms ").toFormatter();
String timeSpent = periodFormatter.print(period);
JOB_EXECUTION_LOG.info("Execution successful. Time spent: {}", timeSpent);
sendEmail(jobExecution.getSuccessEmail(), jobExecution.getType() + " job succeeded.", jobExecution.getLog());
update();
JobExecutionContext.unset();
}
use of org.joda.time.Duration in project graylog2-server by Graylog2.
the class AdditionExpression method evaluateUnsafe.
@Nullable
@Override
public Object evaluateUnsafe(EvaluationContext context) {
final Object leftValue = left.evaluateUnsafe(context);
final Object rightValue = right.evaluateUnsafe(context);
// special case for date arithmetic
final boolean leftDate = DateTime.class.equals(leftValue.getClass());
final boolean leftPeriod = Period.class.equals(leftValue.getClass());
final boolean rightDate = DateTime.class.equals(rightValue.getClass());
final boolean rightPeriod = Period.class.equals(rightValue.getClass());
if (leftDate && rightPeriod) {
final DateTime date = (DateTime) leftValue;
final Period period = (Period) rightValue;
return isPlus() ? date.plus(period) : date.minus(period);
} else if (leftPeriod && rightDate) {
final DateTime date = (DateTime) rightValue;
final Period period = (Period) leftValue;
return isPlus() ? date.plus(period) : date.minus(period);
} else if (leftPeriod && rightPeriod) {
final Period period1 = (Period) leftValue;
final Period period2 = (Period) rightValue;
return isPlus() ? period1.plus(period2) : period1.minus(period2);
} else if (leftDate && rightDate) {
// because adding two dates makes no sense
if (isPlus()) {
// makes no sense to compute and should be handles in the parser already
return null;
}
final DateTime left = (DateTime) leftValue;
final DateTime right = (DateTime) rightValue;
if (left.isBefore(right)) {
return new Duration(left, right);
} else {
return new Duration(right, left);
}
} else if (String.class.equals(type)) {
if (!isPlus) {
return null;
}
final String left = String.valueOf(leftValue);
final String right = String.valueOf(rightValue);
return left + right;
}
if (isIntegral()) {
final long l = (long) leftValue;
final long r = (long) rightValue;
if (isPlus) {
return l + r;
} else {
return l - r;
}
} else {
final double l = (double) leftValue;
final double r = (double) rightValue;
if (isPlus) {
return l + r;
} else {
return l - r;
}
}
}
Aggregations