summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuhushow <huhushow@gmail.com>2016-06-27 10:40:30 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-06-27 10:40:30 -0400
commitb867915cd02fd82d6ae62381e7ef1eb380619acb (patch)
tree78a9109359161ee07eba191e791eceaa9dd7a0d1
parent7c74d702a9632a8c7264d6972e46985de3fb2487 (diff)
downloadsqlalchemy-pr_github_285.tar.gz
add bind processor and result prosseor for DATETIMEOFFSETpr_github_285
datetimeoffset is timezone aware type of mssql this is simple version of ms datetimeoffset support Change-Id: I8fba989355903935ce72598b16447925648f1002 Pull-request: https://github.com/zzzeek/sqlalchemy/pull/285
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index bc1ad5cdf..e00fda782 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -701,12 +701,27 @@ class DATETIME2(_DateTimeBase, sqltypes.DateTime):
self.precision = precision
-# TODO: is this not an Interval ?
+# TODO: this is timezone aware type of mssql
class DATETIMEOFFSET(sqltypes.TypeEngine):
__visit_name__ = 'DATETIMEOFFSET'
def __init__(self, precision=None, **kwargs):
self.precision = precision
+
+ def bind_processor(self, dialect):
+ def process(value):
+ _mstz = value.strftime("%z")[:3] + ':' + value.strftime("%z")[3:]
+ return value.strftime("%Y-%m-%d %H:%M:%S.%f") + _mstz
+ return process
+
+ def result_processor(self, dialect, coltype):
+ def process(value):
+ _str_microsecond = value[20:20+self.precision] if self.precision else value[20:27]
+ _str_microsecond = _str_microsecond[:6] if len(_str_microsecond) > 6 else _str_microsecond
+ _str_tzinfo = value[-6:-3] + value[-2:]
+ _dt = "%s-%s-%s %s:%s:%s.%s %s" % (value[0:4], value[5:7], value[8:10], value[11:13], value[14:16], value[17:19], _str_microsecond, _str_tzinfo)
+ return datetime.datetime.strptime(_dt,"%Y-%m-%d %H:%M:%S.%f %z")
+ return process
class _StringType(object):