Search in sources :

Example 26 with DateTimeStruct

use of org.apache.jena.sparql.util.DateTimeStruct in project jena by apache.

the class XSDFuncOp method tzStrFromNV.

/** Get the timezone in XSD tiezone format (e.g. "Z" or "+01:00").
     * Assumes the NodeValue is of suitable datatype.
     */
private static String tzStrFromNV(NodeValue nv) {
    DateTimeStruct dts = parseAnyDT(nv);
    if (dts == null)
        return "";
    String tzStr = dts.timezone;
    if (tzStr == null)
        tzStr = "";
    return tzStr;
}
Also used : DateTimeStruct(org.apache.jena.sparql.util.DateTimeStruct)

Example 27 with DateTimeStruct

use of org.apache.jena.sparql.util.DateTimeStruct in project jena by apache.

the class XSDFuncOp method fixupDateTime.

private static NodeValue fixupDateTime(NodeValue nv) {
    DateTimeStruct dts = DateTimeStruct.parseDateTime(nv.asNode().getLiteralLexicalForm());
    if (dts.timezone != null)
        return null;
    dts.timezone = defaultTimezone;
    nv = NodeValue.makeDateTime(dts.toString());
    if (!nv.isDateTime())
        throw new ARQInternalErrorException("Failed to reform an xsd:dateTime");
    return nv;
}
Also used : DateTimeStruct(org.apache.jena.sparql.util.DateTimeStruct) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException)

Example 28 with DateTimeStruct

use of org.apache.jena.sparql.util.DateTimeStruct in project jena by apache.

the class XSDFuncOp method dtGetTimezone.

public static NodeValue dtGetTimezone(NodeValue nv) {
    DateTimeStruct dts = parseAnyDT(nv);
    if (dts == null || dts.timezone == null)
        throw new ExprEvalException("Not a datatype with a timezone: " + nv);
    if ("".equals(dts.timezone))
        return null;
    if ("Z".equals(dts.timezone)) {
        Node n = NodeFactory.createLiteral("PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration"));
        return NodeValue.makeNode(n);
    }
    if ("+00:00".equals(dts.timezone)) {
        Node n = NodeFactory.createLiteral("PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration"));
        return NodeValue.makeNode(n);
    }
    if ("-00:00".equals(dts.timezone)) {
        Node n = NodeFactory.createLiteral("-PT0S", NodeFactory.getType(XSDDatatype.XSD + "#dayTimeDuration"));
        return NodeValue.makeNode(n);
    }
    String s = dts.timezone;
    int idx = 0;
    StringBuilder sb = new StringBuilder();
    if (s.charAt(0) == '-')
        sb.append('-');
    // Skip '-' or '+'
    idx++;
    sb.append("PT");
    digitsTwo(s, idx, sb, 'H');
    idx += 2;
    // The ":"
    idx++;
    digitsTwo(s, idx, sb, 'M');
    idx += 2;
    return NodeValue.makeNode(sb.toString(), null, XSDDatatype.XSD + "#dayTimeDuration");
}
Also used : DateTimeStruct(org.apache.jena.sparql.util.DateTimeStruct) Node(org.apache.jena.graph.Node)

Aggregations

DateTimeStruct (org.apache.jena.sparql.util.DateTimeStruct)28 Test (org.junit.Test)19 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Node (org.apache.jena.graph.Node)1