/** * Instantiates year-month duration from string representation of xs:dayTimeDuration value. * * @param value * a string representing the desired duration * @throws java.lang.IllegalArgumentException * if {@code value} is not a valid string representation of xs:dayTimeDuration */ public YearMonthDurationValue(final String value) throws IllegalArgumentException { super(XmlUtils.XML_TEMPORAL_DATATYPE_FACTORY.newDurationYearMonth(value)); }
public Duration newDurationYearMonth(boolean isPositive, BigInteger year, BigInteger month) { return actual.newDurationYearMonth(isPositive, year, month); }
public Duration newDurationYearMonth(String lexicalRepresentation) { return actual.newDurationYearMonth(lexicalRepresentation); }
public Duration newDurationYearMonth(boolean isPositive, int year, int month) { return actual.newDurationYearMonth(isPositive, year, month); }
public Duration newDurationYearMonth(long durationInMilliseconds) { return actual.newDurationYearMonth(durationInMilliseconds); }
public Duration newDurationYearMonth(final boolean isPositive, final int year, final int month) { return newDurationYearMonth(isPositive, BigInteger.valueOf((long) year), BigInteger.valueOf((long) month)); }
public Duration toDuration(ZonedDateTime first, ZonedDateTime second) { LocalDate firstLocalDate = first.toLocalDate(); LocalDate secondLocalDate = second.toLocalDate(); long durationInMilliSeconds = getDurationInMilliSeconds(firstLocalDate.atStartOfDay(DateTimeUtil.UTC), secondLocalDate.atStartOfDay(DateTimeUtil.UTC)); return datatypeFactory.newDurationYearMonth(durationInMilliSeconds); } }
public Duration toDuration(LocalDate date1, LocalDate date2) { long durationInMilliSeconds = getDurationInMilliSeconds(date1.atStartOfDay(DateTimeUtil.UTC), date2.atStartOfDay(DateTimeUtil.UTC)); return datatypeFactory.newDurationYearMonth(durationInMilliSeconds); } }
public Duration toDuration(ZonedDateTime first, ZonedDateTime second) { LocalDate firstLocalDate = first.toLocalDate(); LocalDate secondLocalDate = second.toLocalDate(); long durationInMilliSeconds = getDurationInMilliSeconds(firstLocalDate.atStartOfDay(DateTimeUtil.UTC), secondLocalDate.atStartOfDay(DateTimeUtil.UTC)); return datatypeFactory.newDurationYearMonth(durationInMilliSeconds); } }
/** * Decide what expiration time to grant to the subscription, if * the client did not specify any particular wish for subscription length. */ public XMLGregorianCalendar grantExpiration() { try { // by default, we grant an expiration time of 2 years DatatypeFactory factory = DatatypeFactory.newInstance(); XMLGregorianCalendar granted = factory.newXMLGregorianCalendar(new GregorianCalendar()); granted.add(factory.newDurationYearMonth(true, 2, 0)); return granted; } catch (DatatypeConfigurationException ex) { throw new Error(ex); } }
public Duration toDuration(LocalDate date1, LocalDate date2) { long durationInMilliSeconds = getDurationInMilliSeconds(date1.atStartOfDay(DateTimeUtil.UTC), date2.atStartOfDay(DateTimeUtil.UTC)); return datatypeFactory.newDurationYearMonth(durationInMilliSeconds); } }
/** * Decide what expiration time to grant to the subscription, if * the client did not specify any particular wish for subscription length. */ public XMLGregorianCalendar grantExpiration() { try { // by default, we grant an expiration time of 2 years DatatypeFactory factory = DatatypeFactory.newInstance(); XMLGregorianCalendar granted = factory.newXMLGregorianCalendar(new GregorianCalendar()); granted.add(factory.newDurationYearMonth(true, 2, 0)); return granted; } catch (DatatypeConfigurationException ex) { throw new Error(ex); } }
/** * converts String representation of duration to its XML equivalent. * Returns null if the type provided does not correspond to any XML duration types. * * @param duration the String duration representation * @param dType one of XQJ base type constants * @return XML {@link Duration} instance or null */ public static Duration getXMLDuration(String duration, int dType) { switch (dType) { case XQBASETYPE_DURATION: return dtFactory.newDuration(duration); case XQBASETYPE_DAYTIMEDURATION: return dtFactory.newDurationDayTime(duration); case XQBASETYPE_YEARMONTHDURATION: return dtFactory.newDurationYearMonth(duration); } return null; }
/** * Decide what expiration time to grant to the subscription, if * the client specified a duration in the request and did specify BestEffort=true. */ public XMLGregorianCalendar grantExpirationFor(javax.xml.datatype.Duration requested) { XMLGregorianCalendar granted; try { granted = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); if (DurationAndDateUtil .isPT0S(requested)) { // The client requested a non-expiring subscription. // We will give them 5 years. granted.add(DatatypeFactory.newInstance().newDurationYearMonth(true, 5, 0)); } else { granted.add(requested); // default } return granted; } catch (DatatypeConfigurationException e) { throw new Error(e); } }
/** * Decide what expiration time to grant to the subscription, if * the client specified a duration in the request and did specify BestEffort=true. */ public XMLGregorianCalendar grantExpirationFor(javax.xml.datatype.Duration requested) { XMLGregorianCalendar granted; try { granted = DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()); if (DurationAndDateUtil .isPT0S(requested)) { // The client requested a non-expiring subscription. // We will give them 5 years. granted.add(DatatypeFactory.newInstance().newDurationYearMonth(true, 5, 0)); } else { granted.add(requested); // default } return granted; } catch (DatatypeConfigurationException e) { throw new Error(e); } }
public Duration newDurationYearMonth(final long durationInMilliseconds) { Duration fullDuration = newDuration(durationInMilliseconds); boolean isPositive = fullDuration.getSign() != -1; BigInteger years = (BigInteger) fullDuration.getField(DatatypeConstants.YEARS); if (years == null) { years = BigInteger.ZERO; } BigInteger months = (BigInteger) fullDuration.getField(DatatypeConstants.MONTHS); if (months == null) { months = BigInteger.ZERO; } return newDurationYearMonth(isPositive, years, months); }
public static Duration toYearsMonthDuration(DatatypeFactory datatypeFactory, LocalDate date1, LocalDate date2) { Period between = Period.between(date2, date1); int years = between.getYears(); int months = between.getMonths(); if (between.isNegative()) { years = - years; months = - months; } return datatypeFactory.newDurationYearMonth(!between.isNegative(), years, months); }
public static Duration toYearsMonthDuration(DatatypeFactory datatypeFactory, LocalDate date1, LocalDate date2) { Period between = Period.between(date2, date1); int years = between.getYears(); int months = between.getMonths(); if (between.isNegative()) { years = - years; months = - months; } return datatypeFactory.newDurationYearMonth(!between.isNegative(), years, months); }
Duration d = datatypeFactory.newDurationYearMonth(value); XMLGregorianCalendar c = getCurrentTime(); c.add(d);
@Test public void testConvertFromJavaDuration() throws DatatypeConfigurationException { DatatypeFactory f = DatatypeFactory.newInstance(); Duration d = f.newDuration(true, 1, 2, 3, 4, 5, 6); ValueConverter.convertFromJava(d, processor); checkProcessor("duration", "xs:duration", d); d = f.newDurationYearMonth(true, 1, 2); ValueConverter.convertFromJava(d, processor); checkProcessor("year month duration", "xs:yearMonthDuration", d); d = f.newDurationDayTime(true, 3, 4, 5, 6); ValueConverter.convertFromJava(d, processor); checkProcessor("day time duration", "xs:dayTimeDuration", d); } @Test