rluiten / elm-date-extra

Elm Date Extra library add/subtract/diff/format etc dates
http://package.elm-lang.org/packages/rluiten/elm-date-extra/latest
BSD 3-Clause "New" or "Revised" License
75 stars 36 forks source link

Huge RAM consumption when calling Date.Extra.Utils.dayList with a negative integer. #43

Closed AionDev closed 7 years ago

AionDev commented 7 years ago

I just discovered this unusual behavior to the dayList function which is defined as:

dayList : Int -> Date -> List Date

Calling Date.Extra.Utils.dayList -2 someDate, creates a huge immediate bump into RAM consumption. Then the hole app gets frozen.

For positive numbers it works as expected. But I by mistake was getting a negative integer by calling: Date.Extra.Duration.diffDays startDate endDate

rluiten commented 7 years ago

That is very funny and a good find thanks. It is creating a massive list by subtracting 1 from your -2 until it reaches Zero :).

I hope to get to this in next day or so. Do you have an opinion for negative counts I propose making it return a list of days going back in time instead of forward by the given amount of days.

AionDev commented 7 years ago

from @tolgapaksoy in slack channel :

"i guess it’s because the recursion check is only done with == 0, and not <= 0: https://github.com/rluiten/elm-date-extra/blob/8.5.0/src/Date/Extra/Utils.elm#L52 ."

Yeah, i rely like this library. Thanks so much for building it 👍

rluiten commented 7 years ago

Fixed in 8.5.1. Thanks.