<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Sep 14, 2014 at 10:03 AM, Bert Freudenberg <span dir="ltr">&lt;<a href="mailto:bert@freudenbergs.de" target="_blank">bert@freudenbergs.de</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"><div style="word-wrap:break-word"><div><div><br><div><div>On 14.09.2014, at 07:46, Chris Cunningham &lt;<a href="mailto:cunningham.cb@gmail.com" target="_blank">cunningham.cb@gmail.com</a>&gt; wrote:</div><br><blockquote type="cite"><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>On Fri, Sep 12, 2014 at 10:38 AM, Chris Cunningham<br>
&lt;<a href="mailto:cunningham.cb@gmail.com" target="_blank">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>
</blockquote></div><div><br></div></div></div><div>This sounds surprisingly reasonable to me ;-)</div><div><br></div><div>I love using Squeak interactively, and these messages appear to do &quot;what I&#39;d expect&quot;.</div><div><br></div><div>The only objection I&#39;d have would be that it&#39;s not general enough: if you rolled GenericMonth and GenericYear into one and added in a regular duration, we could get something reasonable out of an expression like (1 year + 1 month + 1 week + 1 day).</div></div></blockquote><div><br></div><div>That would be neat, but not straight-forward.  For instance, 1 month + 1 day is no necessarily the same as 1 day + 1 month!  At least, not with the expectations given before.  Specifically:<br></div><div><br></div><div>August 30th + 1 month + 1 day = October 1st.</div><div>August 30th + 1 day + 1 month = September 30th.</div><div><br></div><div>Similarly, I think you can run into trouble with ordering of years and months (around Leap years, mainly), but I haven&#39;t worked that out yet.</div><div><br></div><div>Maybe a third type of duration - that can take a sequence of additive (subtractive) durations, and apply them together later.</div><div><br></div><div>But maybe I&#39;m missing a point - what would you want to get our of (1 year + 1 month + 1 week + 1 day)?  What questions would you ask of such a thing?  Remember, once you get into months and years, they are unspecific until given the context of a real month and or year.  A month is anywhere from 28 to 31 days (and possibly an extra second or similar); a year is 365 or 366 days.</div><div><br></div><div>-Chris</div><div> </div><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"><div style="word-wrap:break-word"><br></div></blockquote><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"><div style="word-wrap:break-word"><span><font color="#888888"><div>
<span style="border-collapse:separate;border-spacing:0px;font-family:&#39;Lucida Grande&#39;;font-size:12px"><div style="word-wrap:break-word"><div style="font-family:Helvetica"><span style="font-family:Helvetica">- Bert -</span></div><br></div></span><br>

</div>
<br></font></span></div><br><br>
<br></blockquote></div><br></div></div>