Search in sources :

Example 1 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter in project quorrabot by GloriousEggroll.

the class YouTubeAPIv3 method GetVideoLength.

public int[] GetVideoLength(String id) {
    if (Quorrabot.enableDebugging) {
        com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Start id=" + id);
    }
    JSONObject j = GetData(request_type.GET, "https://www.googleapis.com/youtube/v3/videos?id=" + id + "&key=" + apikey + "&part=contentDetails");
    if (j.getBoolean("_success")) {
        if (j.getInt("_http") == 200) {
            JSONArray a = j.getJSONArray("items");
            if (a.length() > 0) {
                JSONObject i = a.getJSONObject(0);
                JSONObject cd = i.getJSONObject("contentDetails");
                PeriodFormatter formatter = ISOPeriodFormat.standard();
                Period d = formatter.parsePeriod(cd.getString("duration"));
                //String d = cd.getString("duration").substring(2);
                int h, m, s;
                String hours = d.toStandardHours().toString().substring(2);
                h = Integer.parseInt(hours.substring(0, hours.indexOf("H")));
                String minutes = d.toStandardMinutes().toString().substring(2);
                m = Integer.parseInt(minutes.substring(0, minutes.indexOf("M")));
                String seconds = d.toStandardSeconds().toString().substring(2);
                s = Integer.parseInt(seconds.substring(0, seconds.indexOf("S")));
                /*
                     * if (d.contains("H")) { h =
                     * Integer.parseInt(d.substring(0, d.indexOf("H")));
                     *
                     * d = d.substring(0, d.indexOf("H")); }
                     *
                     * if (d.contains("M")) { m =
                     * Integer.parseInt(d.substring(0, d.indexOf("M")));
                     *
                     * d = d.substring(0, d.indexOf("M")); }
                     *
                     * s = Integer.parseInt(d.substring(0, d.indexOf("S")));
                     */
                if (Quorrabot.enableDebugging) {
                    com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Success");
                }
                return new int[] { h, m, s };
            } else {
                if (Quorrabot.enableDebugging) {
                    com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail");
                }
                return new int[] { 0, 0, 0 };
            }
        } else {
            if (Quorrabot.enableDebugging) {
                com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail2");
            }
            return new int[] { 0, 0, 0 };
        }
    }
    if (Quorrabot.enableDebugging) {
        com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail3");
    }
    return new int[] { 0, 0, 0 };
}
Also used : JSONObject(org.json.JSONObject) PeriodFormatter(org.joda.time.format.PeriodFormatter) JSONArray(org.json.JSONArray) Period(org.joda.time.Period)

Example 2 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter 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 3 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter 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 4 with PeriodFormatter

use of org.joda.time.format.PeriodFormatter 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 5 with PeriodFormatter

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

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