Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, there is at least one good reason not to: the resulting instance is completely different from the two input instances. Is this important? I don't think so -- consider that <code>date - date</code> yields <code>timedelta</code>.</p> <p>The way I see it:</p> <ul> <li>Does adding two dates together make sense? No.</li> <li>Does adding two times together make sense? No.</li> <li>Does adding a date and a time together make sense? Yup!</li> <li>Does adding a date and a timedelta togethor make sense? Maybe.</li> <li>Does adding a time and a timedelta together make sense? Maybe.</li> </ul> <p>and for subtraction</p> <ul> <li>Does subtracting two dates make sense? Yes.</li> <li>Does subtracting two times make sense? Yes.</li> <li>Does subtracting a time from a date make sense? Nope.</li> <li>Does subtracting a timedelta from a date make sense? Maybe.</li> <li>Does subtracting a timedelta from a time make sense? Maybe.</li> </ul> <p>Developing along the lines of what makes sense:</p> <pre><code>date + time =&gt; datetime date + timedelta =&gt; date | datetime or exception or silently drop time portion time + date =&gt; datetime time + timedelta =&gt; time | wrap-around or exception date - date =&gt; timedelta date - timedelta =&gt; date | datetime or exception or silently drop time portion time - time =&gt; timedelta time - timedelta =&gt; time | wrap-around or exception datetime + timedelta =&gt; datetime datetime - timedelta =&gt; datetime </code></pre> <p>So, if it were me and I were designing a Date, Time, DateTime, TimeDelta framework, I would allow:</p> <pre><code>date + time date - date time - time datetime + timedelta datetime - timedelta </code></pre> <p>and for these:</p> <pre><code>date +/- timedelta time +/- timedelta </code></pre> <p>I would default to returning the same type if the timedelta had none of the other type, and raising an exception if the timedelta did have some of the other type, but there would be a setting that would control that. The other possible behavior would be to drop the unneeded portion -- so a date combined with a timedelta that had hours would drop the hours and return a date.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload