Time Interval Functions

683 views
Skip to first unread message

Rich Keller

unread,
Feb 11, 2014, 11:40:30 AM2/11/14
to topbrai...@googlegroups.com
Hi. I have been trying to do some temporal arithmetic in SPARQL and have stumbled upon what I believe are time periods or time intervals.  For example

SELECT ?a ?aa
WHERE {
BIND (("08:15:00"^^xsd:time - "10:15:00"^^xsd:time) AS ?a)
BIND (("2012-09-08T08:15:00"^^xsd:dateTime - "2012-09-07T10:15:00"^^xsd:dateTime) AS ?aa)
}

Results:

?a -> -P0Y0M0DT2H0M0.000S  (negative 2 hours)
?aa -> P0Y0M0DT22H0M0.000S (positive 22 hours)

My question: Is there any way to operate on these time periods? In particular, suppose I want to convert the length of these these periods into seconds or minutes. smf:duration does something similar, but it works on xsd:date values, and not time periods. If smf:duration took xsd:dateTime or xsd:time arguments, that would be helpful.

Do you have any pointers to functions that extract information from these time periods? I suppose I can figure a way to do the arithmetic myself using days(), hours(), minutes() functions, but I would prefer to avoid that.

Thanks, Rich

Using TBC-SE 4.3.0

Scott Henninger

unread,
Feb 11, 2014, 12:39:40 PM2/11/14
to topbrai...@googlegroups.com
Rich, there are a number of SPARQL and TopBraid functions that work on xsd:time and xsd:dateTime  for SPARQL, see http://www.w3.org/TR/sparql11-query/#func-date-time, including year(), month(), day(), hours(), timezone(), etc.

TopBraid also has functions for duration, formatting date strings, etc.  I.e. you can convert a dateTime string to a date string using dateFormat().  See TopBraid Composer Help TopBraid Composer > Reference > Functions Overview

-- Scott

--
-- You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Insight, SPARQLMotion, SPARQL Web Pages and SPIN.
To post to this group, send email to
topbrai...@googlegroups.com
To unsubscribe from this group, send email to
topbraid-user...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en
---
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 topbraid-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Rich Keller

unread,
Feb 11, 2014, 7:51:38 PM2/11/14
to topbrai...@googlegroups.com
Scott: I'm aware of the SPARQL and TopBraid functions you mention. But to my knowledge, these functions do not operate on duration literals like P0Y0M0DT22H0M0.000S, which was returned by my query subtracting two xsd:time or xsd:dateTime literals (see original post). As I mentioned, smf:duration seems to take two xsd:date variables as input, which means it is not suitable for determining the duration between arbitrary times.

Rich

Scott Henninger

unread,
Feb 11, 2014, 9:48:33 PM2/11/14
to topbrai...@googlegroups.com
Rich; Not sure if the difference in expectation is with the version TopBraid being used, but using 4.3, smf:duration() takes xsd:dateTime and will return down to the milliseconds.  As an example, to get the number of seconds between a dateTime property and the current xsd:dateTime, you can use the following:

SELECT ?dur
WHERE
{  ?s ex:dt ?time
   BIND(smf:duration("s", ?time, now()) AS ?dur)
}


-- Scott

Holger Knublauch

unread,
Feb 11, 2014, 9:52:10 PM2/11/14
to topbrai...@googlegroups.com
Rich,

we do not support any other functions for XSD duration literals (such as P0Y0M0DT22H0M0.000S) apart from those in the SPARQL 1.1 standard.

Holger

Rich Keller

unread,
Feb 12, 2014, 12:23:10 PM2/12/14
to topbrai...@googlegroups.com
Thanks Scott and Holger.

I must have made some error when I tested sfm:duration() previously. In my own defense (:-)), the documentation is ambiguous. It says "Returns the duration between two dates...". The argument documentation reports that the arguments are "the begin date" and "the end date". But unlike other functions documented in the appendix, it does not provide a specific datatype for the begin date and the end date argument.

Regarding SPARQL1.1, it provides no functions on XSD duration literals that I can find. In any case smf:duration should be sufficient for my needs.

Rich
Reply all
Reply to author
Forward
0 new messages