[squeak-dev] Could we have 1 api that work across all of the
cunningham.cb at gmail.com
Mon Sep 15 16:10:19 UTC 2014
On Sun, Sep 14, 2014 at 10:03 AM, Bert Freudenberg <bert at freudenbergs.de>
> On 14.09.2014, at 07:46, Chris Cunningham <cunningham.cb at gmail.com> wrote:
> On Fri, Sep 12, 2014 at 8:54 AM, Chris Muller <asqueaker at gmail.com> wrote:
>> On Fri, Sep 12, 2014 at 10:38 AM, Chris Cunningham
>> <cunningham.cb at gmail.com> wrote:
>> > Ok.
>> > Date today + 15 days
>> > Date today + 1 day
>> > ((Date today + 1 day) - Date today) days
>> > That works. So, does this mean that we should deprecate the following
>> > methods in Date so that the observed API doesn't confuse future users?
>> > #addDays:, #addMonths:, #subtractDays:, #subtractDate: ?
>> Well, you won't be able to replicate #addMonths: with the binary
>> operators, because how long is "1 month?" And if we have addMonths:
>> then it follows that we would have addDays: and addYears: for
>> consistency (I see I have addYears: added in my own personal
>> core-extensions package).
> 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
> 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
> This allows the introduction of GenericMonth and GenericYear, so that we
> CAN do things like
> DateAndTime now + 4 months
> This 'GenericMonth' 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.
> It does make some assumptions on what a 'month' is.
> 1: If you add a month, you want the result to be in the next calendar
> month, never the following one.
> 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.
> 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
> 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.
> 5: Similarly with years - next year, same month, same day (or as close as
> you can get - February is fun!); same for subtracting.
> 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.
> I did this because I think a desired API should be as complete and
> consistent as we can get it - I really didn't like having to mix the two
> (or more) styles:
> DateAndTime now + 1 day
> DateAndTime now addMonths: 1
> This sounds surprisingly reasonable to me ;-)
> I love using Squeak interactively, and these messages appear to do "what
> I'd expect".
> The only objection I'd have would be that it'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).
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:
August 30th + 1 month + 1 day = October 1st.
August 30th + 1 day + 1 month = September 30th.
Similarly, I think you can run into trouble with ordering of years and
months (around Leap years, mainly), but I haven't worked that out yet.
Maybe a third type of duration - that can take a sequence of additive
(subtractive) durations, and apply them together later.
But maybe I'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
> - Bert -
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev