Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArithmeticObjectInterval>>#do: does not works properly in certain cases #3

Open
estebanlm opened this issue Oct 18, 2016 · 1 comment

Comments

@estebanlm
Copy link

Hi,

c := OrderedCollection new.
(January first, 2015 to: December first, 2015 by: 1 monthMeasure) 
    do: [ :each | c add: each ].
c size "335"

I get an OrderedCollection of 335 elements, many of them are in the future... I think this should be answering 12 elements (one for each month), but advancement fails.

If I do this:

c := OrderedCollection new.
(January, 2015 to: December, 2015 by: 1 monthMeasure) 
    do: [ :each | c add: each ].
c size "335"

It works, but just because happens than size was always 12 (because I declared an interval in months).

If I rewrite #do: as this:

    element := from.
    [ element < to ] whileTrue: [ 
        aBlock value: element.
        element := intervalStrategy advanceFrom: element by: by ].

Now it works, but other tests fails.

How to proceed from here? Is this a bug or I'm doing something wrong?

@mtaborda
Copy link
Owner

Hi Esteban,
If you wan't to iterate over an interval of dates and wan't to collect one date in particular, I could imagine that reading your first example, you could do this:
| c | c := OrderedCollection new. (January first, 2015 to: December first, 2015 everyDayNumber: 1) do: [ :each | c add: each ]. c size "12"

In this case, each element of c is the first date of each month of 2015.

But, be careful, if you do this:
| c | c := OrderedCollection new. (January first, 2015 to: December first, 2015 everyDayNumber: 31) do: [ :each | c add: each ]. c size "6"

Here the size is 6 because there is only six months with 31 days in the year.

The model behave in strange way when iterating like you write the first example, maybe there's a bug. If you found a way to solve this without break other things, please do it and share your solution with all. Thanks.

I hope my answer helps you.

Regards.
Maxi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants