Don’t call me DOM

1 September 2004

Dealing with dates in cwm

Filed under:

cwm is the main Semantic Web toolkit I use to manipulate RDF; while it has some speed issues – really, it shouldn’t have them in the next release -, it allows to use N3 Rules which are tricky to write, but are so much more powerful than declarative programing that at least you feel good once you have written them.

A recurrent pattern I have encountered regards dealing with date differences, e.g. comparing the date of publication of a document with the current date; here is what I’m using (e.g. in detect-missing.n3):


@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix time: <http://www.w3.org/2000/10/swap/time#>.
@prefix dc: <http://purl.org/dc/elements/1.1/>.

{
?DOC dc:date ?DATE.
# Was the document published less than 6 months ago?
 #converting iso date in seconds for proper math comparison
 [ is time:inSeconds of ?DATE ] math:greaterThan 
 [ is math:difference of ( 
   # current time in seconds
   [ is time:inSeconds of [is time:localTime of "" ] ] 
    # 15552000 is the # of seconds in 6*30 days
    "15552000")
 ].
} log:implies {
# ?DOC was published in the last 6 months
}.

One Response to “Dealing with dates in cwm”

  1. Danny Says:

    Thanks, that’s answered something I was wondering about a few months ago. I was playing (in Jena) with RSS 1.0 data, where item resources have a dc:date as a literal in iso format. There wasn’t any obvious way of doing any useful kind of comparison (well, beyond identity). Which was a pain, because the first thing most people would want to do with RSS 1.0 data is sort the items reverse-chrono. I bugged the mailing list a bit, but didn’t get anywhere. What I didn’t know was how things like that were done elsewhere. But now I do ;-)

Picture of Dominique Hazael-MassieuxDominique Hazaël-Massieux (dom@w3.org) is part of the World Wide Web Consortium (W3C) Staff; his interests cover a number of Web technologies, as well as the usage of open source software in a distributed work environment.