
query.calendar2.rq Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of corese-core Show documentation
Show all versions of corese-core Show documentation
Corese is a Semantic Web Factory (triple store and SPARQL endpoint) implementing RDF, RDFS, SPARQL 1.1 Query and Update.
The newest version!
#
# Compute the day of a date of next week
# Olivier Corby - Wimmics, Inria, I3S - 2015
#
prefix cal:
select
(now() as ?now)
(xt:today() as ?today)
(xt:tomorrow() as ?tomorrow)
(xt:yesterday() as ?yesterday)
(cal:next(xt:today()) as ?today2)
(cal:next(xt:tomorrow()) as ?tomorrow2)
(cal:next(xt:yesterday()) as ?yesterday2)
(cal:next(xt:today(), 1) as ?today3)
(cal:next(xt:tomorrow(), 1) as ?tomorrow3)
(cal:next(xt:yesterday(), 1) as ?yesterday3)
where {}
export {
function xt:today() {
xt:day(now())}
function xt:tomorrow() {
xt:day(cal:add(now(), 1))}
function xt:yesterday() {
xt:day(cal:add(now(), -1))}
function cal:next(?day) {
cal:shift(now(), ?day, 0)}
# shift = 0 : this week or next week
# shift = 1 : next week
function cal:next(?day, ?shift) {
cal:shift(now(), ?day, ?shift)}
function cal:shift(?date, ?day, ?shift) {
let (
?first = cal:day(?date),
?from = cal:num(?first),
?to = cal:num(?day)){
if (?from < ?to){
let (?diff = ?to - ?from){
cal:add(?date, ?diff + 7 * ?shift)
}
}
else {
let (?diff = ?from - ?to){
cal:add(?date, if (?shift = 0, 1, ?shift) * 7 - ?diff)
}
}
}
}
function cal:add(?date, ?n) {
cal:date (year(?date), month(?date), day(?date) + ?n)}
function cal:date(?y, ?m, ?d) {
xsd:date(concat(?y, "-", ?m, "-", ?d))}
function cal:dayname(?n) {
xt:get(xt:list("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), ?n - 1)}
function cal:nomjour(?n) {
xt:get(xt:list("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"), ?n - 1)}
function cal:daynum(?d) { cal:num(?d) }
function cal:monthname(?m) { cal:month(?m) }
function cal:nommois(?m) { cal:mois(?m) }
function cal:mois(?m) {
let (?list = xt:list(
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin",
"Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre")){
xt:get(?list, ?m - 1)
}
}
function cal:month(?m) {
let (?list = xt:list(
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December")){
xt:get(?list, ?m - 1)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy