slashmili / python-jalali

Jalali calendar binding for Python based on Python's datetime module
http://pypi.python.org/pypi/jdatetime/
Other
339 stars 48 forks source link

unsupported operand for `datetime.datetime` #9

Closed yassersouri closed 11 years ago

yassersouri commented 11 years ago

salam

https://github.com/slashmili/python-jalali/blob/master/jdatetime/__init__.py#L820

we really need to compare between datetimes and jdatetimes, what can we do?

slashmili commented 11 years ago

It's not supported in python standard datetime module so it's better not to be implemented here!

But you can always do this:

>>> datetime.datetime.now().date() == datetime.date.today()
True
yassersouri commented 11 years ago

I think there is a misunderstanding:

I mean this:

>>> dt = datetime.datetime.now()
>>> jdt = jdatetime.datetime.now()
>>> dt > jdt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "jdatetime/__init__.py", line 837, in __lt__
    raise TypeError("unsupported operand type for <: '%s'"%(type(other_datetime)))

I think all operands are implemented in such a way that they raise this exception.

slashmili commented 11 years ago

What do say about this :

>>> dt = datetime.datetime.now()
>>> jdt = jdatetime.datetime.now()
>>> dt > jdt.togregorian()
False

I know the thing that you want is just a few lines change but it ruins the integrity of this lib with python datetime module. Also consider if someone wants to use it this way :

jdatetime.datetime.now() > datetime.datetime.now()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.8-intel/egg/jdatetime/__init__.py", line 784, in __gt__
TypeError: unsupported operand type for >: '<type 'datetime.datetime'>'

Then there would be no way to change the python's datetime.