Skip to content

Commit

Permalink
Makes NOW() return an UTC date
Browse files Browse the repository at this point in the history
Closes #843
  • Loading branch information
Tpt committed Aug 28, 2018
1 parent 9da21db commit c459bef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rdflib/plugins/sparql/sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
from collections import Mapping, MutableMapping

import isodate
from six import text_type, iteritems

from rdflib.namespace import NamespaceManager
Expand Down Expand Up @@ -242,7 +243,7 @@ def __init__(self, graph=None, bindings=None, initBindings=None):
self.graph = graph

self.prologue = None
self.now = datetime.datetime.now()
self.now = datetime.datetime.now(isodate.tzinfo.UTC)

self.bnodes = collections.defaultdict(BNode)

Expand Down
34 changes: 34 additions & 0 deletions try.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from rdflib.plugins.sparql.operators import custom_function

from rdflib import Graph, URIRef, Namespace, Literal
from rdflib.plugins.sparql.sparql import SPARQLError

g = Graph()
foo = URIRef('http://foo')
g.add((foo, foo, foo))

XF = Namespace('http://xact.ai/fn#')


@custom_function(XF.nativeLE)
def xf_native_le(a, b):
if not isinstance(a, Literal) or not isinstance(b, Literal):
raise SPARQLError("xf:nativeLE is only implemented on Literals")
return Literal(a.toPython() <= b.toPython())


@custom_function(XF.nativeAdd)
def xf_native_add(a, b):
print(a, b, Literal(a.toPython() + b.toPython()))
if not isinstance(a, Literal) or not isinstance(b, Literal):
raise SPARQLError("xf:nativeAdd is only implemented on Literals")
return Literal(a.toPython() + b.toPython())


for r in g.query(
"SELECT * WHERE { BIND(<http://xact.ai/fn#nativeAdd>('P1Y'^^xsd:duration, 'P1Y'^^xsd:duration) AS ?t) ?s ?s ?s }"):
print(r)

for r in g.query(
"SELECT * WHERE { BIND(NOW() AS ?t) ?s ?s ?s }"):
print(r)

0 comments on commit c459bef

Please sign in to comment.