Why can't python's datetime.max survive a round trip through timestamp / fromtimestamp?
<p>In most cases I can round-trip datetimes to and from a timestamp as follows:</p>

<pre><code>from datetime import datetime

dt = datetime(2016, 1, 1, 12, 34, 56, 789)
print(dt)
print(datetime.fromtimestamp(dt.timestamp()))
</code></pre>

<blockquote>
  <p>2016-01-01 12:34:56.000789</p>
  
  <p>2016-01-01 12:34:56.000789</p>
</blockquote>

<p>But this doesn't work for datetime.max. Why is that?</p>

<pre><code>dt = datetime.max
print(dt)
print(datetime.fromtimestamp(dt.timestamp()))
</code></pre>

<blockquote>
  <p>9999-12-31 23:59:59.999999</p>
  
  <p>Traceback (most recent call last):   File
  "python", line 9, in  ValueError: year is out of range</p>
</blockquote>

<p>More precisely, why hasn't the datetime library taken this case into account?</p>

<pre><code>dt = datetime.max
</code></pre>

<p>is checking against the maximum of the datetime class. It is a static value.</p>

<pre><code>datetime.fromtimestamp(dt.timestamp()))
</code></pre>

<p>This, however, is working against a timestamp. Different classes, different methods. <a href="https://docs.python.org/3.5/library/datetime.html#datetime.datetime.max" rel="nofollow">Here</a> are the docs for datetime's methods.</p>

python python-3.x datetime