List of usage examples for org.joda.time Period toStandardDuration
public Duration toStandardDuration()
From source file:org.ldp4j.application.data.Literals.java
License:Apache License
public static DurationLiteral of(javax.xml.datatype.Duration duration) { checkNotNull(duration, DURATION_CANNOT_BE_NULL); Period period = ISOPeriodFormat.standard().parsePeriod(duration.toString()); return new ImmutableDurationLiteral(period.toStandardDuration(), Datatypes.DURATION); }
From source file:org.ldp4j.application.sdk.internal.JodaDurationObjectFactory.java
License:Apache License
@Override public Duration fromString(String rawValue) { try {//from w w w .j a v a 2 s. co m Period period = ISOPeriodFormat.standard().parsePeriod(rawValue); return period.toStandardDuration(); } catch (Exception e) { throw new ObjectParseException(e, Duration.class, rawValue); } }
From source file:org.ldp4j.application.sdk.internal.XmlDurationObjectFactory.java
License:Apache License
@Override public Duration fromString(String rawValue) { try {/*from w w w . j a va2 s . co m*/ Period period = ISOPeriodFormat.standard().parsePeriod(rawValue); return TimeUtils.newInstance().from(period.toStandardDuration()).toDuration(); } catch (Exception e) { throw new ObjectParseException(e, Duration.class, rawValue); } }
From source file:org.n52.wps.commons.PropertyUtil.java
License:Apache License
public long extractPeriodAsMillis(String valueKey, long valueDefault) { String periodAsString;//from www . j av a2 s. c o m if (systemPropertyRoot != null) { String systemPropertyName = JOINER.join(systemPropertyRoot, valueKey); periodAsString = System.getProperty(systemPropertyName); if (periodAsString != null) { try { Period period = Period.parse(periodAsString); if (period != null) { long periodMillis = period.toStandardDuration().getMillis(); LOGGER.info("System property \"{}\" exists, using value of: {} ({}ms) ", systemPropertyName, periodAsString, periodMillis); return periodMillis; } else { LOGGER.error("System property \"{}\" exists but unable to parse \"{}\" as ISO8601 period", systemPropertyName, periodAsString); } } catch (Exception e) { LOGGER.error("System property \"{}\" exists but unable to parse \"{}\" as ISO8601 period", systemPropertyName, periodAsString); } } else { LOGGER.debug("System property \"{}\" not present", systemPropertyName); } } else { LOGGER.debug("System property root not present, skipping system property lookup for {}", valueKey); } PropertyDocument.Property property = propertyNameMap.get(valueKey); if (property != null) { if (property.getActive()) { periodAsString = property.getStringValue(); if (periodAsString != null) { try { Period period = Period.parse(periodAsString); if (period != null) { long periodMillis = period.toStandardDuration().getMillis(); LOGGER.info("Config property for \"{}\" exists, using value of: {} ({}ms) ", valueKey, periodAsString, periodMillis); return periodMillis; } else { LOGGER.error( "Config property for \"{}\" exists but unable to parse \"{}\" as ISO8601 period", valueKey, periodAsString); } } catch (Exception e) { LOGGER.error( "Config property for \"{}\" exists but unable to parse \"{}\" as ISO8601 period", valueKey, periodAsString); } } else { LOGGER.error("Config property for \"{}\" exists but unable to parse \"{}\" as ISO8601 period", valueKey, periodAsString); } } else { LOGGER.warn("Config property for \"{}\" exists but is not active, ignoring", valueKey); } } else { LOGGER.debug("Config property for \"{}\" not present", valueKey); } LOGGER.info("Using default value for \"{}\" of {}ms", valueKey, valueDefault); return valueDefault; }
From source file:org.opennms.newts.rest.DurationParam.java
License:Apache License
@Override protected Duration parse(String input) throws Exception { if (input.matches("^[\\d]+$")) { return Duration.seconds(Integer.valueOf(input)); }/*from w w w . j a v a 2 s . c o m*/ Period period = formatter.parsePeriod(input); return Duration.seconds(period.toStandardDuration().getStandardSeconds()); }
From source file:org.openvpms.archetype.rules.workflow.FreeSlotIterator.java
License:Open Source License
/** * Constructs an {@link FreeSlotIterator}. * * @param schedule the schedule//from www . j a v a 2s . c o m * @param fromDate the date to query from * @param toDate the date to query to * @param fromTime the time to query from. May be {@code null} * @param toTime the time to query to. May be {@code null} * @param service the archetype service */ public FreeSlotIterator(Entity schedule, Date fromDate, Date toDate, Period fromTime, Period toTime, IArchetypeService service) { IMObjectBean bean = new IMObjectBean(schedule, service); long scheduleStart = getScheduleTime(bean.getDate("startTime")); // the time that the schedule starts at long scheduleEnd = getScheduleTime(bean.getDate("endTime")); // the time that the schedule ends at Iterator<ObjectSet> queryIterator = createFreeSlotIterator(schedule, fromDate, toDate, service); Iterator<Slot> slotIterator = createFreeSlotAdapter(queryIterator); Iterator<Slot> first = createFirstLastFreeSlotIterator(slotIterator, schedule, fromDate, toDate, service); if (scheduleStart != -1 || scheduleEnd != -1) { // filter free slots outside the schedule opening and closing times, and split those slots that span // multiple opening/closing times first = new TimeRangeSlotIterator(first, scheduleStart, scheduleEnd); } if (fromTime != null || toTime != null) { // filter free slots outside the time range long from = (fromTime != null) ? fromTime.toStandardDuration().getMillis() : -1; long to = (toTime != null) ? toTime.toStandardDuration().getMillis() : -1; first = new TimeRangeSlotIterator(first, from, to); } iterator = first; }
From source file:org.openvpms.web.workspace.customer.charge.OrderPlacer.java
License:Open Source License
/** * Constructs an {@link OrderPlacer}.//from w w w . j av a 2 s . c om * * @param customer the customer * @param location the location * @param user the user responsible for the orders * @param practice the practice * @param cache the object cache * @param services the order services */ public OrderPlacer(Party customer, Party location, User user, Party practice, IMObjectCache cache, OrderServices services) { this.customer = customer; this.location = location; this.user = user; this.cache = cache; this.services = services; PracticeRules rules = services.getPracticeRules(); Period period = rules.getPharmacyOrderDiscontinuePeriod(practice); discontinueOnFinalisation = period == null || period.toStandardDuration().compareTo(Duration.ZERO) < 0; this.pharmacies = new PharmacyProducts(services.getPharmacies(), location, cache); }
From source file:propel.core.utils.ConversionUtils.java
License:Open Source License
@Validate public static String toHumanReadable(@NotNull final Period p) { return toHumanReadable(p.toStandardDuration()); }