Re: [tryton-dev] Comparison support for Pyson Date tipes

2017-08-18 Thread Juan Ramon Alfaro Martinez
El viernes, 18 de agosto de 2017, 9:32:32 (UTC+2), Sergi Almacellas Abellana  
escribió:
> 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

Ok. Two years open, I have not seen it but is a long time without updates

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/b46b438e-7c03-4606-bd90-8cfb49310583%40googlegroups.com.


Re: [tryton-dev] Comparison support for Pyson Date tipes

2017-08-18 Thread Sergi Almacellas Abellana

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

--
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/b6c685cf-2cd8-9184-9e80-b997adcc83aa%40koolpi.com.


[tryton-dev] Comparison support for Pyson Date tipes

2017-08-18 Thread Juan Ramon Alfaro Martinez
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.old2017-08-18 07:53:10.705049046 +0200
+++ pyson.py2017-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,
 }
-

-- 
You received this message because you are subscribed to the Google Groups 
"tryton-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tryton-dev/0a6a0f55-027b-40a0-aae1-05d28a9a5f13%40googlegroups.com.