List of usage examples for org.joda.time Period toStandardHours
public Hours toStandardHours()
From source file:com.gmt2001.YouTubeAPIv3.java
License:Open Source License
public int[] GetVideoLength(String id) { com.gmt2001.Console.debug.println("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")); if (cd.getString("duration").equalsIgnoreCase("PT0S")) { com.gmt2001.Console.debug.println("YouTubeAPIv3.GetVideoLength Fail (Live Stream)"); return new int[] { 123, 456, 7899 }; }//from www . ja va2 s.com //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"))); */ com.gmt2001.Console.debug.println("YouTubeAPIv3.GetVideoLength Success"); return new int[] { h, m, s }; } else { com.gmt2001.Console.debug.println("YouTubeAPIv3.GetVideoLength Fail"); return new int[] { 0, 0, 0 }; } } else { com.gmt2001.Console.debug.println("YouTubeAPIv3.GetVideoLength Fail2"); return new int[] { 0, 0, 0 }; } } com.gmt2001.Console.debug.println("YouTubeAPIv3.GetVideoLength Fail3"); return new int[] { 0, 0, 0 }; }
From source file:com.mirth.connect.server.util.LoginRequirementsChecker.java
License:Open Source License
public String getPrintableGraceTimeRemaining(long graceTimeRemaining) { Period period = new Period(graceTimeRemaining); PeriodFormatter periodFormatter;/*from w w w. j ava 2 s . c o m*/ if (period.toStandardHours().getHours() > 0) { periodFormatter = new PeriodFormatterBuilder().printZeroRarelyFirst().appendDays() .appendSuffix(" day", " days").appendSeparator(" and ").printZeroAlways().appendHours() .appendSuffix(" hour", " hours").toFormatter(); } else { periodFormatter = new PeriodFormatterBuilder().printZeroNever().appendMinutes() .appendSuffix(" minute", " minutes").appendSeparator(" and ").printZeroAlways().appendSeconds() .appendSuffix(" second", " seconds").toFormatter(); } return periodFormatter.print(period); }
From source file:com.thinkbiganalytics.scheduler.util.TimerToCronExpression.java
License:Apache License
private static String getHoursCron(Period p) { Integer hrs = p.getHours();/*from w w w . j a v a 2 s. c o m*/ Hours h = p.toStandardHours(); Integer hours = h.getHours(); String str = "0" + (hrs > 0 ? "/" + hrs : ""); if (hours > 24) { str = hrs + ""; } return str; }
From source file:de.azapps.mirakel.sync.taskwarrior.model.TaskWarriorTaskSerializer.java
License:Open Source License
public static void handleRecurrence(final JsonObject json, final Recurring r) { if (r == null) { Log.wtf(TAG, "recurring is null"); return;/*from w w w.j ava 2s . c o m*/ } if (!r.getWeekdays().isEmpty()) { switch (r.getWeekdays().size()) { case 1: json.addProperty("recur", "weekly"); return; case 7: json.addProperty("recur", "daily"); return; case 5: final List<Integer> weekdays = r.getWeekdays(); for (Integer i = DateTimeConstants.MONDAY; i <= DateTimeConstants.FRIDAY; i++) { if (!weekdays.contains(i)) { Log.w(TAG, "unsupported recurrence"); return; } } json.addProperty("recur", "weekdays"); return; default: Log.w(TAG, "unsupported recurrence"); return; } } final long interval = r.getIntervalMs() / (1000L * 60L); if (interval > 0L) { Period p = r.getInterval(); if (r.getInterval().getMinutes() > 0) { json.addProperty("recur", p.toStandardMinutes().getMinutes() + "mins"); } else if (r.getInterval().getHours() > 0) { json.addProperty("recur", p.toStandardHours().getHours() + "hours"); } else if (r.getInterval().getDays() > 0) { json.addProperty("recur", p.toStandardDays().getDays() + "days"); } else if (r.getInterval().getWeeks() > 0) { json.addProperty("recur", p.toStandardWeeks().getWeeks() + "weeks"); } else if (r.getInterval().getMonths() > 0) { json.addProperty("recur", p.getMonths() + (12 * p.getYears()) + "months"); } else { json.addProperty("recur", p.getYears() + "years"); } } }
From source file:org.projectbuendia.client.utils.RelativeDateTimeFormatter.java
License:Apache License
/** Formats a representation of {@code dateTime} relative to {@code anchor}. */ public String format(DateTime dateTime, DateTime anchor) { if (dateTime.isAfter(anchor)) { return "in the future"; // TODO/i18n }//from ww w . j a v a 2 s. co m Period period = new Period(dateTime, anchor); int daysAgo = period.toStandardDays().getDays(); int hoursAgo = period.toStandardHours().getHours(); int minutesAgo = period.toStandardMinutes().getMinutes(); return daysAgo > 1 ? daysAgo + " days ago" : // TODO/i18n hoursAgo > 1 ? hoursAgo + " hours ago" : // TODO/i18n minutesAgo > 1 ? minutesAgo + " min ago" : // TODO/i18n "right now"; // TODO/i18n }