Java Code Examples for org.joda.time.Period#seconds()
The following examples show how to use
org.joda.time.Period#seconds() .
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: TestISOPeriodFormat.java From astor with GNU General Public License v2.0 | 6 votes |
public void testFormatStandard_negative() { Period p = new Period(-1, -2, -3, -4, -5, -6, -7, -8); assertEquals("P-1Y-2M-3W-4DT-5H-6M-7.008S", ISOPeriodFormat.standard().print(p)); p = Period.years(-54); assertEquals("P-54Y", ISOPeriodFormat.standard().print(p)); p = Period.seconds(4).withMillis(-8); assertEquals("PT3.992S", ISOPeriodFormat.standard().print(p)); p = Period.seconds(-4).withMillis(8); assertEquals("PT-3.992S", ISOPeriodFormat.standard().print(p)); p = Period.seconds(-23); assertEquals("PT-23S", ISOPeriodFormat.standard().print(p)); p = Period.millis(-8); assertEquals("PT-0.008S", ISOPeriodFormat.standard().print(p)); }
Example 2
Source File: TestISOPeriodFormat.java From astor with GNU General Public License v2.0 | 6 votes |
public void testFormatStandard_negative() { Period p = new Period(-1, -2, -3, -4, -5, -6, -7, -8); assertEquals("P-1Y-2M-3W-4DT-5H-6M-7.008S", ISOPeriodFormat.standard().print(p)); p = Period.years(-54); assertEquals("P-54Y", ISOPeriodFormat.standard().print(p)); p = Period.seconds(4).withMillis(-8); assertEquals("PT3.992S", ISOPeriodFormat.standard().print(p)); p = Period.seconds(-4).withMillis(8); assertEquals("PT-3.992S", ISOPeriodFormat.standard().print(p)); p = Period.seconds(-23); assertEquals("PT-23S", ISOPeriodFormat.standard().print(p)); p = Period.millis(-8); assertEquals("PT-0.008S", ISOPeriodFormat.standard().print(p)); }
Example 3
Source File: DetectionUtils.java From incubator-pinot with Apache License 2.0 | 6 votes |
public static Period periodFromTimeUnit(int size, TimeUnit unit) { switch (unit) { case DAYS: return Period.days(size); case HOURS: return Period.hours(size); case MINUTES: return Period.minutes(size); case SECONDS: return Period.seconds(size); case MILLISECONDS: return Period.millis(size); default: return new Period(TimeUnit.MILLISECONDS.convert(size, unit)); } }
Example 4
Source File: UIUtils.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * Format the duration in milliseconds to a human readable String, with "yr", "days", "hr" etc prefixes * * * @param durationMs Duration in milliseconds * @return Human readable string */ public static String formatDuration(long durationMs){ Period period = Period.seconds((int)(durationMs/1000L)); Period p2 = period.normalizedStandard(PeriodType.yearMonthDayTime()); PeriodFormatter formatter = new PeriodFormatterBuilder() .appendYears() .appendSuffix(" yr ") .appendMonths() .appendSuffix(" months ") .appendDays() .appendSuffix(" days ") .appendHours() .appendSuffix(" hr ") .appendMinutes() .appendSuffix(" min ") .appendSeconds() .appendSuffix(" sec") .toFormatter(); return formatter.print(p2); }
Example 5
Source File: CalendarDuration.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Convert a time udunit string * * @param value number of units * @param udunit msec, sec, minute, hour, hr, day, week, month, year (plural form ok) * @return joda Period */ static org.joda.time.Period convertToPeriod(int value, String udunit) { if (udunit.endsWith("s")) udunit = udunit.substring(0, udunit.length() - 1); switch (udunit) { case "msec": return Period.millis(value); case "sec": return Period.seconds(value); case "minute": return Period.minutes(value); case "hour": case "hr": return Period.hours(value); case "day": return Period.days(value); case "week": return Period.weeks(value); case "month": return Period.months(value); case "year": return Period.years(value); } throw new IllegalArgumentException("cant convert " + udunit + " to Joda Period"); }
Example 6
Source File: NumericalIntervalParser.java From crate with Apache License 2.0 | 5 votes |
private static Period buildSecondsWithMillisPeriod(int seconds, int millis) { Period period = Period.seconds(seconds); if (millis != 0) { period = period.withMillis(millis); } return period; }
Example 7
Source File: NumericalIntervalParser.java From crate with Apache License 2.0 | 4 votes |
private static Period roundToPrecision(int value, int millis, @Nullable IntervalParser.Precision start, @Nullable IntervalParser.Precision end) { if (start == null && end == null) { return buildSecondsWithMillisPeriod(value, millis); } if (start == IntervalParser.Precision.YEAR) { if (end == null) { return Period.years(value); } if (end == IntervalParser.Precision.MONTH) { return Period.months(value); } } if (start == IntervalParser.Precision.MONTH && end == null) { return Period.months(value); } if (start == IntervalParser.Precision.DAY) { if (end == null) { return Period.days(value); } if (end == IntervalParser.Precision.HOUR) { return Period.hours(value); } if (end == IntervalParser.Precision.MINUTE) { return Period.minutes(value); } if (end == IntervalParser.Precision.SECOND) { return buildSecondsWithMillisPeriod(value, millis); } } if (start == IntervalParser.Precision.HOUR) { if (end == null) { return Period.hours(value); } if (end == IntervalParser.Precision.MINUTE) { return Period.minutes(value); } if (end == IntervalParser.Precision.SECOND) { return buildSecondsWithMillisPeriod(value, millis); } } if (start == IntervalParser.Precision.MINUTE) { if (end == null) { return Period.minutes(value); } if (end == IntervalParser.Precision.SECOND) { return Period.seconds(value); } } if (start == IntervalParser.Precision.SECOND && end == null) { return buildSecondsWithMillisPeriod(value, millis); } throw new IllegalArgumentException("Invalid start and end combination"); }