summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGaëtan de Menten <gdementen@gmail.com>2007-10-10 16:15:29 +0000
committerGaëtan de Menten <gdementen@gmail.com>2007-10-10 16:15:29 +0000
commitba1f5c45ef1d06e83c537bdce69a9d5f79d7d19b (patch)
treec2114b3a9e704e73b321ffa75c465cb76af7fa80 /lib
parent1d05d76cad30e96e54adb5cf2f03e7a0bc5aab8a (diff)
downloadsqlalchemy-ba1f5c45ef1d06e83c537bdce69a9d5f79d7d19b.tar.gz
similar type optimization for the Interval type
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/types.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index 02e36e0f3..1f18201d7 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -535,14 +535,17 @@ class Interval(TypeDecorator):
if self.__hasNativeImpl(dialect):
return impl_processor
else:
- def process(value):
- if value is None:
- return None
- tmpval = dt.datetime.utcfromtimestamp(0) + value
- if impl_processor is not None:
- return impl_processor(tmpval)
- else:
- return tmpval
+ zero_timestamp = dt.datetime.utcfromtimestamp(0)
+ if impl_processor is None:
+ def process(value):
+ if value is None:
+ return None
+ return zero_timestamp + value
+ else:
+ def process(value):
+ if value is None:
+ return None
+ return impl_processor(zero_timestamp + value)
return process
def result_processor(self, dialect):
@@ -550,12 +553,17 @@ class Interval(TypeDecorator):
if self.__hasNativeImpl(dialect):
return impl_processor
else:
- def process(value):
- if value is None:
- return None
- if impl_processor is not None:
- value = impl_processor(value)
- return value - dt.datetime.utcfromtimestamp(0)
+ zero_timestamp = dt.datetime.utcfromtimestamp(0)
+ if impl_processor is None:
+ def process(value):
+ if value is None:
+ return None
+ return value - zero_timestamp
+ else:
+ def process(value):
+ if value is None:
+ return None
+ return impl_processor(value) - zero_timestamp
return process
class FLOAT(Float):pass