diff options
| author | gromgull <devnull@localhost> | 2011-01-28 18:56:38 +0000 |
|---|---|---|
| committer | gromgull <devnull@localhost> | 2011-01-28 18:56:38 +0000 |
| commit | 6993093612ee41c3ca2021d0bab241a4139a1d0b (patch) | |
| tree | 8ac810bca0f50d8975f2397687d516a5ac5061a8 | |
| parent | ab4b183c250cd7c915dd0643c31ecf7fa4da009c (diff) | |
| download | rdflib-6993093612ee41c3ca2021d0bab241a4139a1d0b.tar.gz | |
applied patch to fix timezone bug in datetime literals\nFixes issue 118\nFixes issue 157
| -rw-r--r-- | rdflib/term.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/rdflib/term.py b/rdflib/term.py index 5e52bb6d..2e564602 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -20,13 +20,14 @@ import logging _LOGGER = logging.getLogger(__name__) import base64 +import re import threading from urlparse import urlparse, urljoin, urldefrag from string import ascii_letters, rsplit from random import choice from itertools import islice -from datetime import date, time, datetime +from datetime import date, time, datetime, timedelta from time import strptime try: @@ -745,7 +746,21 @@ def _strToDateTime(v) : # %f only works in python 2.6 return datetime.strptime(v, "%Y-%m-%dT%H:%M:%S.%fZ") except: - return v + try: + # %f only works in python 2.6 + # HACK split off the timezone offset + # works for "2011-01-16T19:39:18.239743+01:00" + m = re.match(r'(.*)([-+])(\d{2}):(\d{2})$', + v).groups() + d = datetime.strptime(m[0], "%Y-%m-%dT%H:%M:%S.%f") + t = timedelta(hours=int(m[2]), seconds=int(m[3])) + if m[1] == '+': + d += t + else: + d -= t + return d + except: + return v return datetime(tstr.tm_year, tstr.tm_mon, tstr.tm_mday, tstr.tm_hour, tstr.tm_min, tstr.tm_sec) |
