Comparison support for Pyson Date tipes

11 views
Skip to first unread message

Juan Ramon Alfaro Martinez

unread,
Aug 18, 2017, 3:00:05 AM8/18/17
to tryton-dev
Hello.
I have need to campare a Date in pyson and I have modified pyson.py in trytond to support it, if someone wants to push upstream this is the patch.

--- pyson.py.old 2017-08-18 07:53:10.705049046 +0200
+++ pyson.py 2017-08-18 07:54:47.925945516 +0200
@@ -24,7 +24,13 @@
return reduced_type(func(*args, **kwargs))
return wrapper

-
+def date_to_float(statement1):
+ if isinstance(statement1, datetime.datetime):
+ statement1=(statement1-datetime.datetime(1970,1,1)).total_seconds()
+ if isinstance(statement1, datetime.date):
+ statement1=(statement1-datetime.date(1970,1,1)).total_seconds()
+ return statement1
+
class PYSON(object):

def pyson(self):
@@ -313,7 +319,7 @@
super(Greater, self).__init__()
for i in (statement1, statement2):
if isinstance(i, PYSON):
- assert i.types().issubset(set([int, long, float])), \
+ assert i.types().issubset(set([int, long, float, datetime.date, datetime.datetime ])), \
'statement must be an integer or a float'
else:
assert isinstance(i, (int, long, float)), \
@@ -346,7 +352,7 @@
for i in ('s1', 's2'):
if not isinstance(dct[i], (int, long, float)):
dct = dct.copy()
- dct[i] = float(dct[i])
+ dct[i] = float(date_to_float(dct[i]))
return dct

@staticmethod
@@ -711,4 +717,3 @@
'Len': Len,
'Id': Id,
}
-

Sergi Almacellas Abellana

unread,
Aug 18, 2017, 3:32:32 AM8/18/17
to tryto...@googlegroups.com
El 18/08/17 a les 08:08, Juan Ramon Alfaro Martinez ha escrit:
> Hello.

Hi,
> I have need to campare a Date in pyson and I have modified pyson.py in trytond to support it, if someone wants to push upstream this is the patch.

There is an issue to add support to them:

https://bugs.tryton.org/issue4879

So feel free to join the issue to discuss about it.

--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Juan Ramon Alfaro Martinez

unread,
Aug 18, 2017, 4:35:05 AM8/18/17
to tryton-dev
Ok. Two years open, I have not seen it but is a long time without updates
Reply all
Reply to author
Forward
0 new messages