Search in sources :

Example 11 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter in project openhab1-addons by openhab.

the class SonosZonePlayer method snoozeAlarm.

public boolean snoozeAlarm(int minutes) {
    if (isAlarmRunning() && isConfigured()) {
        Service service = device.findService(new UDAServiceId("AVTransport"));
        Action action = service.getAction("SnoozeAlarm");
        ActionInvocation invocation = new ActionInvocation(action);
        Period snoozePeriod = Period.minutes(minutes);
        PeriodFormatter pFormatter = new PeriodFormatterBuilder().printZeroAlways().appendHours().appendSeparator(":").appendMinutes().appendSeparator(":").appendSeconds().toFormatter();
        try {
            invocation.setInput("Duration", pFormatter.print(snoozePeriod));
        } catch (InvalidValueException ex) {
            logger.error("Action Invalid Value Exception {}", ex.getMessage());
        } catch (NumberFormatException ex) {
            logger.error("Action Invalid Value Format Exception {}", ex.getMessage());
        }
        executeActionInvocation(invocation);
        return true;
    } else {
        logger.warn("There is no alarm running on {} ", this);
        return false;
    }
}
Also used : InvalidValueException(org.teleal.cling.model.types.InvalidValueException) Action(org.teleal.cling.model.meta.Action) PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) Period(org.joda.time.Period) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Example 12 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter in project opennms by OpenNMS.

the class NewtsConverter method main.

/**
 * The main method.
 *
 * @param args the arguments
 */
public static void main(final String... args) {
    final long start;
    try (final NewtsConverter converter = new NewtsConverter(args)) {
        start = System.currentTimeMillis();
        converter.execute();
    } catch (final NewtsConverterError e) {
        LOG.error(e.getMessage(), e);
        System.exit(1);
        throw null;
    }
    final Period period = new Interval(start, System.currentTimeMillis()).toPeriod();
    final PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix(" days ").appendHours().appendSuffix(" hours ").appendMinutes().appendSuffix(" min ").appendSeconds().appendSuffix(" sec ").printZeroNever().toFormatter();
    LOG.info("Conversion Finished: metrics: {}, samples: {}, time: {}", processedMetrics, processedSamples, formatter.print(period));
    System.exit(0);
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Period(org.joda.time.Period) Interval(org.joda.time.Interval)

Example 13 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter in project knox by apache.

the class DefaultHttpClientFactory method parseTimeout.

private static long parseTimeout(String s) {
    PeriodFormatter f = new PeriodFormatterBuilder().appendMinutes().appendSuffix("m", " min").appendSeconds().appendSuffix("s", " sec").appendMillis().toFormatter();
    Period p = Period.parse(s, f);
    return p.toStandardDuration().getMillis();
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Period(org.joda.time.Period)

Example 14 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter in project knox by apache.

the class GatewayConfigImpl method getGatewayDeploymentsBackupAgeLimit.

@Override
public long getGatewayDeploymentsBackupAgeLimit() {
    PeriodFormatter f = new PeriodFormatterBuilder().appendDays().toFormatter();
    String s = get(DEPLOYMENTS_BACKUP_AGE_LIMIT, "-1");
    long d;
    try {
        Period p = Period.parse(s, f);
        d = p.toStandardDuration().getMillis();
        if (d < 0) {
            d = -1;
        }
    } catch (Exception e) {
        d = -1;
    }
    return d;
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Period(org.joda.time.Period) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException)

Example 15 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter in project incubator-gobblin by apache.

the class RecompactionConditionTest method testRecompactionConditionBasedOnDuration.

@Test
public void testRecompactionConditionBasedOnDuration() {
    RecompactionConditionFactory factory = new RecompactionConditionBasedOnDuration.Factory();
    RecompactionCondition conditionBasedOnDuration = factory.createRecompactionCondition(dataset);
    DatasetHelper helper = mock(DatasetHelper.class);
    when(helper.getDataset()).thenReturn(dataset);
    PeriodFormatter periodFormatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays().appendSuffix("d").appendHours().appendSuffix("h").appendMinutes().appendSuffix("min").toFormatter();
    DateTime currentTime = getCurrentTime();
    Period period_A = periodFormatter.parsePeriod("11h59min");
    DateTime earliest_A = currentTime.minus(period_A);
    when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_A));
    when(helper.getCurrentTime()).thenReturn(currentTime);
    Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), false);
    Period period_B = periodFormatter.parsePeriod("12h01min");
    DateTime earliest_B = currentTime.minus(period_B);
    when(helper.getEarliestLateFileModificationTime()).thenReturn(Optional.of(earliest_B));
    when(helper.getCurrentTime()).thenReturn(currentTime);
    Assert.assertEquals(conditionBasedOnDuration.isRecompactionNeeded(helper), true);
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) LoggerFactory(org.slf4j.LoggerFactory) RecompactionConditionFactory(org.apache.gobblin.compaction.conditions.RecompactionConditionFactory) Period(org.joda.time.Period) RecompactionCondition(org.apache.gobblin.compaction.conditions.RecompactionCondition) RecompactionConditionFactory(org.apache.gobblin.compaction.conditions.RecompactionConditionFactory) DatasetHelper(org.apache.gobblin.compaction.dataset.DatasetHelper) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

PeriodFormatter (org.joda.time.format.PeriodFormatter)22 PeriodFormatterBuilder (org.joda.time.format.PeriodFormatterBuilder)15 Period (org.joda.time.Period)13 DateTime (org.joda.time.DateTime)7 Duration (org.joda.time.Duration)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)2 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)2 ExpressionProcessor (org.akaza.openclinica.domain.rule.expression.ExpressionProcessor)2 MalformedURLException (java.net.MalformedURLException)1 UnknownHostException (java.net.UnknownHostException)1 MessageFormat (java.text.MessageFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Matcher (java.util.regex.Matcher)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1