has_streak icon indicating copy to clipboard operation
has_streak copied to clipboard

Date fixer

Open short-matthew-f opened this issue 11 years ago • 1 comments

So, I realized this didn't allow for the following streak [Feb 27th, Feb 28th, Mar 1st, Mar 2nd] to count since your mapping would convert it to [28, 27, 2, 1].

Also, if your create dates have multiple creations on the same day, or multiple days that are the same (Mar 1st, May 1st, etc) then it will kill actual streaks.

The strategy is to leverage Date's tomorrow method, and to iterate over the dates and store them in arrays of streaks.

[Feb 1st, Feb 2nd, Feb 4th, Feb 5th, Feb 6th, Feb 8th] would convert under to_streaks to [ [Feb 1st, Feb 2nd], [Feb 4th, Feb 5th, Feb 6th], [Feb 8th] ]. Then, longest_streak would return [Feb 4th, Feb 5th, Feb 6th], and determine_consecutive_days would finally yield 3, the correct longest streak length.

The extra methods could be used to show the user the actual longest streak, and also all of their streaks, if public method were created to expose the information.

short-matthew-f avatar Oct 16 '14 01:10 short-matthew-f

@short-matthew-f really appreciate you taking the time to submit a fix. I want to try to wrap my head around some of the code you wrote with calculating the longest streak before I merge, so for now I'm going get a quick patch up so it's no longer broken. Using .tomorrow is definitely the way to go!

Again, thanks. :+1:

blvrd avatar Oct 16 '14 03:10 blvrd