Java Code Examples for org.joda.time.Period#millis()

The following examples show how to use org.joda.time.Period#millis() . 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 vote down vote up
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 vote down vote up
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 vote down vote up
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: CalendarDuration.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 5
Source File: StreamsPeriodDeserializer.java    From streams with Apache License 2.0 4 votes vote down vote up
public Period deserialize(JsonParser jpar, DeserializationContext context) throws IOException {
  return Period.millis(jpar.getIntValue());
}