ULB-Darmstadt / shacl-form

HTML5 web component for editing/viewing RDF data that conform to SHACL shapes
https://ulb-darmstadt.github.io/shacl-form/
MIT License
20 stars 3 forks source link

shacl too strict on xsd:dateTime #16

Closed renevoorburg closed 1 week ago

renevoorburg commented 1 week ago

An rdf that is validated by https://www.itb.ec.europa.eu/shacl/any/upload gives an validation error in the generated form. The triple that fails is:

ex:Event001 mdto:eventTijd '2020-01-12T23:20:00'^^xsd:dateTime . 

It does validate when I change it to:

ex:Event001 mdto:eventTijd '2020-01-12T23:20:01'^^xsd:dateTime . 

To my knowledge, the former is valid too.

s-tittel commented 1 week ago

Could you provide a minimal example to reproduce?

s-tittel commented 1 week ago

Never mind, found it. The datetime-local html input field omits the seconds part completely in case they are 0.

v1.4.6 fixes this by converting the value to xsd:dateTime via new Date(value).toISOString().slice(0, 19)

renevoorburg commented 1 week ago

Great!

For the sake of completeness, this example doesn't validate now while it should. Adding one second to the data time will make it pass.

<html>
  <head>
    <script
      src="https://cdn.jsdelivr.net/npm/@ulb-darmstadt/shacl-form/dist/form-default.js"
      type="module"
    ></script>
  </head>
  <body>
    <shacl-form
      data-shape-subject="http://www.nationaalarchief.nl/mdto-shacl#EventGegevensShape"
      data-shapes="
      @prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
      @prefix sh:      <http://www.w3.org/ns/shacl#> .
      @prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
      @prefix mdto:    <http://www.nationaalarchief.nl/mdto#> .
      @prefix mdtosh:  <http://www.nationaalarchief.nl/mdto-shacl#> .

      mdtosh:EventGegevensShape
          a sh:NodeShape ;
          sh:targetClass mdto:EventGegevens ;
          sh:property [
            a sh:NodeShape ;
            sh:path mdto:eventTijd ;
            sh:datatype xsd:dateTime ;
            sh:name 'Date time' 
        ].   
    " data-values="
        @prefix mdto: <http://www.nationaalarchief.nl/mdto#> .
        @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
        @prefix ex: <http://www.example.com/> .

        ex:Event001
            a mdto:EventGegevens ;
            mdto:eventTijd '2020-01-12T23:20:00'^^xsd:dateTime . 
    " data-values-subject="http://www.example.com/Event001"
    ></shacl-form>
    <script>
      const form = document.querySelector("shacl-form");
      form.addEventListener("change", (event) => {
        if (event.detail?.valid) {
          const triples = form.serialize();
          console.log("entered form data", triples);
        }
      });
    </script>
  </body>
</html>
s-tittel commented 1 week ago

Just check once more, it should work now. It takes a while for the CDN to update to the latest version of this library. Alternatively you can request a specific version like so: https://cdn.jsdelivr.net/npm/@ulb-darmstadt/shacl-form@1.4.6/dist/form-default.js

renevoorburg commented 1 week ago

Now it works as expected. Thank you!