Infinite recursion on adding days to a SimpleDate python object created from UTC
<p>I am using the python library simple-date. I created a SimpleDate object by initializing with a string representing a UTC date. When I try to add days to it, using timedelta, it seems to work fine but then when I try to print it, it recurses infinitely. I inspected the object resulting from the addition with p in the debugger and it displays nothing. The type is SimpleDate but it seems empty somehow. If I dont use a UTC string, it works fine.</p>

<p>Am I doing something wrong ?</p>

<p>My code:</p>

<pre><code>from simpledate import SimpleDate
from datetime import timedelta

# This works
day = '2016-06-01 00:00:00'
later = SimpleDate(day) + timedelta(days=10)
print(later)

# This works
day = '2016-06-01 00:00:00'
later = SimpleDate(day) + timedelta(days=10)
print(later)

# The print statement will cause infinite recursion
day = '2016-06-01 00:00:00'
later = SimpleDate(day, tz='UTC') + timedelta(days=10)
print(later)

# The print statement will cause infinite recursion
day = '2016-06-01 00:00:00UTC'
later = SimpleDate(day) + timedelta(days=10)
print(later)
</code></pre>

<p>So, there were two issues here.</p>

<p>The first is easy to explain.  Generating a message for a certain error caused the same error it was trying to report.  That caused a new message to be generated, which caused a new error, which ... eventually exhausted the stack.  That is now fixed.</p>

<p>The second is harder to explain, because timezones are complicated.  So I will start by giving an example that is easier to understand.  Consider this date in PDT (Pacific Daylight Time):</p>

<pre>
>>> SimpleDate('2016-08-28', tz='PDT')
SimpleDate('2016-08-28')
</pre>

<p>if we add 6 months to that, we will be in the middle of winter.  PDT doesn't even <strong>exist</strong> then (it's winter)!  So we get an error:</p>

<pre>
>>> SimpleDate('2016-08-28', tz='PDT') + timedelta(days=180)
simpledate.SingleInstantTzError: Attempted to use PDT, defined only for 2016-08-28 07:00:00+00:00
</pre>

<p>Now you could argue that SimpleDate should be smart enough to know when PDT ends.  But it isn't (and afaik it just doesn't have the data available, but I may be wrong).  Instead, SimpleDate <strong>refuses to modify dates associated with timezones that may have limited validity</strong>.  That's what "single instant" means.</p>

<p>For more on this see <a href="https://github.com/andrewcooke/simple-date#why-did-i-get-the-error-singleinstanttzerror-" rel="nofollow">the documentation</a>.</p>

<p>But in this case, the timezone was UTC!  We know that is always valid.  So I have added a special case that avoids this restriction when parsing UTC:</p>

<pre>
>>> SimpleDate('2016-08-28', tz='UTC') + timedelta(days=180)
SimpleDate('2017-02-24', tz='UTC')
</pre>

<p>This is now in PyPI as release 0.5.0.  Sorry for the delay - some tests were failing and I found a new bug, so I needed to do some extra work.</p>

python recursion timedelta