Search in sources :

Example 1 with PeriodFormatterBuilder

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

the class SonosZonePlayer method updateAlarm.

public boolean updateAlarm(SonosAlarm alarm) {
    if (alarm != null && isConfigured()) {
        Service service = device.findService(new UDAServiceId("AlarmClock"));
        Action action = service.getAction("ListAlarms");
        ActionInvocation invocation = new ActionInvocation(action);
        DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm:ss");
        PeriodFormatter pFormatter = new PeriodFormatterBuilder().printZeroAlways().appendHours().appendSeparator(":").appendMinutes().appendSeparator(":").appendSeconds().toFormatter();
        try {
            invocation.setInput("ID", Integer.toString(alarm.getID()));
            invocation.setInput("StartLocalTime", formatter.print(alarm.getStartTime()));
            invocation.setInput("Duration", pFormatter.print(alarm.getDuration()));
            invocation.setInput("Recurrence", alarm.getRecurrence());
            invocation.setInput("RoomUUID", alarm.getRoomUUID());
            invocation.setInput("ProgramURI", alarm.getProgramURI());
            invocation.setInput("ProgramMetaData", alarm.getProgramMetaData());
            invocation.setInput("PlayMode", alarm.getPlayMode());
            invocation.setInput("Volume", Integer.toString(alarm.getVolume()));
            if (alarm.getIncludeLinkedZones()) {
                invocation.setInput("IncludeLinkedZones", "1");
            } else {
                invocation.setInput("IncludeLinkedZones", "0");
            }
            if (alarm.getEnabled()) {
                invocation.setInput("Enabled", "1");
            } else {
                invocation.setInput("Enabled", "0");
            }
        } 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 {
        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) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Example 2 with PeriodFormatterBuilder

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

the class GatewayConfigImpl method parseNetworkTimeout.

private static long parseNetworkTimeout(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 3 with PeriodFormatterBuilder

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

the class CompactionTimeRangeVerifier method verify.

public Result verify(FileSystemDataset dataset) {
    final DateTime earliest;
    final DateTime latest;
    try {
        CompactionPathParser.CompactionParserResult result = new CompactionPathParser(state).parse(dataset);
        DateTime folderTime = result.getTime();
        DateTimeZone timeZone = DateTimeZone.forID(this.state.getProp(MRCompactor.COMPACTION_TIMEZONE, MRCompactor.DEFAULT_COMPACTION_TIMEZONE));
        DateTime compactionStartTime = new DateTime(this.state.getPropAsLong(CompactionSource.COMPACTION_INIT_TIME), timeZone);
        PeriodFormatter formatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays().appendSuffix("d").appendHours().appendSuffix("h").toFormatter();
        // get earliest time
        String maxTimeAgoStr = this.state.getProp(TimeBasedSubDirDatasetsFinder.COMPACTION_TIMEBASED_MAX_TIME_AGO, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO);
        Period maxTimeAgo = formatter.parsePeriod(maxTimeAgoStr);
        earliest = compactionStartTime.minus(maxTimeAgo);
        // get latest time
        String minTimeAgoStr = this.state.getProp(TimeBasedSubDirDatasetsFinder.COMPACTION_TIMEBASED_MIN_TIME_AGO, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO);
        Period minTimeAgo = formatter.parsePeriod(minTimeAgoStr);
        latest = compactionStartTime.minus(minTimeAgo);
        if (earliest.isBefore(folderTime) && latest.isAfter(folderTime)) {
            log.debug("{} falls in the user defined time range", dataset.datasetRoot());
            return new Result(true, "");
        }
    } catch (Exception e) {
        log.error("{} cannot be verified because of {}", dataset.datasetRoot(), ExceptionUtils.getFullStackTrace(e));
        return new Result(false, e.toString());
    }
    return new Result(false, dataset.datasetRoot() + " is not in between " + earliest + " and " + latest);
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Period(org.joda.time.Period) CompactionPathParser(org.apache.gobblin.compaction.parser.CompactionPathParser) DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone)

Example 4 with PeriodFormatterBuilder

use of org.joda.time.format.PeriodFormatterBuilder 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();
}
Also used : PeriodFormatterBuilder(org.joda.time.format.PeriodFormatterBuilder) PeriodFormatter(org.joda.time.format.PeriodFormatter) Period(org.joda.time.Period) Duration(org.joda.time.Duration)

Example 5 with PeriodFormatterBuilder

use of org.joda.time.format.PeriodFormatterBuilder 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)

Aggregations

PeriodFormatterBuilder (org.joda.time.format.PeriodFormatterBuilder)16 PeriodFormatter (org.joda.time.format.PeriodFormatter)15 Period (org.joda.time.Period)10 DateTime (org.joda.time.DateTime)6 Duration (org.joda.time.Duration)5 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 PeriodParser (org.joda.time.format.PeriodParser)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