Search in sources :

Example 51 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class FiqlSearchConditionBuilderTest method testNotEqualToDuration.

@Test
public void testNotEqualToDuration() throws ParseException, DatatypeConfigurationException {
    Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);
    String ret = b.is("foo").notEqualTo(d).query();
    assertEquals("foo!=-P0Y0M1DT12H0M0S", ret);
}
Also used : Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 52 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class FiqlSearchConditionBuilderTest method testGreaterThanDuration.

@Test
public void testGreaterThanDuration() throws DatatypeConfigurationException {
    Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);
    String ret = b.is("foo").after(d).query();
    assertEquals("foo=gt=-P0Y0M1DT12H0M0S", ret);
}
Also used : Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 53 with Duration

use of javax.xml.datatype.Duration in project wikidata-query-rdf by wikimedia.

the class WikibaseDateUnitTest method durations.

@Test
public void durations() throws DatatypeConfigurationException {
    WikibaseDate wbDate = new WikibaseDate(2016, 8, 5, 0, 0, 0);
    Duration d = DatatypeFactory.newInstance().newDuration("P7D");
    WikibaseDate wdDate7days = wbDate.addDuration(d);
    assertThat(wdDate7days.secondsSinceEpoch()).isEqualTo(jodaSeconds(2016, 8, 12, 0, 0, 0));
    wdDate7days = wbDate.addDuration(d.negate());
    assertThat(wdDate7days.secondsSinceEpoch()).isEqualTo(jodaSeconds(2016, 7, 29, 0, 0, 0));
}
Also used : Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 54 with Duration

use of javax.xml.datatype.Duration in project keycloak by keycloak.

the class XMLTimeUtil method add.

/**
 * Add additional time in miliseconds
 *
 * @param value calendar whose value needs to be updated
 * @param millis
 *
 * @return calendar value with the addition
 */
public static XMLGregorianCalendar add(XMLGregorianCalendar value, long millis) {
    if (value == null) {
        return null;
    }
    XMLGregorianCalendar newVal = (XMLGregorianCalendar) value.clone();
    if (millis == 0) {
        return newVal;
    }
    Duration duration;
    duration = DATATYPE_FACTORY.get().newDuration(millis);
    newVal.add(duration);
    return newVal;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Duration(javax.xml.datatype.Duration)

Example 55 with Duration

use of javax.xml.datatype.Duration in project tck by dmn-tck.

the class CamundaTCKTest method getValue.

private Object getValue(ValueType valueType) {
    final JAXBElement<Object> value = valueType.getValue();
    final JAXBElement<ValueType.List> listValue = valueType.getList();
    final List<Component> componentValue = valueType.getComponent();
    if (value == null && listValue == null && componentValue == null) {
        return null;
    }
    if (listValue != null) {
        final List<Object> list = new ArrayList<>();
        for (ValueType item : listValue.getValue().getItem()) {
            list.add(getValue(item));
        }
        return list;
    }
    if (componentValue != null && !componentValue.isEmpty()) {
        final Map<String, Object> context = new HashMap<>();
        for (Component component : componentValue) {
            final Object compValue = getValue(component);
            context.put(component.getName(), compValue);
        }
        return context;
    }
    if (value instanceof Node) {
        final Node node = (Node) value;
        final String text = node.getFirstChild().getTextContent();
        if ("true".equalsIgnoreCase(text) || "false".equalsIgnoreCase(text)) {
            return Boolean.valueOf(text);
        }
        try {
            return Long.valueOf(text);
        } catch (NumberFormatException e) {
        }
        try {
            return Double.valueOf(text);
        } catch (NumberFormatException e) {
        }
        return text;
    }
    if (value != null) {
        final Object singleValue = value.getValue();
        if (singleValue instanceof XMLGregorianCalendar) {
            return transformDateTime((XMLGregorianCalendar) singleValue);
        }
        if (singleValue instanceof Duration) {
            return transformDuration((Duration) singleValue);
        }
        if (singleValue instanceof String[]) {
            String[] array = (String[]) singleValue;
            return Arrays.asList(array);
        }
        return singleValue;
    }
    throw new RuntimeException(String.format("Unexpected value: '%s'", valueType));
}
Also used : ValueType(org.omg.dmn.tck.marshaller._20160719.ValueType) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) ResultNode(org.omg.dmn.tck.marshaller._20160719.TestCases.TestCase.ResultNode) ArrayList(java.util.ArrayList) Duration(javax.xml.datatype.Duration) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.omg.dmn.tck.marshaller._20160719.ValueType.Component)

Aggregations

Duration (javax.xml.datatype.Duration)137 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)57 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 Date (java.util.Date)12 BigDecimal (java.math.BigDecimal)9 Calendar (java.util.Calendar)9 GregorianCalendar (java.util.GregorianCalendar)9 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 IOException (java.io.IOException)5 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)5 FileNotFoundException (java.io.FileNotFoundException)4 Collection (java.util.Collection)4 DatatypeFactory (javax.xml.datatype.DatatypeFactory)4 NotNull (org.jetbrains.annotations.NotNull)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3