Java Code Examples for org.joda.time.Duration#getStandardMinutes()
The following examples show how to use
org.joda.time.Duration#getStandardMinutes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateUtils.java From xmu-2016-MrCode with GNU General Public License v2.0 | 6 votes |
/** * 获得两个时间点之间的时间跨度 * * @param time1 * 开始的时间点 * @param time2 * 结束的时间点 * @param timeUnit * 跨度的时间单位 see {@link JodaTime} * (支持的时间单位有DAY,HOUR,MINUTE,SECOND,MILLI) */ public static long lengthBetween(DateTime time1, DateTime time2, DurationFieldType timeUnit) { Duration duration = Days.daysBetween(time1, time2).toStandardDuration(); if (timeUnit == JodaTime.DAY) { return duration.getStandardDays(); } else if (timeUnit == JodaTime.HOUR) { return duration.getStandardHours(); } else if (timeUnit == JodaTime.MINUTE) { return duration.getStandardMinutes(); } else if (timeUnit == JodaTime.SECOND) { return duration.getStandardSeconds(); } else if (timeUnit == JodaTime.MILLI) { return duration.getMillis(); } else { throw new RuntimeException( "TimeUnit not supported except DAY,HOUR,MINUTE,SECOND,MILLI"); } }
Example 2
Source File: DateUtils.java From joda-time-android with Apache License 2.0 | 6 votes |
/** * Return given duration in a human-friendly format. For example, "4 * minutes" or "1 second". Returns only largest meaningful unit of time, * from seconds up to hours. * * The longest duration it supports is hours. * * This method assumes that there are 60 minutes in an hour, * 60 seconds in a minute and 1000 milliseconds in a second. * All currently supplied chronologies use this definition. */ public static CharSequence formatDuration(Context context, ReadableDuration readableDuration) { Resources res = context.getResources(); Duration duration = readableDuration.toDuration(); final int hours = (int) duration.getStandardHours(); if (hours != 0) { return res.getQuantityString(R.plurals.joda_time_android_duration_hours, hours, hours); } final int minutes = (int) duration.getStandardMinutes(); if (minutes != 0) { return res.getQuantityString(R.plurals.joda_time_android_duration_minutes, minutes, minutes); } final int seconds = (int) duration.getStandardSeconds(); return res.getQuantityString(R.plurals.joda_time_android_duration_seconds, seconds, seconds); }
Example 3
Source File: ConfigSupport.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Convert duration to an representation accepted by Configuration parser. * @param duration A duration. * @return A StringBuilder with the string representation of the duration. */ public static StringBuilder durationConfigString(Duration duration) { Duration remainder = duration; long days = remainder.getStandardDays(); remainder = remainder.minus(Duration.standardDays(days)); long hours = remainder.getStandardHours(); remainder = remainder.minus(Duration.standardHours(hours)); long minutes = remainder.getStandardMinutes(); remainder = remainder.minus(Duration.standardMinutes(minutes)); long seconds = remainder.getStandardSeconds(); remainder = remainder.minus(Duration.standardSeconds(seconds)); if (!remainder.isEqual(Duration.ZERO)) Logger.getLogger(ConfigSupport.class.getName()).log(Level.WARNING, "Duration is more precise than configuration will handle: {0}, dropping remainder: {1}", new Object[]{duration, remainder}); StringBuilder result = new StringBuilder(); if (days != 0) { if (result.length() != 0) result.append(' '); result.append(days).append('d'); } if (hours != 0) { if (result.length() != 0) result.append(' '); result.append(hours).append('h'); } if (minutes != 0) { if (result.length() != 0) result.append(' '); result.append(minutes).append('m'); } if (result.length() == 0 || seconds != 0) { if (result.length() != 0) result.append(' '); result.append(seconds).append('s'); } return result; }
Example 4
Source File: Output.java From helios with Apache License 2.0 | 5 votes |
public static String humanDuration(final Duration dur) { final Period p = dur.toPeriod().normalizedStandard(); if (dur.getStandardSeconds() == 0) { return "0 seconds"; } else if (dur.getStandardSeconds() < 60) { return format("%d second%s", p.getSeconds(), p.getSeconds() > 1 ? "s" : ""); } else if (dur.getStandardMinutes() < 60) { return format("%d minute%s", p.getMinutes(), p.getMinutes() > 1 ? "s" : ""); } else if (dur.getStandardHours() < 24) { return format("%d hour%s", p.getHours(), p.getHours() > 1 ? "s" : ""); } else { return format("%d day%s", dur.getStandardDays(), dur.getStandardDays() > 1 ? "s" : ""); } }
Example 5
Source File: PluginDateUtils.java From template-compiler with Apache License 2.0 | 4 votes |
public static void humanizeDate(long instantMs, long baseMs, String tzId, boolean showSeconds, StringBuilder buf) { DateTimeZone timeZone = DateTimeZone.forID(tzId); int offset = timeZone.getOffset(instantMs); Duration delta = new Duration(baseMs - instantMs + offset); int days = (int)delta.getStandardDays(); int years = (int)Math.floor(days / 365.0); if (years > 0) { humanizeDatePlural(years, DatePartType.YEAR, buf); return; } int months = (int)Math.floor(days / 30.0); if (months > 0) { humanizeDatePlural(months, DatePartType.MONTH, buf); return; } int weeks = (int)Math.floor(days / 7.0); if (weeks > 0) { humanizeDatePlural(weeks, DatePartType.WEEK, buf); return; } if (days > 0) { humanizeDatePlural(days, DatePartType.DAY, buf); return; } int hours = (int)delta.getStandardHours(); if (hours > 0) { humanizeDatePlural(hours, DatePartType.HOUR, buf); return; } int mins = (int)delta.getStandardMinutes(); if (mins > 0) { humanizeDatePlural(mins, DatePartType.MINUTE, buf); return; } int secs = (int)delta.getStandardSeconds(); if (showSeconds) { humanizeDatePlural(secs, DatePartType.SECOND, buf); return; } buf.append("less than a minute ago"); }