Thanks, Holger,
Definitely half the solution.
Now I need to find a version of spif:timeMillis that can parse duration strings
like “PT30M” into milliseconds.
- 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]
From: [email protected] [mailto:[email protected]]
On Behalf Of Holger Knublauch
Sent: Wednesday, February 22, 2017 6:21 PM
To: [email protected]
Subject: Re: [topbraid-users] Looking for help on doing time calculations
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].
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.
--
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.