xsd:dateTime format

Hello All,

Our java application started recently started barfing when we attempted to insert xsd:dateTime literals formatted like the following:
2017-03-02T14:14:23.000-0800

I noticed that the stardog web console has no problem with the following sparql:

  select * where {
    bind ("2017-03-02T13:31:59.000-0800"^^xsd:dateTime as ?t1)
    bind ("2017-03-02T13:31:59.000Z"^^xsd:dateTime as ?t2)
    bind ( datatype (?t1) as ?type1)
    bind ( datatype (?t2) as ?type2)
  }

Our java app uses RDF4J to create triples that are later insert into Stardog. Here’s an excerpt:

    Literal literal;
    if (property.getLiteralType() != null) {
      IRI typeIri = this.vf.createIRI(property.getLiteralType());
      literal = this.vf.createLiteral(value, typeIri);
    } else {
      literal = this.vf.createLiteral(value);
    }
    this.trips.add(this.vf.createStatement(parentIndividual, this.vf.createIRI(property.getPredicate()), literal));

Stardog seems to be kicking back this error message when we encounter the format in question:
14:22:14.215 [ForkJoinPool-1-worker-5] WARN [c.c.c.s.r.r.CustomSPARQLProtocolSession] Server reports problem: {"message":"Data block for update operation could not be parsed: '2017-03-02T14:14:23.000-0800' is not a valid value for datatype http://www.w3.org/2001/XMLSchema#dateTime [line 10]","code":"MalformedQuery"}

Is this a bug? Am I missing something?

Thank You,
Peter Neorr
Champion Technology Company

Hi,

There are two things at work here:

  1. "2017-03-02T13:31:59.000-0800" is indeed an invalid value for an xsd:dateTime. When specifying the time zone, it requires a colon between the hours and minutes section, so you would need "2017-03-02T13:31:59.000-08:00", which will load properly. "2017-03-02T13:31:59.000Z" is perfectly valid.

  2. The query works because the RDF spec dictates that we accept ill-typed literals because while they are semantically inconsistent, they are "not syntactically ill-formed." They will, however, not function as actual xsd:dateTimes, e.g., when using them in dateTime functions:

Stephens-iMac:community stephen$ stardog query support 
'select * where { 
    bind ("Stephen"^^xsd:dateTime as ?t1) 
    bind (datatype(?t1) as ?type1)  
    bind( hours(?t1) as ?h1)
}'

+-------------------------+--------------+-------+
|           t1            |    type1     |  h1   |
+-------------------------+--------------+-------+
| "Stephen"^^xsd:dateTime | xsd:dateTime |       |
+-------------------------+--------------+-------+

Thank you Stephen! I didn’t even notice the missing colon in the time zone offeset. I guess we can add some pre-processing to fix these in our input.

:smiley:

-Peter

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.