query.calendar.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.
#
# Compute the day of a date
# http://fr.wikipedia.org/wiki/Détermination_du_jour
#
# Olivier Corby - Wimmics, Inria, I3S - 2015
#
prefix cal:
select (cal:jour(now()) as ?fr)
where { }
@public {
function xt:day(?d) { cal:day(?d) }
function xt:jour(?d) { cal:jour(?d) }
function cal:day(?d) { cal:en(cal:find(?d)) }
function cal:jour(?d) { cal:fr(cal:find(?d)) }
function cal:div(?a, ?b) { xsd:integer(floor(?a / ?b)) }
function cal:mod(?a, ?b) { xsd:integer(?a - (?b * cal:div(?a, ?b))) }
function cal:bisextile(?y) {
((cal:mod(?y, 4) = 0) &&
((cal:mod(?y, 100) != 0) || (cal:mod(?y, 400) = 0)))
}
function cal:ab(?y) { cal:div(?y, 100) }
function cal:cd(?y) { cal:mod(?y, 100) }
function cal:k(?y) { cal:div(cal:cd(?y), 4) }
function cal:q(?y) { cal:div(cal:ab(?y), 4) }
function cal:monthday(?m, ?y) {
if (?m <= 2,
if (cal:bisextile(?y),
if (?m = 1, 3, 6),
if (?m = 1, 4, 0)),
if (?m in (3, 11), 0,
if (?m in (6), 1,
if (?m in (9, 12), 2,
if (?m in (4, 7), 3,
if (?m in (10), 4,
if (?m in (5), 5, 6)))))))
}
function cal:get(?y, ?m, ?d) {
let (?n = cal:k(?y) + cal:q(?y) + cal:cd(?y) +
cal:monthday(?m, ?y) + ?d + 2 + 5 * cal:ab(?y))
{
cal:mod(?n, 7)
}
}
function cal:find(?d) {
cal:get(year(?d), month(?d), day(?d))
}
function cal:en(?n) {
if (?n = 0, "Sunday",
if (?n = 1, "Monday",
if (?n = 2, "Tuesday",
if (?n = 3, "Wednesday",
if (?n = 4, "Thursday",
if (?n = 5, "Friday",
if (?n = 6, "Saturday", "Unknown")))))))
}
function cal:fr(?n) {
if (?n = 0, "Dimanche",
if (?n = 1, "Lundi",
if (?n = 2, "Mardi",
if (?n = 3, "Mercredi",
if (?n = 4, "Jeudi",
if (?n = 5, "Vendredi",
if (?n = 6, "Samedi", "Inconnu")))))))
}
function cal:num(?day) {
if (?day in( "Lundi", "Monday"), 1,
if (?day in( "Mardi", "Tuesday"), 2,
if (?day in( "Mercredi", "Wednesday"), 3,
if (?day in( "Jeudi", "Thursday"), 4,
if (?day in( "Vendredi", "Friday"), 5,
if (?day in( "Samedi", "Saturday"), 6,
if (?day in( "Dimanche", "Sunday"), 7, 0)))))))
}
function cal:days(?y, ?m) {
let (?list =
xt:list(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)){
if (?m != 2, xt:get(?list, ?m - 1),
if (cal:bisextile(?y), 29, 28))
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy