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

Subtraction is not defined for jdatetime.datetime objects? #17

Closed 5j9 closed 9 years ago

5j9 commented 9 years ago

When using the standard library:

>>> m = datetime.datetime(2015, 9, 22)
>>> n = datetime.datetime(2014, 9, 22)
>>> m-n
datetime.timedelta(365)

but with jdatetime:

>>> m = jdatetime.datetime(1394,1,1)
>>> n = jdatetime.datetime(1395,1,1)
>>> m-n
Traceback (most recent call last):
  File "<pyshell#21>", line 1, in <module>
    m-n
  File "C:\Users\a\AppData\Local\Programs\Python\Python35-32\lib\site-packages\jdatetime\__init__.py", line 753, in __sub__
    raise TypeError("unsupported operand type(s) for -: '%s' and '%s'"%(type(self), type(timedelta)))
TypeError: unsupported operand type(s) for -: '<class 'jdatetime.datetime'>' and '<class 'jdatetime.datetime'>'

I'm using Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32

slashmili commented 9 years ago

Well, I did implement

In [2]: n = jdatetime.datetime(1395,1,1)
In [3]: n - jdatetime.timedelta(days=1)
Out[3]: jdatetime.datetime(1394, 12, 29, 0, 0)

But apparently forgot to implement what you need :(

slashmili commented 9 years ago

it's fixed and pushed to pypi with version 1.7

5j9 commented 9 years ago

Thanks!