<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Sep 12, 2014 at 8:54 AM, Chris Muller <span dir="ltr">&lt;<a href="mailto:asqueaker@gmail.com" target="_blank">asqueaker@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Fri, Sep 12, 2014 at 10:38 AM, Chris Cunningham<br>
&lt;<a href="mailto:cunningham.cb@gmail.com">cunningham.cb@gmail.com</a>&gt; wrote:<br>
&gt; Ok.<br>
&gt;<br>
&gt; Date today + 15 days<br>
&gt; Date today + 1 day<br>
&gt; ((Date today + 1 day)  - Date today) days<br>
&gt;<br>
&gt; That works.  So, does this mean that we should deprecate the following<br>
&gt; methods in Date so that the observed API doesn&#39;t confuse future users?<br>
&gt; #addDays:, #addMonths:, #subtractDays:, #subtractDate: ?<br>
<br>
</span>Well, you won&#39;t be able to replicate #addMonths: with the binary<br>
operators, because how long is &quot;1 month?&quot;  And if we have addMonths:<br>
then it follows that we would have addDays: and addYears: for<br>
consistency (I see I have addYears: added in my own personal<br>
core-extensions package).</blockquote><div><br></div><div>Actually, you can add 1 month and 1 year, if you want.  I have proposed alterations in the InBox that does this - Kernel-cbc.870 and Collections-cbc.582 (the later of which does not include Collections-cbc.581).</div><div><br></div><div>These collections change #+  in DateAndTime to double-dispatch to the operand, sending the method #addToDateTime:. This does the same logic on all objects the previously could be added to a DateAndTime (as tested in KernelTests-cbc.277).</div><div><br></div><div>This allows the introduction of GenericMonth and GenericYear, so that we CAN do things like</div><div>   DateAndTime now + 4 months</div><div>This &#39;GenericMonth&#39; simple holds the number of months that you want to add (or subtract), and then does the appropriate addition of days based on the DateAndTime.  It handles different sizes of months, and leap years, just fine.  SImilarly for GenericYear.</div><div><br></div><div>It does make some assumptions on what a &#39;month&#39; is.</div><div>1: If you add a month, you want the result to be in the next calendar month, never the following one.</div><div>2: If you add a month, you want the same day of the month if possible, and if not (becaue the next month has less days), then the closest that you can get to it.</div><div>3: Similarly, if you subtract a month, you want it in the previous calendar month, and as close to the starting day of the month as you can get.</div><div>4: If you add more than 1 month, you want to end up in the right calendar month that you would expect, and as close to the starting day of the month as you can.</div><div>5: Similarly with years - next year, same month, same day (or as close as you can get - February is fun!); same for subtracting.</div><div><br></div><div>So, adding 1 month to August 31 would give September 30th; adding 2 months to August 31 would give October 31st.  And adding 1 month to September 30th would give October 30th.</div><div><br></div><div>I did this because I think a desired API should be as complete and consistent as we can get it - I really didn&#39;t like having to mix the two (or more) styles:</div><div>  DateAndTime now + 1 day</div><div>  DateAndTime now addMonths: 1</div><div><br></div><div>-cbc</div></div></div></div>