List of usage examples for org.joda.time Period Period
public Period(Object period)
From source file:com.cloudhopper.commons.util.demo.UptimeMain.java
License:Apache License
public static void main(String[] args) { //Period period = new Period(uptime, PeriodType.standard().withYearsRemoved().withWeeksRemoved().withMonthsRemoved().withMillisRemoved()); //MutablePeriod period = new Duration(uptime).toPeriod().toMutablePeriod(); long uptime = UPTIME_56_SECS; // ah, ha -- this is super important -- need to normalize the period! PeriodType periodType = PeriodType.standard().withYearsRemoved().withMonthsRemoved().withWeeksRemoved() .withMillisRemoved();/*from w w w.j a v a2 s . c o m*/ Period period = new Period(uptime).normalizedStandard(periodType); System.out.println("Uptime: " + uptime + " ms"); System.out.println("Weeks: " + period.getWeeks()); System.out.println("Days: " + period.getDays()); System.out.println("Millis: " + period.getMillis() + " ms"); // print out the uptime String uptimeStyleString = PeriodFormatterUtil.getStandardUptimeStyle().print(period); String linuxStyleString = PeriodFormatterUtil.getLinuxUptimeStyle().print(period); System.out.println(uptimeStyleString); System.out.println(linuxStyleString); PeriodFormatter fmt = new PeriodFormatterBuilder().printZeroNever().appendDays() .appendSuffix(" day ", " days ").appendHours().appendSuffix(" hours ").appendMinutes() .appendSuffix(" mins ").printZeroAlways().appendSeconds().appendSuffix(" secs ").toFormatter(); String str0 = fmt.print(period); System.out.println(str0); String str1 = PeriodFormat.getDefault().print(period); System.out.println(str1); }
From source file:com.cloudhopper.commons.util.PeriodFormatterUtil.java
License:Apache License
/** * Creates a new Period that can be used properly with the "Uptime" styles * returned by this utility class. This period normalizes the internal * fields to only include days, hours, minutes, and seconds. * @param durationInMillis The length of the duration in milliseconds * @return A new normalized Period//from w w w .j av a 2s. co m */ public static Period createDayHourMinSecPeriod(long durationInMillis) { return new Period(durationInMillis).normalizedStandard(dayHourMinSecPeriodType); }
From source file:com.cloudhopper.commons.util.TimedStateBoolean.java
License:Apache License
/** * Based on the time this method is called (System.currentTimeMillis), this * method returns a Period that represents the duration of time this value * has retained this value.//from w ww . j ava 2 s. c om * @see #getValueDurationInMills() */ public Period getValueDuration() { long now = System.currentTimeMillis(); return new Period(now - valueTime); }
From source file:com.enonic.cms.core.portal.livetrace.SimpleDuration.java
License:Open Source License
void setDurationInMilliseconds(long durationInMilliseconds) { this.durationInMilliseconds = durationInMilliseconds; this.durationAsHRFormat = HOURS_MINUTES_MILLIS.print(new Period(durationInMilliseconds)).trim(); }
From source file:com.enonic.cms.core.portal.livetrace.Traces.java
License:Open Source License
public String getTotalPeriodInHRFormat() { return hoursMinutesMillis.print(new Period(totalPeriodTimeInMilliseconds)); }
From source file:com.enonic.cms.core.tools.index.IndexMonitorController.java
License:Open Source License
private String getTimeUsedString() { final long lastReindexTimeUsed = reindexContentToolService.getLastReindexTimeUsed(); return HOURS_MINUTES_MILLIS.print(new Period(lastReindexTimeUsed)).trim(); }
From source file:com.ethercis.servicemanager.common.IsoDateJoda.java
License:Apache License
/** * Calculate the difference of given millis. * @param diffMillis The elapsed time/*from ww w . j a va 2 s .c o m*/ * @param trimDateIfPossible true: * <pre> * 3000->00:00:03 * 380000->00:06:20 * 5692439078->1581:13:59.078 * </pre> * false: * <pre> * 3000->P0000-00-00T00:00:03 * 5692439078->P0000-00-00T1581:13:59.078 * </pre> * * @return The ISO 8601 Period like "P3Y6M4DT12H30M17S" */ public static String getDifference(long diffMillis, boolean trimDateIfPossible) { if (diffMillis == 0) return ""; Period period = new Period(diffMillis); /* PeriodFormatter myFormatter = new PeriodFormatterBuilder() .printZeroAlways() .appendYears() .appendSuffix(" year", " years") .appendSeparator(" and ") .appendMonths() .appendSuffix(" month", " months") .toFormatter(); */ /*if (true) */ { // 3000->P0000-00-00T00:00:03 // 5692439078->P0000-00-00T1581:13:59.078 PeriodFormatter formatter = ISOPeriodFormat.alternateExtended(); String periodStr = formatter.print(period); if (trimDateIfPossible) { if (periodStr.startsWith("P0000-00-00T")) periodStr = periodStr.substring("P0000-00-00T".length()); } return periodStr; } /* else { // 3000->PT3S // 5692439078->PT1581H13M59.078S return period.toString(); } */ }
From source file:com.eviware.loadui.ui.fx.views.analysis.linechart.MillisToTickMark.java
License:EUPL
private String prettyPrintTime(final Number n) { Period period = new Period(n.longValue()); period = trimPeriod(period);/* www .ja va 2 s .c o m*/ String res = timeFormatter.print(period); String[] timeUnits = res.split(" "); return timeUnits[timeUnits.length - 1]; }
From source file:com.eviware.loadui.ui.fx.views.analysis.linechart.MillisToTickMark.java
License:EUPL
public String generatePositionString(final long millis) { return timeFormatter.print(trimPeriod(new Period(millis))); }
From source file:com.facebook.config.StringToPeriodMapper.java
License:Apache License
@Override public Period map(String input) { return new Period(ConfigUtil.getDurationMillis(input)); }