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 };
}
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;
}
}
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();
}
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);
}
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();
}
Aggregations