Hi Steve,

you can use JavaScript to define a SPARQL function that converts milliseconds into a valid xsd:dateTime. I have attached such a function, defined using SPINx:

msToDate:msToDate
  rdf:type spin:Function ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:ms ;
      spl:valueType xsd:integer ;
      rdfs:comment "The milliseconds as a number." ;
    ] ;
  spin:returnType xsd:dateTime ;
  spinx:javaScriptCode "return new Date(arg1).toISOString();" ;
  rdfs:label "ms to date" ;
  rdfs:subClassOf spin:Functions ;
.

The key here is the JS function Date.toISOString() which has AFAIK no equivalent in our SPARQL support right now.

Use it as in

SELECT *
WHERE {
    BIND (NOW() AS ?now) .
    BIND (spif:timeMillis(?now) AS ?ms) .
    BIND (?ms + 1000 AS ?later) .
    BIND (msToDate:msToDate(?later) AS ?result)
}

Does this sound right?

Holger


On 23/02/2017 10:01, Steve Ray (CMU) wrote:

Hi,

I’m building a set of SPIN rules, and will need to be able to do calculations on date/time values represented according to RFC 5545, such as:

2014-12-09T12:37:40Z

I need to add a duration to such a date/time, again using the same standard, such as:

PT30M

I dread the idea of parsing these strings, accounting for days in a month, not to mention leap years. It would be amazing if there was a SPIN function library for these operations. Next best I suppose, is a Java library, although I don’t have any experience in calling external Java routines from within a SPIN rule (but I believe it’s not hard, right?).

Does anybody have a suggestion of how I might proceed?

- Steve

Steven R. Ray, Ph.D.

Distinguished Research Fellow

Carnegie Mellon University

NASA Research Park

Building 23 (MS 23-11)

P.O. Box 1
Moffett Field, CA 94305-0001

Email: [email protected]

Phone: (650) 587-3780

Cell: (202) 316-6481

Skype: steverayconsulting

cid:[email protected]

--
You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include the TopBraid Suite family of products and its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to [email protected]
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Group "TopBraid 
Suite Users", the topics of which include the TopBraid Suite family of products and 
its base technologies such as SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to [email protected]
--- You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
# baseURI: http://example.org/msToDate
# imports: http://spinrdf.org/spinx
# prefix: msToDate

@prefix arg: <http://spinrdf.org/arg#> .
@prefix msToDate: <http://example.org/msToDate#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sp: <http://spinrdf.org/sp#> .
@prefix spin: <http://spinrdf.org/spin#> .
@prefix spinx: <http://spinrdf.org/spinx#> .
@prefix spl: <http://spinrdf.org/spl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/msToDate>
  rdf:type owl:Ontology ;
  owl:imports <http://spinrdf.org/spinx> ;
  owl:versionInfo "Created with TopBraid Composer" ;
.
msToDate:msToDate
  rdf:type spin:Function ;
  spin:constraint [
      rdf:type spl:Argument ;
      spl:predicate arg:ms ;
      spl:valueType xsd:integer ;
      rdfs:comment "The milliseconds as a number." ;
    ] ;
  spin:returnType xsd:dateTime ;
  spinx:javaScriptCode "return new Date(arg1).toISOString();" ;
  rdfs:label "ms to date" ;
  rdfs:subClassOf spin:Functions ;
.
arg:ms
  rdf:type rdf:Property ;
  rdfs:subPropertyOf sp:arg ;
.

Reply via email to