Skip to content

Commit

Permalink
Merge pull request #1193 from FlorianLudwig/sparql-timezone
Browse files Browse the repository at this point in the history
do not use current time in sparql TIMEZONE
  • Loading branch information
nicholascar committed Dec 28, 2020
2 parents 009dc24 + 0f191ae commit 6c294aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rdflib/plugins/sparql/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def Builtin_TIMEZONE(e, ctx):
if not dt.tzinfo:
raise SPARQLError("datatime has no timezone: %r" % dt)

delta = dt.tzinfo.utcoffset(ctx.now)
delta = dt.utcoffset()

d = delta.days
s = delta.seconds
Expand Down
10 changes: 8 additions & 2 deletions rdflib/plugins/sparql/sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def remember(self, these):
return FrozenBindings(self.ctx, (x for x in self.items() if x[0] in these))


class QueryContext:
class QueryContext(object):
"""
Query context - passed along when evaluating the query
"""
Expand All @@ -242,10 +242,16 @@ def __init__(self, graph=None, bindings=None, initBindings=None):
self.graph = graph

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

self.bnodes = collections.defaultdict(BNode)

@property
def now(self) -> datetime.datetime:
if self._now is None:
self._now = datetime.datetime.now(isodate.tzinfo.UTC)
return self._now

def clone(self, bindings=None):
r = QueryContext(
self._dataset if self._dataset is not None else self.graph,
Expand Down

0 comments on commit 6c294aa

Please sign in to comment.